A problem with connecting BLE device to Arduino Uno R4 WiFi

Hello. I am a newbie with Arduino. I am trying to connect my Xbox One wireless controller to my Arduino Uno R4 WiFi. I intend to use the controller to send wireless signals to Arduino and use those to control output on pins.

I am working with BLE library since both the Xbox controller and R4 support BLE. Arduino sees my Xbox controller, but it seems unable to connect to it. It does print the "Connected" message, yet the controller doesn't act as if it was connected. The Xbox logo should start glowing steady light, instead, it is still pulsating, as if it is waiting for the connection.

Additionally, the discoverAttributes() function cannot resolve. Arduino prints "Discovering attributes ..." message, and it seems to be stuck on that.

Also, for some reason, I need to reinstall firmware after each test, if I don't BLE fails to start at all.

If anyone knows what to do, I would be really grateful for help.

#include <ArduinoBLE.h>
void setup() {
  Serial.begin(9600);
  while (!Serial);

  // initialize the Bluetooth® Low Energy hardware
  if (!BLE.begin()) {
    Serial.println("Fail");
  }

  Serial.println("Bluetooth® Low Energy Central - LED control");

  // start scanning for peripherals
  BLE.scanForUuid("1812");
}

void loop() {
  BLEDevice peripheral = BLE.available();
  
   if (peripheral) {
    // discovered a peripheral, print out address, local name, and advertised service
    Serial.print("Found ");
    Serial.print(peripheral.address());
    Serial.print(" '");
    Serial.print(peripheral.localName());
    Serial.print("' ");
    Serial.print(peripheral.advertisedServiceUuid());
    Serial.println();
   }
    
   if (peripheral.connect()) {
      Serial.println("Connected");
    } else {
      Serial.println("Failed to connect!");
      return;
    }

    Serial.println("Discovering attributes ...");
    if (peripheral.discoverAttributes()) {
      Serial.println("Attributes discovered");
    } else {
      Serial.println("Attribute discovery failed!");
      peripheral.disconnect();
      return;
    }
}

You might try using an example from the ArduinoBLE library called PeripheralExplorer.
It sets up the Arduino as a central device and then scans for peripheral devices. You may have to modify the sketch since it is looking for a specific peripheral name of LED, before connecting.
I hope this helps.

Hello, thanks for you response.

I did use examples while making this little Frankenstein of a code - that's why it says 'LED control'. The UID is the service UID of my controller that I found via earlier scans.

As I said, it does find the correct device, just don't do anything after it is found.

There is most likely some protocol handshaking that occurs. For some ideas, you might search for the Xbox controller, BLE, and the ESP-32.
Sorry, I cannot supply the answer since I have no experience with HID controllers and BLE.
I have implemented a BLE interface for the UNO R4 WIFI that uses BLE serial. In my case, the UNO R4 is a peripheral and a Python script acts as the central. The telemetrix library is somewhat similar to StandardFirmata. For the UNO R4 WIFI it supports WIFI, USB Serial, and BLE transports.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.