I wish to use some code thawas used by anothe project on this XIAO module. However the way that BLE connects via Android has changed since the original code was created.
I believe that I could figure out the new code that I want to make but I have to first get conennected to the XIAO
Thank you for your help.
I have replaced all of the UUIs with those which match in the Arduino code.
However, when I build the latest apk file of XIAO _Ver1_7_30_24 and dowload it , somehow my tablet is opening and older apk fie of XIAO _Ver_6_10_24.
Do I need to clear out a cashe or something to get the newest file to load?
After making the changes to the UUIDs and removing the app name from the Attribute, the XIAO began to download, install and connect. I am only able to achieve getting the red LED to light on the XIAO board... I need to confrim that I have the "Sense" board.. I'm just not sure at this time why only the red led is coming on.
I'm soo very grateful for your assistance in this project. Thank you very much!
Here are your new characteristice from your latest .aia export:
Now NONE of them match your sketch's UUIDs at
Maybe you should also post your new sketch too?
Also, I do not like the way you are using background color of buttons to remember their states.
The color blocks look too similar to the coder and might not be exact matches, block to block.
(I once got burned by this doing a Wordle app.)
I renamed the three color buttons to help code readability.
you are missing a test of the characteristic value, like that '1' or '0' you are sending.
(I missed that code all the way to the right in the sketch. But do the data types (char vs int match?))
Also, is that any way to talk to an LED?
Your code, for the phone users:
XIAO 8-9-24 Sketch
include <ArduinoBLE.h>
// Theses are the BLE UUIDs
BLEService LEDService("f4b3c654-39f9-423a-8639-53010dc4301c"); //Service UUID hexadecimal numbers
BLEIntCharacteristic redCharacteristic("bc776cf6-50d7-41cf-9999-55df941b2b9d", BLERead | BLEWrite | BLENotify);
BLEIntCharacteristic greenCharacteristic("d3c69083-8afc-46d1-bd5a-fcca8893e7b2", BLERead | BLEWrite | BLENotify);
BLEIntCharacteristic blueCharacteristic("9e2d6c3f-98ea-4e7d-95ad-2b8a88fbf97a", BLERead | BLEWrite | BLENotify);
const int redPIN = LEDR; //pin to use for the red LED (D11)
const int greenPIN = LEDG; //pin to use for the green LED (D12)
const int bluePIN = LEDB; //pin to use for the red LED (D13)
void setup() {
pinMode(redPIN, OUTPUT); //set pins as outputs and set LED's HiGH ( HIGH is off for this board)
digitalWrite(redPIN, HIGH);
pinMode(greenPIN, OUTPUT);
digitalWrite(greenPIN, HIGH);
pinMode(bluePIN, OUTPUT);
digitalWrite(bluePIN, HIGH);
if (!BLE.begin()) { // begin initialization
while (1) ; // wait until initialization is complete
}
BLE.setLocalName("BLE_RGB"); // set advertised local name
BLE.setAdvertisedService(LEDService); // set advertised service UUID
LEDService.addCharacteristic(redCharacteristic); // add the red characteristic to the service
LEDService.addCharacteristic(greenCharacteristic); // add the green characteristic to the service
LEDService.addCharacteristic(blueCharacteristic); // add the blue characteristic to the service
BLE.addService(LEDService); // add service
BLE.advertise(); // start advertising
}
void loop() {
BLEDevice central = BLE.central(); // listen for BLE devices to connect: Not sure that this works for ESP32
if (central) { // if a central is connected to peripheral
// put code here to perform 1 time when device is connected
while (central.connected()) { // While the central is still connected to peripheral
// if there is an update from the Android App, change light ON (0) or OFF (1)
if (redCharacteristic.written()) digitalWrite(redPIN, redCharacteristic.value());
if (greenCharacteristic.written()) digitalWrite(greenPIN, greenCharacteristic.value());
if (blueCharacteristic.written()) digitalWrite(bluePIN, blueCharacteristic.value());
} // end of while loop
} // you can put code here for what to do when not conected
} // end of loop