Bluetooth connection of PS4 controller and RemoteXY interface
Posted: Fri Jun 28, 2024 4:17 pm
I am trying to connect a PS4 controller and display an interface on a phone using the RemoteXY library. Both function properly on separate sketches, but if i combine them, the connection to one device or the other is not possible. The order in which i call PS4.begin("C0:49:EF:E7:CD:5E"); or RemoteXY_Init (); determines wich one is working. I suspect some conflict in the BT serial configuration, but the initialisation code is in the libraries. I have trouble navigating the library functions to determine the origin of the problem. Here are both libraries in question:
https://github.com/RemoteXY/RemoteXY-Arduino-library
https://github.com/xman4242/PS4-ESP32
Here is my arduino code
https://github.com/RemoteXY/RemoteXY-Arduino-library
https://github.com/xman4242/PS4-ESP32
Here is my arduino code
- #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:5E"); //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 : " + switch_01);
- }
- itoa(millis(), RemoteXY.text_01, 10);
- //if (PS4.Circle()) Serial.println("Circle Button");
- }