Digits being dropped between HC-05/Arduino and app inventor

I’m trying to get a basic app to work that receives data from a potentiometer and graphs the results. The app works in general but every so often (every 5 - 30 seconds) a digit is dropped and therefore my graph is not a smooth curve. I’m just beginning with app inventor so please help point me in the correct direction to solve the issues.

Here is my Arduino code:

int in = A0;

void setup() {
Serial.begin(9600);
pinMode(in,INPUT);

}

void loop() {
//Map the value from 10 bits to 8 bits:

byte val = map(analogRead(in),0,679.0,0,255); //map 3.3volts to 255 (1023*3.3/5)
Serial.print(val);
Serial.println("\n");
delay(5000); //Small delay between each data send
}

And here's my blocks

I tried to fix the the dropped digit by using a delimeter and the "\n" but that now does not read the data at all. It shows "Run Time Error The operation yail-divide cannot accept the arguments: , [ ], [255]"

So I think I have at least two errors in the current code shown. Thanks for any help.

Doug

This sequence sends values followed by two newlines, one from the println, and the second from the \n.

Your data arrives at AI2 interspersed with empty lines as a result.

All you needed was

Serial.println(val)

I don't understand why you had to map your data into a byte just to have Serial.print remap it into text.

Your blocks look okay, as long as you receive more often than your Arduino sends.

(I did not look at the math to map to the Canvas height.)

1 Like

That was it! Thanks

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.