Sending bytes to BLE from AI2

Hi everyone,
I am needing some help with Bluetooth Low Energy. I am trying to simply send an Arduino device that is connected via BLE a variable of “2.” I need the fix to be able to replicate for sending other variables (single integer) to the device.
The device is connected, but it doesn’t appear to be receiving the byte that I am sending.
I cannot figure out what I’m doing wrong here, and I’ve scoured the forums and the Internet for help but am coming up short.

This is what I have so far:

Hi,
I am new to App Inventor and appear to be on a similar journey to yourself.
Don’t take my answer as gospel, but this worked for me.
I hard coded the UUIDs to make use of the BLE generic UART service.
Got these UUIDS here:


This is an Adafruit module which I think uses a different BLE chipset to the Arduino but I think the UUIDs should be the same.
On the Adafruit module the UART service is started automatically for you so i didn’t have to do anything special on that side.
Hope this helps.

blocks

Hi @Anna_C,

Can you also share the code for your Arduino sketch, at the very least how you are handling the receiving of the data from App Inventor? It will help us better understand where the problem might lay.

Here an example with WriteBytesWithResponse:

This is written based on standard Bluetooth which very well may be my problem, but I haven’t used Arduino sketches for BLE before, either.

char incomingByte = 1;
int ledPin = 4;

void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}

void loop()
{
if (Serial.available())
{
incomingByte = Serial.read();
}

digitalWrite(ledPin,HIGH);
delay(500);
digitalWrite(ledPin,LOW);
delay(incomingByte*60000);

}

So, through some other channels I have determined the issue!
I used Juan_Antonio’s “WriteBytesWithResponse” model to update my own code, and then also figured out I needed to use a ‘while’ statement rather than an ‘if’ statement in Arduino IDE.

Screenshots included for those that run into this issue in their own projects.

1 Like