Arduino to android error

getting led status from arduino to android. it works for few seconds, then i am getting this error

Check what is coming back in global input, then check if this makes a list for global list (not a good name!)

thank you for your reply sir!

actually i am just a newbie, How can I do that sir?

Set one of your labels to global input value and just run the clock once. Check what is in the label.

Hi good day!
Can I ask something from an expert like you?

My expertise is in knowing who else is a real expert, so I made your post public.
Ask away.

1 Like

Post your Arduino code here.
Also read:

Please see the Delimiter article in FAQ

Be sure to use println() at the end of each message to send from the sending device, to signal end of message. Do not rely on timing for this, which is unreliable.

In the AI2 Designer, set the Delimiter attribute of the BlueTooth Client component to 10 to recognize the End of Line character.

Also, return data is not immediately available after sending a request,
you have to start a Clock Timer repeating and watch for its arrival in the Clock Timer event. The repeat rate of the Clock Timer should be faster than the transmission rate in the sending device, to not flood the AI2 buffers.

In your Clock Timer, you should check

  Is the BlueTooth Client still Connected?
  Is Bytes Available > 0?
     IF Bytes Available > 0 THEN
       set message var  to BT.ReceiveText(-1) 

This takes advantage of a special case in the ReceiveText block:

ReceiveText(numberOfBytes)
Receive text from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.

If you are sending multiple data values per message separated by | or comma, have your message split into a local or global variable for inspection before trying to select list items from it. Test if (length of list(split list result) >= expected list length) before doing any select list item operations, to avoid taking a long walk on a short pier. This bulletproofing is necessary in case your sending device sneaks in some commentary messages with the data values.

thank you very much. will check on this.

int RedRGB = 3;
int GrRGB = 5;
int BlRGB = 6;
int LED1 = 2;
int LED2 = 4;
int LED3 = 7;
int But1 = 8;
int But2 = 9;
int But3 = 10;
int LED1state = 0;
int LED2state = 0;
int LED3state = 0;
int But1NEW;
int But2NEW;
int But3NEW;
int But1OLD = 1;
int But2OLD = 1;
int But3OLD = 1;
int dt = 100;
String data;



void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(RedRGB, OUTPUT);
  pinMode(GrRGB, OUTPUT);
  pinMode(BlRGB, OUTPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(But1, INPUT_PULLUP);
  pinMode(But2, INPUT_PULLUP);
  pinMode(But3, INPUT_PULLUP);

}

void loop() {
  // put your main code here, to run repeatedly:

  But1NEW = digitalRead(But1);
  But2NEW = digitalRead(But2);
  But3NEW = digitalRead(But3);
  data = Serial.readString();

  if (LED1state == 1) {
    Serial.print("ON");
  }
  else {
    Serial.print("OFF");
  }
  Serial.print("|");
  if (LED2state == 1) {
    Serial.print("ON");
  }
  else {
    Serial.print("OFF");
  }
  Serial.print("|");
  if (LED3state == 1) {
    Serial.print("ON");
  }
  else {
    Serial.println("OFF");
  }










  if (But1OLD == 1 && But1NEW == 0) {
    if (LED1state == 0) {
      digitalWrite(LED1, HIGH);
      LED1state = 1;
    }
    else {
      digitalWrite(LED1, LOW);
      LED1state = 0;
    }
    But1NEW = But1OLD;
  }

  if (data == "LV1") {
    if (LED1state == 0) {
      digitalWrite(LED1, HIGH);
      LED1state = 1;
    }
    else {
      digitalWrite(LED1, LOW);
      LED1state = 0;
    }
  }

  if (But2OLD == 1 && But2NEW == 0) {
    if (LED2state == 0) {
      digitalWrite(LED2, HIGH);
      LED2state = 1;
    }
    else {
      digitalWrite(LED2, LOW);
      LED2state = 0;
    }
    But2NEW = But2OLD;
  }

  if (data == "LV2") {
    if (LED2state == 0) {
      digitalWrite(LED2, HIGH);
      LED2state = 1;
    }
    else {
      digitalWrite(LED2, LOW);
      LED2state = 0;
    }
  }

  if (But3OLD == 1 && But3NEW == 0) {
    if (LED3state == 0) {
      digitalWrite(LED3, HIGH);
      LED3state = 1;
    }
    else {
      digitalWrite(LED3, LOW);
      LED3state = 0;
    }
    But3NEW = But3OLD;
  }

  if (data == "LV3") {
    if (LED3state == 0) {
      digitalWrite(LED3, HIGH);
      LED3state = 1;
    }
    else {
      digitalWrite(LED3, LOW);
      LED3state = 0;
    }
  }
  if (data == "green") {
    digitalWrite(GrRGB, HIGH);
    digitalWrite(RedRGB, LOW);
    digitalWrite(BlRGB, LOW);
  }
  if (data == "off") {
    digitalWrite(GrRGB, LOW);
    digitalWrite(RedRGB, LOW);
    digitalWrite(BlRGB, LOW);
  }
  if (data == "white") {
    digitalWrite(GrRGB, HIGH);
    digitalWrite(RedRGB, HIGH);
    digitalWrite(BlRGB, HIGH);
  }

  if (data == "red") {
    digitalWrite(GrRGB, LOW);
    digitalWrite(RedRGB, HIGH);
    digitalWrite(BlRGB, LOW);
  }
  if (data == "blue") {
    digitalWrite(GrRGB, LOW);
    digitalWrite(RedRGB, LOW);
    digitalWrite(BlRGB, HIGH);
  }
  if (data == "yellow") {
    analogWrite(GrRGB, 255);
    analogWrite(RedRGB, 255);
    analogWrite(BlRGB, 0);
  }
  if (data == "orange") {
    analogWrite(GrRGB, 50);
    analogWrite(RedRGB, 255);
    analogWrite(BlRGB, 0);
  }
  if (data == "aqua") {
    analogWrite(GrRGB, 255);
    analogWrite(RedRGB, 0);
    analogWrite(BlRGB, 200);
  }
  if (data == "violet") {
    analogWrite(GrRGB, 0);
    analogWrite(RedRGB, 150);
    analogWrite(BlRGB, 155);
  }
}

This section of code causes you to lose the necessary line feed end of message delimiter when LED3state == 1.
To fix this, do a Serial.println("")
after your last if/then/else sequence, and just use print() for data before that.

This is necessary, in addition to changing your BT ReceiveText block to ask for -1 bytes and setting BT delimiter to 10.

thank you for that info

how to do this sir?


global message
(draggable)

thank you very much sir

thank you veru much sir. indeed it has removed that error, however it now takes around 10 seconds for that message to reach the android

Have Clock1 run more frequently (small ms value) than the Arduino transmissions, otherwise it will fall behind.

thank you very much