First you will need your ESP32 working with the Arduino 2.0.x IDE by installing the arduino-esp32 board package.
This will get you setup once you’ve downloaded and installed the Arduino IDE v2.
https://docs.espressif.com/projects/arduino-esp32/en/latest/getting_started.html
Hopefully you’ve tried the Blink sketch and were able to get the ESP32 LED blinking. On my ESP32 board the LED was connected to pin 2 so I defined this “#define LED_BUILTIN 2”.
With the Arduino IDE v2 setup you’ll now need to install the “PS3 Controller Host” library by Jeffrey van Pernis. Do this by opening the Library Manager and searching for “PS3 Controller”. When you find the library, click the install button. Open the example sketch called Ps3Demo found under the “PS3 Controller Host” section. In the setup() function the ps3.begin() function requires a Bluetooth MAC address and this is where most problems occur. The PS3 controller needs to be paired with a Bluetooth Host interface and will store that devices MAC address in the controller for use when connecting over wireless Bluetooth. Our ESP32 is not a Sony PlayStation so we need a trick to get the MAC address of our ESP32 Bluetooth interface into the PS3 controller. To get the ESP32 MAC address, I followed the instructions on this site:
https://linuxhint.com/esp32-bluetooth-address-arduino-ide
And the sketch listed which looks like this:
<code>
#include “esp_bt_main.h”
#include “esp_bt_device.h”
#include “BluetoothSerial.h”
BluetoothSerial SerialBT;
void printDeviceAddress() {
const uint8_t* point = esp_bt_dev_get_address();
for (int i = 0; i < 6; i++) {
char str[3];
sprintf(str, “%02X”, (int)point[i]);
Serial.print(str);
if (i < 5){
Serial.print(“:”);
}
}
}
void setup() {
Serial.begin(115200);
SerialBT.begin(“ESP32 Bluetooth”);
printDeviceAddress();
}
void loop() {}
</code>
When you build this and install it on your ESP32 and look at the terminal window it will show you the MAC address of that device’s Bluetooth interface. Copy it using your mouse by highlighting it, then use Ctl-c keys to copy.
Now, the SixPair tool will let you push that MAC address into the PS3 controller when it is connected over USB cable to your PC. I use Linux but you could use an rPi or even Linux on Windows via WSL. I used the following commands but you can follow the developer’s pages if you have problems( http://www.pabr.org/sixlinux/sixlinux.en.html )
# sudo apt install libusb-dev
# wget http://www.pabr.org/sixlinux/sixpair.c
# gcc -o sixpair sixpair.c -lusb
# sudo ./sixpair [paste the ESP32 MAC Address here]
At this point your PS3 now has your ESP32 Bluetooth MAC address stored and before you build the Ps3Demo.ino sketch you just need to paste(Ctrl-v) the ESP32 Bluetooth MAC address into the setup() function on the line with ps3.begin(“01:02:03:04:05:06”); replacing everything inside the double quotes with your ESP32 Bluetooth MAC address. You can now build and upload the Ps3Demo.ino sketch into the ESP32.
I use a Makefile to build and flash from the commandline once working within the Arduino IDE v2.
make build flash && minicom -D /dev/ttyUSB0 -b 115200
But you can do all this in the Arduino IDE v2 and once uploaded, open the terminal window with the 115200 baud rate setting. Then push the PS button on your PS3 controller and 1 LED should light up when it connects to your ESP32. Now, when you move the sticks or push buttons you should see the data on the terminal window.
This is what the terminal window data can look like once working:
Setting LEDs to player 0
Connected.
The controller battery is FULL
Moved the right stick: x=0 y=3
Moved the right stick: x=0 y=-2
Moved the right stick: x=-1 y=-7
Moved the right stick: x=-2 y=-10
Moved the right stick: x=-3 y=-19
Moved the right stick: x=-3 y=-30
Moved the right stick: x=-3 y=-39
Moved the right stick: x=-3 y=-49
Moved the right stick: x=-3 y=-57
Moved the right stick: x=-1 y=-68
Moved the right stick: x=3 y=-80
Moved the right stick: x=6 y=-90
Moved the right stick: x=8 y=-96
Moved the right stick: x=8 y=-101
Moved the right stick: x=9 y=-106
Moved the right stick: x=8 y=-108
Moved the right stick: x=2 y=-102
Moved the right stick: x=-6 y=-90
Moved the right stick: x=-14 y=-75
Moved the right stick: x=-18 y=-48