Bluetooth connection of PS4 controller and RemoteXY interface
Posted: Sat Jun 29, 2024 3:39 am
I am trying to combine input from a PS4 controller via bluetooth with a display on a smartphone using the RemoteXY app to an ESP32 WROOM 32UE. Both work correctly separatly, but one or the other does not connect when combined in the same sketch. The code compiles, but depending on which is called first in setup, only one or the other works. My guess is some conflict in the bluetooth initialization, but figuring it out by reading the library code is challenging. Here are both libraries. Any cues are appreciated,
https://github.com/RemoteXY/RemoteXY-Arduino-library
https://github.com/aed3/PS4-esp32
https://github.com/RemoteXY/RemoteXY-Arduino-library
https://github.com/aed3/PS4-esp32
- #include <PS4Controller.h>
- #include <ps4.h>
- #include <ps4_int.h>
- //////////////////////////////////////////////
- // RemoteXY include library //
- //////////////////////////////////////////////
- // you can enable debug logging to Serial at 115200
- //#define REMOTEXY__DEBUGLOG
- // RemoteXY select connection mode and include library
- #define REMOTEXY_MODE__ESP32CORE_BLUETOOTH
- #include <BluetoothSerial.h>
- // RemoteXY connection settings
- #define REMOTEXY_BLUETOOTH_NAME "RemoteXY"
- #include <RemoteXY.h>
- // RemoteXY GUI configuration
- #pragma pack(push, 1)
- uint8_t RemoteXY_CONF[] = // 55 bytes
- { 255,12,0,11,0,48,0,17,0,0,0,31,1,106,200,1,1,3,0,2,
- 18,36,44,22,0,2,26,31,31,79,78,0,79,70,70,0,7,51,77,40,
- 10,36,2,26,2,11,67,6,77,40,10,4,2,26,11 };
- // this structure defines all the variables and events of your control interface
- struct {
- // input variables
- uint8_t switch_01; // =1 if switch ON and =0 if OFF
- char edit_01[11]; // string UTF8 end zero
- // output variables
- char text_01[11]; // string UTF8 end zero
- // other variable
- uint8_t connect_flag; // =1 if wire connected, else =0
- } RemoteXY;
- #pragma pack(pop)
- /////////////////////////////////////////////
- // END RemoteXY include //
- /////////////////////////////////////////////
- const byte pin_sortie_relais_alimentation = 12;
- byte dernier_etat_switch_01 = 0;
- void setup()
- {
- Serial.begin(115200);
- PS4.begin("c0:49:ef:e7:cd:5c"); //ESP
- RemoteXY_Init ();
- pinMode(pin_sortie_relais_alimentation, OUTPUT);
- digitalWrite(pin_sortie_relais_alimentation, RemoteXY.switch_01);
- Serial.println("adresse MAC BT");
- uint8_t baseMac[6];
- // Get the MAC address of the Bluetooth interface
- esp_read_mac(baseMac, ESP_MAC_BT);
- Serial.print("Bluetooth MAC: ");
- for (int i = 0; i < 5; i++) {
- Serial.printf("%02X:", baseMac[i]);
- }
- Serial.printf("%02X\n", baseMac[5]);
- Serial.println("");
- }
- void loop()
- {
- RemoteXY_Handler ();
- if (RemoteXY.switch_01 != dernier_etat_switch_01){
- dernier_etat_switch_01 = RemoteXY.switch_01;
- digitalWrite(pin_sortie_relais_alimentation, RemoteXY.switch_01);
- Serial.println("Relais : " + RemoteXY.switch_01);
- }
- itoa(millis(), RemoteXY.text_01, 10);
- }