I used the following code to receive serial data, and then saved them as a string. However, when I tried to print them to Arduino TVout, it gives me an exception.
Arduino: 1.6.5 (Mac OS X), Board: "Arduino/Genuino Uno"
sketch_jul03c.ino: In function 'void loop()': sketch_jul03c:22: error: no matching function for call to 'TVout::printPGM(String&)' sketch_jul03c.ino:22:25: note: candidates are: In file included from sketch_jul03c.ino:1:0: /Users/jordanfung/Documents/Arduino/libraries/TVout/TVout.h:164:7: note: void TVout::printPGM(const char*) void printPGM(const char[]); ^ /Users/jordanfung/Documents/Arduino/libraries/TVout/TVout.h:164:7: note: no known conversion for argument 1 from 'String' to 'const char*' /Users/jordanfung/Documents/Arduino/libraries/TVout/TVout.h:165:7: note: void TVout::printPGM(uint8_t, uint8_t, const char*) void printPGM(uint8_t, uint8_t, const char[]); ^ /Users/jordanfung/Documents/Arduino/libraries/TVout/TVout.h:165:7: note: candidate expects 3 arguments, 1 provided no matching function for call to 'TVout::printPGM(String&)'
If I convert them to char, I would have to limit the size. However, the data coming from serial can vary. How can I achieve a variable size? Or are there any other simple way to just print the text to the TVout?
Using the example 2 of this tutorial, it worked very great at first. However, when I added the odes for TVout, something wrong happened. Some of the characters are missing.
For example if the text is: Testing Serial String Handling
The output I got before I inserted the TVout code: Testing Serial String Handling (everything is fine)
The output I got after I inserted the TVout code: Tstg Serlang
Why is this happening? Is it some kind of timing issue?
Thanks again for your help!
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
you keep adding stuff into receivedChars until you receive your endMarker and if the buffer is full then you just overwrite over and over the end of the buffer (that's what the consequence of if (ndx >= numChars) {ndx = numChars - 1;} will be)
Your buffer is only 32 chars (defined with numChars), so will fill up quickly. try bumping that to 64
Also anything that gets your program to pause while the serial input buffer gets filled in is likely to aggravate the problem, this time this will be the serial input buffer being overflown.
you do a lot of Serial.print which does not block unless the outgoing buffer is full. As you write at 9600 bauds, that's not too fast.. so Serial.print could become blocking and slowing down your program.