Bluetooth connection of PS4 controller and RemoteXY interface

BWV999
Posts: 2
Joined: Mon Jun 24, 2024 7:06 pm

Bluetooth connection of PS4 controller and RemoteXY interface

Postby BWV999 » 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
  1. #include <PS4Controller.h>
  2. #include <ps4.h>
  3. #include <ps4_int.h>
  4.  
  5.  
  6.  
  7. //////////////////////////////////////////////
  8. //        RemoteXY include library          //
  9. //////////////////////////////////////////////
  10.  
  11. // you can enable debug logging to Serial at 115200
  12. //#define REMOTEXY__DEBUGLOG    
  13.  
  14. // RemoteXY select connection mode and include library
  15. #define REMOTEXY_MODE__ESP32CORE_BLUETOOTH
  16.  
  17. #include <BluetoothSerial.h>
  18.  
  19. // RemoteXY connection settings
  20. #define REMOTEXY_BLUETOOTH_NAME "RemoteXY"
  21.  
  22.  
  23. #include <RemoteXY.h>
  24.  
  25. // RemoteXY GUI configuration  
  26. #pragma pack(push, 1)  
  27. uint8_t RemoteXY_CONF[] =   // 55 bytes
  28.   { 255,12,0,11,0,48,0,17,0,0,0,31,1,106,200,1,1,3,0,2,
  29.   18,36,44,22,0,2,26,31,31,79,78,0,79,70,70,0,7,51,77,40,
  30.   10,36,2,26,2,11,67,6,77,40,10,4,2,26,11 };
  31.  
  32. // this structure defines all the variables and events of your control interface
  33. struct {
  34.  
  35.     // input variables
  36.   uint8_t switch_01; // =1 if switch ON and =0 if OFF
  37.   char edit_01[11]; // string UTF8 end zero
  38.  
  39.     // output variables
  40.   char text_01[11]; // string UTF8 end zero
  41.  
  42.     // other variable
  43.   uint8_t connect_flag;  // =1 if wire connected, else =0
  44.  
  45. } RemoteXY;  
  46. #pragma pack(pop)
  47.  
  48. /////////////////////////////////////////////
  49. //           END RemoteXY include          //
  50. /////////////////////////////////////////////
  51.  
  52.  
  53.  
  54. const byte pin_sortie_relais_alimentation = 12;
  55. byte dernier_etat_switch_01 = 0;
  56.  
  57. void setup()
  58. {
  59.   Serial.begin(115200);
  60.   PS4.begin("c0:49:ef:e7:cd:5c"); //ESP
  61.   RemoteXY_Init ();
  62.  
  63.   pinMode(pin_sortie_relais_alimentation, OUTPUT);
  64.   digitalWrite(pin_sortie_relais_alimentation, RemoteXY.switch_01);
  65.  
  66.   Serial.println("adresse MAC BT");
  67.  
  68.   uint8_t baseMac[6];
  69.   // Get the MAC address of the Bluetooth interface
  70.   esp_read_mac(baseMac, ESP_MAC_BT);
  71.   Serial.print("Bluetooth MAC: ");
  72.   for (int i = 0; i < 5; i++) {
  73.     Serial.printf("%02X:", baseMac[i]);
  74.   }
  75.   Serial.printf("%02X\n", baseMac[5]);
  76.   Serial.println("");
  77. }
  78.  
  79. void loop()
  80. {
  81.   RemoteXY_Handler ();
  82.  
  83.   if (RemoteXY.switch_01 != dernier_etat_switch_01){
  84.     dernier_etat_switch_01 = RemoteXY.switch_01;
  85.     digitalWrite(pin_sortie_relais_alimentation, RemoteXY.switch_01);
  86.     Serial.println("Relais : " + RemoteXY.switch_01);
  87.   }
  88.   itoa(millis(), RemoteXY.text_01, 10);
  89.  
  90. }

Who is online

Users browsing this forum: No registered users and 103 guests