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;
}
}