Using PS3/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)
- Select
Sketch
→Include Library
→Manage Libraries..
. - In search field type
PS3 Controller Host
. - Select library
PS3 Controller Host
from the list and click Install. - Close the window when installation is finished.
- Click PlatformIO icon in sidebar.
- Select
Miscellaneous
→New Terminal
. - Run command inside terminal:
pio lib --global install https://github.com/jvpernis/esp32-ps3
PS4Controller (click to expand)
- Download file PS4-esp32-master.zip.
- Select
Sketch
→Include Library
→Add .ZIP Library..
. - Select downloaded PS4-esp32-master.zip file.
- Message "Library added to your libraries" should appear.
- Click PlatformIO icon in sidebar.
- Select
Miscellaneous
→New Terminal
. - 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
- Run SixaxisPairTool.
- Connect controller to PC using USB cable.
- SixaxisPairTool should detect connected controller and display current stored MAC address at "Current Master".
- In "Change Master" enter
00:02:03:04:05:06
- Click Update
- "Current Master" will change to "00:02:03:04:05:06"
- 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 → Tools
→ Erase All Flash Before Sketch Upload
.
Select PlatformIO → Project Tasks → Platform → Erase Flash
.
Command line: esptool.py erase_flash
.