Skip to content

Using PS3/PS4 controller

PS3 Controller PS4 Controller

Totem robots can be controller using PS3 or PS4 wireless controllers. This tutorial contains set-up instructions required to use with RoboBoard.

How it works

Controller communicates directly with ESP32 MCU using Arduino libraries PS3 Controller Host, PS4Controller. They provide API to read controller buttons, control leds, vibration, etc.

When PS button is pressed, controller tries to connect device with MAC address stored in its memory. ESP32 presents itself with this address and accepts connection. For this reason, a setup of same MAC address for controller and ESP32 is required.

Install library

A third party Arduino library is required to compile the code to use with controller.
Select install instructions depending on controller. Both of them can be installed also.

PS3 Controller Host (click to expand)
  1. Select SketchInclude LibraryManage Libraries...
  2. In search field type PS3 Controller Host.
  3. Select library PS3 Controller Host from the list and click Install.
  4. Close the window when installation is finished.
  1. Click PlatformIO icon in sidebar.
  2. Select MiscellaneousNew Terminal.
  3. Run command inside terminal:
    pio lib --global install https://github.com/jvpernis/esp32-ps3
PS4Controller (click to expand)
  1. Download file PS4-esp32-master.zip.
  2. Select SketchInclude LibraryAdd .ZIP Library...
  3. Select downloaded PS4-esp32-master.zip file.
  4. Message "Library added to your libraries" should appear.
  1. Click PlatformIO icon in sidebar.
  2. Select MiscellaneousNew Terminal.
  3. Run command inside terminal:
    pio lib --global install https://github.com/aed3/PS4-esp32

Change MAC

Stored MAC address can be changed with Sixaxis Pairer Tool using PC.
This is required only once. If controller was connected to other device, this step should be repeated. Follow instructions to change controller address:

Download link: SixaxisPairToolSetup-0.3.1.exe – [Size: 25.6 MB]
Run downloaded file and install.

Download link: sixpair - [Size: 9.4 KB]
This utility requires libusb, which can be downloaded from http://www.ellert.se/twain-sane/. Choose the binary for your version of OSX.

Download link: SixaxisPairTool – [Size: 55.7 KB]

Required dependencies: qt5, libusb-1.0

You will also need to install the following udev rule file under /etc/udev/rules.d/ to give the app access to the controller: 51-sixaxispairtool.rules

Sixaxis Pair Tool

  1. Run SixaxisPairTool.
  2. Connect controller to PC using USB cable.
  3. SixaxisPairTool should detect connected controller and display current stored MAC address at "Current Master".
  4. In "Change Master" enter 00:02:03:04:05:06
  5. Click Update
  6. "Current Master" will change to "00:02:03:04:05:06"
  7. Address is set. Unplug controller and close the tool.

Run example code

Interaction with controller features can be found inside library examples.

To use controllers with RoboBoard and Totem robotic kits, check Totem Arduino examples.

Ensure that adddress entered in "Change Master" matches with one provided in PS4.begin("00:02:03:04:05:06").
Press PS button on the controller and after few seconds it should start working.

Bug

Sometimes remote does not connect even if MAC address is correct.
Erase ESP32 flash and upload it again to resolve issue:
Select Arduino IDE → ToolsErase All Flash Before Sketch Upload.
Select PlatformIO → Project Tasks → Platform → Erase Flash.
Command line: esptool.py erase_flash.