Question

I'm sending serial data from an arduino to an android device.

Here is the code I have for the arduino sketch:

void setup(){
Serial.begin(9600);
  delay(10000);

Serial.println(4);
delay(2000);
Serial.println(7);
delay(2000);
Serial.println(7);
delay(2000);
Serial.println(5);

}

void loop()                   
{

  }

And what the data that prints on my Android device begins: [53, 13, 10, 0, 0...] with the rest of the numbers being zero. Now the size of the array I'm sending this data to is 1024 so I know why it keeps printing zeros, but what is going on with the first couple of numbers?

Was it helpful?

Solution

Serial.println(5);

Will indeed produce the sequence of bytes

[53, 13, 10,

Because the ascii code for '5' is 53, while println appends a carriage return (13) and newline(10).

It would appear you have missing your beginning. Be aware that your data will not necessarily be received in chunks of meaningful size, but instead my dribble in bit by bit in smaller packets which break up a message, or larger ones which combine messages, or both.

OTHER TIPS

The value "53" is the ascii value for the character "5", followed by a carriage-return (13) and line feed (10).

That matches your last println() statement.

Why the previous data is not visible is hard to say without the receiving end. Please provide the android code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top