문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top