List index too large, Select list item

When i want to run my app on my celphone it show me that, ando i dont know where the error is


Someone can help me plz

2 Likes

Check that you have set your BlueTooth Delimiter to 10 and that your device uses println() only at the end of each message.
Also count the number of '|' in each message. A short count will give you an error.

Standard advice:

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.
BlueToothClient1_Properties
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.

P.S. You should also up load the .ino file of your sketch.

2 Likes

Here is my ino code

int TempF;
int TempC;
int LuzLDR;
int Humedad;
double UltraS;

double fnc_ultrasonic_distance(int _t, int _e) {
double dur = 0;
digitalWrite (_t, LOW);
delayMicroseconds (2);
digitalWrite (_t, HIGH);
delayMicroseconds (10);
digitalWrite (_t, LOW);
dur = pulseIn (_e, HIGH);
return (dur/ 29.0 / 2.0);

}
void setup() {
Serial.begin(9600);

pinMode (A0, INPUT);
pinMode (A1, INPUT);
pinMode (A2, INPUT);
pinMode (4, INPUT);
pinMode (5, INPUT);

}

void loop() {
TempF = (analogRead(A0) * 0.48828125);
TempC = (((TempF - 32)) / 1.8);
Serial.print(TempC);
Serial.print(String("|"));
LuzLDR = map(analogRead(A1), 0, 1023, 0, 100);
Serial.print(LuzLDR);
Serial.print(String("|"));
Humedad = map(analogRead(A2), 0, 1023, 100, 0);
Serial.print(Humedad);
Serial.print(String("|"));
UltraS = fnc_ultrasonic_distance(4, 5);
Serial.print(UltraS);
Serial.print(String("|"));

delay(1000);

}

1 Like

I don't see a println() to end each line.
The BlueTooth GetText(-1) can't work without that.

2 Likes

Sorry, im new in arduino, its a project.

int TempF;
int TempC;
int LuzLDR;
int Humedad;
double UltraS;

double fnc_ultrasonic_distance(int _t, int _e) {
double dur = 0;
digitalWrite (_t, LOW);
delayMicroseconds (2);
digitalWrite (_t, HIGH);
delayMicroseconds (10);
digitalWrite (_t, LOW);
dur = pulseIn (_e, HIGH);
return (dur/ 29.0 / 2.0);

}
void setup() {
Serial.begin(9600);

pinMode (A0, INPUT);
pinMode (A1, INPUT);
pinMode (A2, INPUT);
pinMode (4, INPUT);
pinMode (5, INPUT);

}

void loop() {
TempF = (analogRead(A0) * 0.48828125);
TempC = (((TempF - 32)) / 1.8);
Serial.print(TempC);
println(String("|"));
LuzLDR = map(analogRead(A1), 0, 1023, 0, 100);
Serial.print(LuzLDR);
println(String("|"));
Humedad = map(analogRead(A2), 0, 1023, 100, 0);
Serial.print(Humedad);
println(String("|"));
UltraS = fnc_ultrasonic_distance(4, 5);
Serial.print(UltraS);
println(String("|"));

delay(1000);

}

1 Like

Wrong.

Use only one println(), at the end.

Your AI2 blocks expect half a dozen values at a time, on one line.
You are sending half a dozen separate lines, so that will make your lists have only one item each.

2 Likes

TempF = (analogRead(A0) * 0.48828125);
TempC = (((TempF - 32)) / 1.8);
Serial.print(TempC);
Serial.print(String("|"));
println();
LuzLDR = map(analogRead(A1), 0, 1023, 0, 100);
Serial.print(LuzLDR);
Serial.print(String("|"));
println();
Humedad = map(analogRead(A2), 0, 1023, 100, 0);
Serial.print(Humedad);
Serial.print(String("|"));
println();
UltraS = fnc_ultrasonic_distance(4, 5);
Serial.print(UltraS);
Serial.print(String("|"));
println();

Somthing like that?

1 Like

I have other code where it works but at the next day when i test it doesnt work

1 Like

Is there some one on this board who can explain in this poster's language?

I am not getting through to them.

2 Likes

1 Like

I see what you are coding .
I can't understand why you don't see what I am recommending!

1 Like

I have been away helping people who listen to me.

Here is an idea to possibly penetrate the language barrier ...

How many
lines
are there
in this
question?

(Answer with a number)

2 Likes

five lines in that question

Correct!

Now examine your .ino file.

How many lines does it send to BlueTooth in a single loop() ?

1 Like

Four lines are sending in single loop in the .ino file

It took you one month to figure out how many lines each loop emits?

So here is the problem.

You emit 4 lines, but you set up the AI2 app to expect only one line with all 4 pieces of data on it. The sending and receiving side must agree on how the data is packed and unpacked.

Here is a recent thread where some one else is dealing with this problem.

I suggest reading their sending code, and waiting to see how they fix their receiving code.