Connecting PS4 Controller to Wemos D1 R32

@benedictdied Hello, thanks for your help so far I greatly appreciate it. I am trying to connect a ps4 controller to my wemos d1 r32 board. From what I understand, the only thing I need to do is retrieve the mac address of the controller and input it into my PinConfig as such:

 const char *PSX_MAC = "a8:47:4a:7b:xx:xx"; (rest is filled in correctly)
 int8_t PSX_CONTROLLER_TYPE = 2;
 boolean enableBlueTooth = true;

 int8_t JOYSTICK_SPEED_MULTIPLIER = 5;
 int8_t JOYSTICK_SPEED_MULTIPLIER_Z = 3;

And then upload the firmware from visual studio code/ platform.io.

I did these steps and tried to connect to the board through the webserialtest but I got this information back:

{“task”:“/bt_scan”}
[ 16183][I][SerialProcess.cpp:31] loop(): String s:{“task”:“/bt_scan”} , char:{“task”:“/bt_scan”}
[ 16183][I][BtController.cpp:375] scanForDevices(): scanForDevices - this does not work on all ESP32 even if same fabricate and same version
e[0;32mI (16892) HIDGamePad: SCAN…e[0m
e[0;31mE (16896) ESP_HID_GAP: esp_ble_gap_set_scan_params failed: 259e[0m
e[0;32mI (16903) HIDGamePad: SCAN: 0 resultse[0m
e[0;32mI (16907) HIDGamePad: vtaskdelete hid_demo_taske[0m

Does this mean this board is really not compatible with this controller? Is there other libraries or dependencies I need to include besides what I provided here?

@benedictdied this is the readout i get in the terminal of imswitch:

2024-09-10 15:17:33 DEBUG [UC2ConfigController] Pairing BT device.
DEBUG:imswitch:[UC2ConfigController] Pairing BT device.
2024-09-10 15:17:33 DEBUG [ESP32Manager → ESP32] [SendingCommands]:{“dummy”: 1, “task”: “/bt_scan”, “qid”: 9}

DEBUG:imswitch:[ESP32Manager → ESP32] [SendingCommands]:{“dummy”: 1, “task”: “/bt_scan”, “qid”: 9}

2024-09-10 15:17:33 DEBUG [ESP32Manager → ESP32] [ProcessLines]:[1417985][I][SerialProcess.cpp:31] loop(): String s:{“dummy”: 1, “task”: “/bt_scan”, “qid”: 9}
DEBUG:imswitch:[ESP32Manager → ESP32] [ProcessLines]:[1417985][I][SerialProcess.cpp:31] loop(): String s:{“dummy”: 1, “task”: “/bt_scan”, “qid”: 9}
2024-09-10 15:17:33 DEBUG [ESP32Manager → ESP32] [ProcessLines]:, char:{“dummy”: 1, “task”: “/bt_scan”, “qid”: 9}
DEBUG:imswitch:[ESP32Manager → ESP32] [ProcessLines]:, char:{“dummy”: 1, “task”: “/bt_scan”, “qid”: 9}
2024-09-10 15:17:33 DEBUG [ESP32Manager → ESP32] [ProcessLines]:[1417987][I][BtController.cpp:375] scanForDevices(): scanForDevices - this does not work on all ESP32 even if same fabricate and same version
DEBUG:imswitch:[ESP32Manager → ESP32] [ProcessLines]:[1417987][I][BtController.cpp:375] scanForDevices(): scanForDevices - this does not work on all ESP32 even if same fabricate and same version
2024-09-10 15:17:33 DEBUG [ESP32Manager → ESP32] [ProcessLines]:I (1418699) HIDGamePad: SCAN…
DEBUG:imswitch:[ESP32Manager → ESP32] [ProcessLines]:I (1418699) HIDGamePad: SCAN…
2024-09-10 15:17:33 DEBUG [ESP32Manager → ESP32] [ProcessLines]:E (1418703) ESP_HID_GAP: esp_ble_gap_set_scan_params failed: 259
DEBUG:imswitch:[ESP32Manager → ESP32] [ProcessLines]:E (1418703) ESP_HID_GAP: esp_ble_gap_set_scan_params failed: 259
2024-09-10 15:17:33 DEBUG [ESP32Manager → ESP32] [ProcessLines]:I (1418709) HIDGamePad: SCAN: 0 results
DEBUG:imswitch:[ESP32Manager → ESP32] [ProcessLines]:I (1418709) HIDGamePad: SCAN: 0 results
2024-09-10 15:17:33 DEBUG [ESP32Manager → ESP32] [ProcessLines]:I (1418714) HIDGamePad: vtaskdelete hid_demo_task
DEBUG:imswitch:[ESP32Manager → ESP32] [ProcessLines]:I (1418714) HIDGamePad: vtaskdelete hid_demo_task

Did you bring the Controller in PAiring mode as stated here PS4-Controller | openUC2 Documentation

@benedictdied Yes, the controller was in pairing mode. In this documentation you said

“However, please note that the flashing tool is a separate tool for uploading firmware, and the Bluetooth communication with the PS4 controller needs to be implemented in your firmware code.”

Is there something else that should be implemented?

If you use the firmware from the web page then it should work. You just need to press the BT scan button on the web serial testing page, then it works if the controller is in pairing mode.

@benedictdied Any other possible debugging things I can do? I reinstalled the firmware and tried to connect the controller but still not luck and get the same error I showed above. I am using an OEM PS4 controller.

{“task”:“/bt_scan”}
e[0;32mI (929041) HIDGamePad: SCAN…e[0m
e[0;31mE (929042) ESP_HID_GAP: esp_ble_gap_set_scan_params failed: 259e[0m
e[0;32mI (929042) HIDGamePad: SCAN: 0 resultse[0m
e[0;32mI (929045) HIDGamePad: vtaskdelete hid_demo_taske[0m

You used the WEMOS, right? I think certain ESP32 CPUs have different Bluetooth behviours, right? I’m also struggeling with this right now. I honestly don’t know. Could you test something like this to see if this works at all GitHub - ricardoquesada/bluepad32: Bluetooth gamepad, mouse and keyboard support for ESP32 and PicoW

@benedictdied Yes I am using a WEMOS board. I am not sure about the different Bluetooth behaviors though. I can try this link here. Should this work in conjunction with the firmware already downloaded onto my ESP32?

@benedictdied I was able to connect the controller to the WEMOS esp32 like the link showed. My serial monitor is just an endless output of these control settings. Not sure what to do now or how to implement this with the firmware on the webserialtool as it will most likely delete what I just uploaded onto the board?

idx=0, dpad: 0x00, buttons: 0x0000, axis L: 4, -164, axis R: -16, 0, brake: 0, throttle: 0, misc: 0x00, gyro x: 123 y: 62 z: -302, accel x: 10 y: 7893 z: 1395
idx=0, dpad: 0x00, buttons: 0x0000, axis L: 4, -212, axis R: -16, 0, brake: 0, throttle: 0, misc: 0x00, gyro x: 61 y: 62 z: -181, accel x: -13 y: 7906 z: 1402
idx=0, dpad: 0x00, buttons: 0x0000, axis L: 4, -140, axis R: -16, 0, brake: 0, throttle: 0, misc: 0x00, gyro x: 61 y: 62 z: -362, accel x: 2 y: 7897 z: 1409
idx=0, dpad: 0x00, buttons: 0x0000, axis L: 4, -204, axis R: -16, 0, brake: 0, throttle: 0, misc: 0x00, gyro x: 123 y: 124 z: -181, accel x: 19 y: 7913 z: 1398
idx=0, dpad: 0x00, buttons: 0x0000, axis L: 4, -164, axis R: -16, 0, brake: 0, throttle: 0, misc: 0x00, gyro x: 61 y: 124 z: -60, accel x: 33 y: 7890 z: 1413
idx=0, dpad: 0x00, buttons: 0x0000, axis L: 4, -164, axis R: -16, 0, brake: 0, throttle: 0, misc: 0x00, gyro x: 61 y: 62 z: -241, accel x: 15 y: 7863 z: 1420
idx=0, dpad: 0x00, buttons: 0x0000, axis L: 4, -208, axis R: -16, 0, brake: 0, throttle: 0, misc: 0x00, gyro x: 0 y: 124 z: -241, accel x: 25 y: 7905 z: 1379
idx=0, dpad: 0x00, buttons: 0x0000, axis L: 4, -124, axis R: -16, 0, brake: 0, throttle: 0, misc: 0x00, gyro x: 0 y: 62 z: -241, accel x: 9 y: 7844 z: 1379
idx=0, dpad: 0x00, buttons: 0x0000, axis L: 4, -164, axis R: -16, 0, brake: 0, throttle: 0, misc: 0x00, gyro x: 123 y: 0 z: -241, accel x: 39 y: 7923 z: 1394
idx=0, dpad: 0x00, buttons: 0x0000, axis L: 4, -128, axis R: -16, 0, brake: 0, throttle: 0, misc: 0x00, gyro x: 123 y: 124 z: -181, accel x: 10 y: 7907 z:

Interesting. How did you compile it? Which version did you use? I’m trying the bluepad in platformio and it fails

@benedictdied I used option B from this link here using platform.io: Arduino + ESP32 board - Bluepad32

I just cloned the template and built/uploaded it using the esp32dev board option. Once it uploaded, I just put the controller in pairing mode and it connected automatically.

Aha, interesting. I cannot get it to run. Either on Window nor mac. It complains about version conflicts. Were you able to get it working with Platformio? My hopis that the btstack is a little more robust than the vanilla ESP BT stack. It sometimes works, sometimes just doesn’t with the same code…

@benedictdied Are you taking about the UC2-esp32 firmware through Platform.io? I have compiled the firmware on both the webserial website and platform.io and both I am not able to get the controller to connect. Is there a possible solution to this that we can work on? I am not well versed in the coding aspect so I am not sure I am much help but I am willing to try whatever you might suggest.

I think the main thing is at least I know my controller is able to connect to my wemos esp32 board so I know it’s at least possible. Have you been able to get the controller working with your UC2 firmware on a wemos board recently?

@benedictdied any solutions on this that can be worked on?

Hey, sorry not yet. I’m working on I2C implementations at the moment. The Bluetooth Stack from the ESP side is a bit nasty. It sometimes work, sometimes it doesn’t. it’s really hard to debug (for me). I also do not get the bluepad to work unfortunately. Did you use the platformio or the ESP-IDF implementation? You wrote Option B - that would be IDF, rihgt?

@benedictdied Yes, I used esp-idf implementation (option B) but I did this through platform.io (A).

I did not manually install the ESP-IDF toolchain