Connecting via Bluetooth to the XIAO Sense module

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

Can you give better quality screenshot, because I tried to look at it couldn't understand even with zooming in? :smiling_face:

Please take a look at this image. TY

What about the button 1, 2 & 3's codes? Can you send them 1 by 1? :question:

I notice that all 4 UUIDs in your code are the same value.

Here are the latest versions of the BLE extension:



When BLE1 Connected


XIAo Sketch.txt (2.5 KB)

Thank you for all your help.

I have included all of the sketch and the Arduino code.

Your characteristics on the board:

BLEService LEDService("19b10000-e8f2-537e-4f6c-d104768a124");  //Service UUID hexadecimal numbers
BLEIntCharacteristic redCharacteristic("19b10001-e8f2-537e-4f6c-d104768a124", BLERead | BLEWrite | BLENotify);
BLEIntCharacteristic greenCharacteristic("19b10002-e8f2-537e-4f6c-d104768a124", BLERead | BLEWrite | BLENotify);
BLEIntCharacteristic blueCharacteristic("19b10003-e8f2-537e-4f6c-d104768a124", BLERead | BLEWrite | BLENotify);

Your characteristics in the app:

See the difference?

ABG,

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?

Thank you,

There is an app name attribute in Project Properties that might be relevant.

A deinstall of the old version would sweep clean.

Thank you ABG,

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!

If you need an extra eye or two, post the new blocks and sketch here.
Be sure to include the parts with the Characteristic definition and checking.

Hello ABG,

I am a bit perplexed. I continue to look though both the sketch and the MIT code. I am unable to get the green or the blue LED to turn on.

No matter which button I select I only get the red LED to turn on. According to the specs there is a REd, Blue, and a Green LED on this hardware.

I an trying to duplcate the activity shown the the following link:

I'm just not figuring this out. Can you take a look at the previous code to see if you can see the problem?

Thank you,

(Canned Reply: ABG- Export & Upload .aia)
Export your .aia file and upload it here.
export_and_upload_aia

XIAO_Ver1_8_9_24.aia (199.2 KB)
ABG,

Please see to uploaded file. ty

Here are your new characteristice from your latest .aia export:
image

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.

Here is alternative code:
initialize global Grey to




XIAO 8-9-24 Sketch.txt (3.0 KB)

Here is my latest sketch.

Thank you,

According to

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

Thank you ABG,,I will confirm that this is the proper way to talk to LED via the XIAO examples.

I will get back with you.

Sorry, I applied the wrong global variable name in one block:

I notice you varies wildly from the Service UUID in your choice of characteristic UUIDs.

Why?

Could there be a requirement of some similarity between the device UUID and characteristic UUIDs?

I notice you are one version behind in your BLE extension version.

The newer version handles permissions better.