Using PS3/PS4 controller
Warning
This guide is outdated and some steps may not work. Will be updated later
Totem robots can be controller using DUALSHOCK™3 and DUALSHOCK™4 wireless controllers. This tutorial contains set-up instructions required to use with Totem products.
Requirements
- DUALSHOCK™ controller
- RoboBoard X4 or other ESP32 based module
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 - DUALSHOCK™3
- Click PlatformIO icon in sidebar.
- Select
Miscellaneous
→New Terminal
. - Run command inside terminal:
pio lib --global install https://github.com/jvpernis/esp32-ps3
- 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.
PS4Controller - DUALSHOCK™4
- Click PlatformIO icon in sidebar.
- Select
Miscellaneous
→New Terminal
. - Run command inside terminal:
pio lib --global install https://github.com/aed3/PS4-esp32
- 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.
Configure controller
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
01:02:03:04:05:06
- Click Update
- "Current Master" will change to "01:02:03:04:05:06"
- Address is set. Unplug controller and close the tool.
Run example code
Totem library provides example code to connect and use controllers.
Examples starting with "Controller/PS3_" are made for DUALSHOCK™3 controller.
Examples starting with "Controller/PS4_" are made for DUALSHOCK™4 controller.
Ensure that adddress entered in "Change Master" matches with one provided in PS4.begin("01: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 PlatformIO → esp32dev → Platform → Erase Flash
or esptool.py erase_flash
.