Hello all,
I have a project I am working on where the following is happening:
- An android phone is sending strings of data to an arduino over bluetooth, coming into arduino over serial. Arduino baudrate is 9600, bluetooth module (HC-06) also at 9600.
- Each loop, the arduino checks if there is serial data available, and reads it char by char
- it builds a string char by char, and when it gets to a '/' char, it writes the string to a text file on an SD card.
- it clears the string to be built up again by subsequently received data.
I am sending 100 strings total, each with a length of 195 ASCII chars.
All of that is working (mostly) fine. The issue I'm having is that, pretty consistently, on a few lines received I am missing a handful of chars. I seem to always be receiving the delimiter ('/') just fine, but some chars are missing from somewhere in the middle of the group.
When I print out the length of the resulting string after each '/' received, i get all 195's (which is correct) except for maybe 3 or 4 of the 100 lines (that number seems to vary) which print 176. So 19 chars are missing from each of these strings.
I did find one other (hopefully helpful) bit of information out - when I print out Serial.available() with each char received, I am seeing a corresponding spike in how many bytes are available with the lines that are missing chars.
For example, when I print Serial.available() each time the loop runs, I see values that start at 1 and ramp up to 62, maintain at 62 for the majority of the 100 lines sent, then ramp back down to 1 at the end. BUT, around the lines that are missing data, I am seeing that 62 number jump up to 63.
My question is (and it may be stupid), is the serial buffer overflowing when these values read 63, and are therefore not all read before the next set of data comes in? Am I sending data faster than it can be received at my current baudrate?
If so, are there any clever solutions to this problem other than increasing baudrate or decreasing the speed at which I am sending data?
Alternatively, am I fundamentally misunderstanding the problem and need to look somewhere else for a solution?
Thanks in advance. I will post my code if necessary, but I hope the above description does an adequate job on its own.
Best,
Brian