if i do this is shows select list item: atempt to get item no 2 of list of length 1
..... except that your events are eating into the memory allocation for the App - if it goes beyond maximum, the App will start crashing.
Edit: Also, before you fire a Bluetooth Event (e.g. send) you must check that BT is connected. So all your Button Touch Events need that.
On the App side, you seem to be missing the Delimiter Byte setting. It's good practice to set Clock Timer Intervals in the Screen Initialise Block. See the attached file - you can copy paste relevant Blocks via the Backpack.
BT_Basic_Setup_ReceiveMulti.aia (8.4 KB)
- Why two microcontrollers?
- Do all of the expected results get displayed in the Serial Monitor?
A little less haste would help to ensure your Project is more robust.
Arduino_nano_analog_input_and_transfer.ino is incomplete!
Button 7 is missing - is that an unlucky number or something?
That's because you are sending every value with Serial.println() - should be Serial.print() Like this:
Serial.print(MyVal1);
Serial.print("|");
Serial.print(MyVal2);
Serial.print("|");
Serial.print(MyVal3);
Serial.print("|");
Serial.println(); //Blank (empty): Tells App 'End of data stream'
To clarify: The Arduino Mega is driven by Sketch INK_key.ino and that board sends the data stream to the App?
I can only see 17 values added to the data stream via INK_key.ino
It looks as though there is a data stream in......... Arduino_nano_analog_input_and_transfer.ino......that is intended to be sent to the App directly and not to the Mega?
That stream consists of 10 values (outputValue17 is sent twice)
Need some concise, accurate, unhurried answers to my questions Aniket.
I can't see your Clock Timer Block clearly to see if there is anything in detail wrong - if you have corrected it as per my example then I'd like to see a screenshot of just that Block. However, the inconsistent value count per stream is caused by your Sketch code, not the App code.
You have more than a minor error - for the task in hand, the code needs to have reliability built in.
yes! you are right.
nano send via serial to mega
while after 17values of mega there it receives the value from nano and mega sends all 24 to BT module.
i have deleted the twice outputValue17 and it sends b to end the value.
The mega Sketch Serial prints 17 values outputValue1, outputValue2 etc +
Serial.print(link.readStringUntil('b')) which is from the Nano Sketch - the Nano Sketch should not have the last value divider "|" before 'b'.
There is no loop time interval in the Nano Sketch, so values are streamed on top of prior values before they reach the App via the mega. The App time interval needs to be 20% shorter than the mega to ensure all values are read and processed before the next stream arrives, but it must not be so short that the App process fails to complete before the next stream arrives.
The Nano Sketch loop:
void loop()
{
outputValue17 = map(analogRead(A0), 0, 1023, 0, 99);
outputValue18 = map(analogRead(A1), 0, 1023, 0, 99);
outputValue19 = map(analogRead(A2), 0, 1023, 0, 99);
outputValue20 = map(analogRead(A3), 0, 1023, 0, 99);
outputValue21 = map(analogRead(A4), 0, 1023, 0, 99);
outputValue22 = map(analogRead(A5), 0, 1023, 0, 99);
outputValue23 = map(analogRead(A6), 0, 1023, 0, 99);
outputValue24 = map(analogRead(A7), 0, 1023, 0, 99);
if(Serial.available()>0)
{
char a =(Serial.read());
if(a =='a')
{
Serial.print(outputValue17); Serial.print("|");
Serial.print(outputValue18); Serial.print("|");
Serial.print(outputValue19); Serial.print("|");
Serial.print(outputValue20); Serial.print("|");
Serial.print(outputValue21); Serial.print("|");
Serial.print(outputValue22); Serial.print("|");
Serial.print(outputValue23); Serial.print("|");
Serial.print(outputValue24);
Serial.print('b');
}
}
delay(1200);
}
The mega Sketch loop:
void loop()
{
outputValue1 = map(analogRead(A0), 0, 1023, 0, 99);
outputValue2 = map(analogRead(A1), 0, 1023, 0, 99);
outputValue3 = map(analogRead(A2), 0, 1023, 0, 99);
outputValue4 = map(analogRead(A3), 0, 1023, 0, 99);
outputValue5 = map(analogRead(A4), 0, 1023, 0, 99);
outputValue6 = map(analogRead(A5), 0, 1023, 0, 99);
outputValue7 = map(analogRead(A6), 0, 1023, 0, 99);
outputValue8 = map(analogRead(A7), 0, 1023, 0, 99);
outputValue9 = map(analogRead(A8), 0, 1023, 0, 99);
outputValue10 = map(analogRead(A9), 0, 1023, 0, 99);
outputValue11 = map(analogRead(A10), 0, 1023, 0, 99);
outputValue12 = map(analogRead(A11), 0, 1023, 0, 99);
outputValue13 = map(analogRead(A12), 0, 1023, 0, 99);
outputValue14 = map(analogRead(A13), 0, 1023, 0, 99);
outputValue15 = map(analogRead(A14), 0, 1023, 0, 99);
outputValue16 = map(analogRead(A15), 0, 1023, 0, 99);
Serial.print(outputValue1);
Serial.print("|");
Serial.print(outputValue2);
Serial.print("|");
Serial.print(outputValue3);
Serial.print("|");
Serial.print(outputValue4);
Serial.print("|");
Serial.print(outputValue5);
Serial.print("|");
Serial.print(outputValue6);
Serial.print("|");
Serial.print(outputValue7);
Serial.print("|");
Serial.print(outputValue8);
Serial.print("|");
Serial.print(outputValue9);
Serial.print("|");
Serial.print(outputValue10);
Serial.print("|");
Serial.print(outputValue11);
Serial.print("|");
Serial.print(outputValue12);
Serial.print("|");
Serial.print(outputValue13);
Serial.print("|");
Serial.print(outputValue14);
Serial.print("|");
Serial.print(outputValue15);
Serial.print("|");
Serial.print(outputValue16);
Serial.print("|");
link.println("a"); //where is this going?
Serial.print(link.readStringUntil('b'));
Serial.println();
delay(1000);
if (Serial.available()>0)
{
char Incoming_value = Serial.read();
if(Incoming_value == 'A') {digitalWrite(C1,LOW);}
if(Incoming_value == 'B') {digitalWrite(C1,HIGH);}
if(Incoming_value == 'C') {digitalWrite(C2,LOW);}
if(Incoming_value == 'D') {digitalWrite(C2,HIGH);}
if(Incoming_value == 'E') {digitalWrite(C3,LOW);}
if(Incoming_value == 'F') {digitalWrite(C3,HIGH);}
if(Incoming_value == 'G') {digitalWrite(C4,LOW);}
if(Incoming_value == 'H') {digitalWrite(C4,HIGH);}
if(Incoming_value == 'I') {digitalWrite(C5,LOW);}
if(Incoming_value == 'J') {digitalWrite(C5,HIGH);}
if(Incoming_value == 'K') {digitalWrite(C6,LOW);}
if(Incoming_value == 'L') {digitalWrite(C6,HIGH);}
if(Incoming_value == 'M') {digitalWrite(C7,LOW);}
if(Incoming_value == 'N') {digitalWrite(C7,HIGH);}
if(Incoming_value == 'O') {digitalWrite(C8,LOW);}
if(Incoming_value == 'P') {digitalWrite(C8,HIGH);}
if(Incoming_value == 'Q') {digitalWrite(C9,LOW);}
if(Incoming_value == 'R') {digitalWrite(C9,HIGH);}
if(Incoming_value == 'S') {digitalWrite(C10,LOW);}
if(Incoming_value == 'T') {digitalWrite(C10,HIGH);}
if(Incoming_value == 'U') {digitalWrite(C11,LOW);}
if(Incoming_value == 'V') {digitalWrite(C11,HIGH);}
if(Incoming_value == 'W') {digitalWrite(C12,LOW);}
if(Incoming_value == 'X') {digitalWrite(C12,HIGH);}
if(Incoming_value == 'Y') {digitalWrite(C13,LOW);}
if(Incoming_value == 'Z') {digitalWrite(C13,HIGH);}
if(Incoming_value == '0') {digitalWrite(C14,LOW);}
if(Incoming_value == '1') {digitalWrite(C14,HIGH);}
if(Incoming_value == '2') {digitalWrite(C15,LOW);}
if(Incoming_value == '3') {digitalWrite(C15,HIGH);}
if(Incoming_value == '4') {digitalWrite(C16,LOW);}
if(Incoming_value == '5') {digitalWrite(C16,HIGH);}
if(Incoming_value == '6') {digitalWrite(C17,LOW);}
if(Incoming_value == '7') {digitalWrite(C17,HIGH);}
if(Incoming_value == '8') {digitalWrite(C18,LOW);}
if(Incoming_value == '9') {digitalWrite(C18,HIGH);}
if(Incoming_value == '~') {digitalWrite(C19,LOW);}
if(Incoming_value == '`') {digitalWrite(C19,HIGH);}
if(Incoming_value == '!') {digitalWrite(C20,LOW);}
if(Incoming_value == '@') {digitalWrite(C20,HIGH);}
if(Incoming_value == '#') {digitalWrite(C21,LOW);}
if(Incoming_value == '$') {digitalWrite(C21,HIGH);}
if(Incoming_value == '%') {digitalWrite(Unit1,LOW);} if(Incoming_value == '^') {digitalWrite(Unit1,HIGH);}
if(Incoming_value == '&') {digitalWrite(Unit2,LOW);} if(Incoming_value == '*') {digitalWrite(Unit2,HIGH);}
if(Incoming_value == '(') {digitalWrite(Unit3,LOW);} if(Incoming_value == ')') {digitalWrite(Unit3,HIGH);}
if(Incoming_value == '_') {digitalWrite(Unit4,LOW);} if(Incoming_value == '-') {digitalWrite(Unit4,HIGH);}
if(Incoming_value == '+') {digitalWrite(Forward,LOW);}
if(Incoming_value == '=') {digitalWrite(Forward,HIGH);}
if(Incoming_value == '[') {digitalWrite(Reverse,LOW);}
if(Incoming_value == ']') {digitalWrite(Reverse,HIGH);}
if(Incoming_value == 'a') {digitalWrite(RelayA,LOW);}
if(Incoming_value == 'b') {digitalWrite(RelayA,HIGH);}
if(Incoming_value == 'c') {digitalWrite(RelayB,LOW);}
if(Incoming_value == 'd') {digitalWrite(RelayB,HIGH);}
if(Incoming_value == 'e') {digitalWrite(RelayC,LOW);}
if(Incoming_value == 'f') {digitalWrite(RelayC,HIGH);}
if(Incoming_value == 'g') {digitalWrite(RelayD,LOW);}
if(Incoming_value == 'h') {digitalWrite(RelayD,HIGH);}
if(digitalRead(LimitA)==LOW && Incoming_value == 'i') {digitalWrite(RelayU, LOW);}
if(Incoming_value == 'j') {digitalWrite(RelayU, HIGH);}
if(digitalRead(LimitB)==LOW && Incoming_value == 'k') {digitalWrite(RelayN, LOW);}
if(Incoming_value == 'l') {digitalWrite(RelayN, HIGH);}
if(digitalRead(LimitC)==LOW && Incoming_value == 'm') {digitalWrite(RelayL, LOW);}
if(Incoming_value == 'n') {digitalWrite(RelayL, HIGH);}
if(digitalRead(LimitD)==LOW && Incoming_value == 'o') {digitalWrite(RelayR, LOW);}
if(Incoming_value == 'p') {digitalWrite(RelayR, HIGH);}
if(digitalRead(LimitE)==LOW && Incoming_value == 'q') {digitalWrite(Inkin, LOW);}
if(Incoming_value == 'r') {digitalWrite(Inkin, HIGH);}
if(digitalRead(LimitF)==LOW && Incoming_value == 's') {digitalWrite(Inkde, LOW);}
if(Incoming_value == 't') {digitalWrite(Inkde, HIGH);}
}
}
Instead of half a million ifs, use Switch -Case.
brother mine i think this will solve my problem !
thank you in advance !
ill try and see
Fingers and toes crossed it will be better.
OK.! so whenever i do receive no of bytes -1 is says attempt to get item no 2 of list of length 1
When i do receive text no of bytes bytes able to receive is send me the list but the values change sometime is shows value to 2 in 7 or value of 1 in 8 it varries
and if i add delay in program then the buttons respond after the delay
so delay is not the option
As I explained before, -1 will receive all bytes available, it's the only method to ensure this. If all the expected values are not arriving, there is something wrong in the Sketch code.
It could be in the timing, so experiments are needed. The first experiment would be to exchange the data stream only once.
To do that, make copies of the Sketches. Remove the loop() and instead put the Serial comms in setup().
In the App, just send the data to a label without splitting it.
Did you get it to work?