Canonical mode serial reading failure

Man, I just can’t get my head around this one.

My Arduino is running a simple call/response program. If you sent it a byte, it will send back “Hello”.

void setup()

void loop()
 if (Serial.available() > 0)

The is to pop off the byte in the buffer so that Serial.available() won’t always be true and the program will stop sending “hello”.

Here’s my test program for writing out the byte to the Arduino, and receiving the response:

There’s really nothing special going on, but what happens is that read() says it’s returning 7 bytes, and if I cast one of the bytes to int it reads as 21, which doesn’t make sense. On the ascii table it’s “NAK”.

Anyways, I’ve beat my head against this enough today. I’ll hit it again next week.

This entry was posted in Hobbies, Programming. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s