Serial.available() returning unexpected results

Hello Jarboer, I am also new to Arduino, recently bought an Uno and getting to know it. I am refreshing now decades old computer programming experience, and I want to get the serial comms under my belt. I have been having a similar problem, the Serial.available() command was returning unexpected results, so I started feeding serial output in, via keyboard string inputs to observe how the available command would behave. I am using 9600 baud. My question, which I realize is pretty basic, is when I submit say 10 chars in one string, the buffer use shoots up to maybe 10 or 20, and then decays back to zero. I kind of expected to stay full. Where is the data going, as the buffer clears? Into the 2K RAM in the Arduino? Thanks.

@steven_lightfoot , you would be better off starting your own thread than posting in a solved thread. Members are not likely to look into a solved thread.

When you start a new thread, include your code. Read the forum guidelines to see how to properly post code and some good information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Where else :confused:

For an Uno, the Serial class has a 64 byte receive buffer (and a 64 byte transmit buffer). Concentrating on the receive, each character that is received is stored in that buffer; if the buffer is full, you have a problem.

The buffer does not clear unless you use Serial.read() or other functions that read the buffer.

I've reported your post so it can be moved to its own topic.

I have split the thread off from the original location at Why does Serial.available() not return 0 without entering any data into the Serial Monitor when the buad rate is higher than 9600? - #18 to a dedicated topic as requested.

Best wishes for success with your Arduino endeavors @steven_lightfoot.

Would you post the code you are using? If you are seeing unexpected results either your code, your expectations, or both are wrong.

1 Like

Thanks, I actually did this deliberately, to post to a close existing topic, as every time I made a new post (only a few so far) I got warnings about checking for existing posts, so I though users were actually discouraged from making new posts. I wont hesitate next time.

Please post your code.

Sure thank you. Your comments are good. I didn't think the buffer was emptied without specific action. I have discovered my problem, not obvious - The Serial.available() was returning one too many bytes, after more research discovered it was CR, and I had my Serial mon input settings wrong, did not know in fact I could change them, so all is good with no line ending set. Thx.

Thank you. Problem solved - bad serial mon input settings, for character input.

All good, bad serial mon settings. I learned something!

It is good that you did look. The reason that it asks you to look for related posts is that, often, you may find an answer to your question and so no need to open a thread. Any member that has been here for very long will tell you of several questions that get asked over and over. If you look and cant't find help, fine, ask away. Not even looking is just lazy.

1 Like

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