Arduino TVout Library cannot print string

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.

The code I used:

while (Serial.available() > 0)
{
char recieved = Serial.read();
inData += recieved;
if (recieved == '\n')
{
Serial.print(inData);
TV.println(inData);
inData = "";
}
}

The code I tried already:

TV.print(inData);
TV.printPGM(inData);

Exception I got:

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&)'

What can I do to solve this? Thanks in advance!

Exception I got:

You misspelled "compiler error" there.

no matching function for call to 'TVout::printPGM(String&)

Serial.print(inData);

Massive clue (it would've been even more obvious if you'd posted your code.)

Thanks for your quick reply, AWOL!

However, I don't really understand, could you please elaborate more?

You're using a String for a function that expects a string

to just reinforce what to look for...

You're using a String for a function that expects a string

:slight_smile:

AWOL:
You're using a String for a function that expects a string

What is the difference between a String and a string? :confused:
I would really want to learn more strings and things like this.

read this document

I still don't understand what to do. :o

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?

Why not simply "print" the characters, one-by-one, as they arrive?
I don't see the advantage of using a string, or a String in this case.

If I convert them to char, I would have to limit the size.

I don't understand what this means.

I would have to store it in a string, because it may not be displayed right after it is received, maybe after the user triggered a button.

Would you mind telling me what to do if I do have to store it in a string?

Thanks a lot! :slight_smile:

I think basic input string handling is covered in Robin2's serial handling basics tutorial.

Thanks for sharing that great tutorial!
http://forum.arduino.cc/index.php?topic=396450

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.

This is the code I used:

#include <TVout.h>
#include <fontALL.h>

const byte numChars = 32;
char receivedChars[numChars];

boolean newData = false;

TVout TV;

void setup() {
        TV.begin(NTSC,120,96);
  TV.select_font(font6x8);
  TV.println("started");
    Serial.begin(9600);
    Serial.println("<Arduino is ready>");
}

void loop() {
    recvWithEndMarker();
    showNewData();
}

void recvWithEndMarker() {
    static byte ndx = 0;
    char endMarker = '\n';
    char rc;
    
    while (Serial.available() > 0 && newData == false) {
        rc = Serial.read();

        if (rc != endMarker) {
            receivedChars[ndx] = rc;
            ndx++;
            if (ndx >= numChars) {
                ndx = numChars - 1;
            }
        }
        else {
            receivedChars[ndx] = '\0';
            ndx = 0;
            newData = true;
        }
    }
}

void showNewData() {
    if (newData == true) {
        Serial.print("This just in ... ");
        Serial.println(receivedChars);
        TV.println(receivedChars);
        newData = false;
    }
}

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!

One reason you will loose chars is this one

        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.

try changing

     Serial.begin(9600);

into

    Serial.begin(115200);

Thanks for your reply, J-M-L!

I followed your instructions, and also changed the baud rate of the HC05 Bluetooth module to 115200.

After that, I am able to receive all the characters sometimes, but not every time.

In many times, I am only able to receive the first 2 characters, or else I can only receive random characters.

Most of my strings are more than 40 characters.

Is there any way to solve this problem?

I followed your instructions

The implied, but unstated, instruction was that you post your modified code.

Is there any way to solve this problem?

Maybe.

comment out all the Serial.print and see if things are better. if they are you know where to look...

This is the code I am using. As I am using the TX and RX for my Bluetooth module, I can't remove the Serial.print.

#include <TVout.h>
#include <fontALL.h>

const byte numChars = 64;
char receivedChars[numChars];
boolean newData = false;

TVout TV;

void setup() {
  TV.begin(_NTSC, 120, 96);
  TV.select_font(font6x8);
  TV.println("started");
  Serial.begin(115200);
  Serial.println("<Arduino is ready>");
}

void loop() {
  recvWithEndMarker();
  showNewData();
}

void recvWithEndMarker() {
  static byte ndx = 0;
  char endMarker = '@';
  char rc;

  while (Serial.available() > 0 && newData == false) {
    rc = Serial.read();

    if (rc != endMarker) {
      receivedChars[ndx] = rc;
      ndx++;
      if (ndx >= numChars) {
        ndx = numChars - 1;
      }
    }
    else {
      receivedChars[ndx] = '\0';
      ndx = 0;
      newData = true;
    }
  }
}

void showNewData() {
  if (newData == true) {
    Serial.println(receivedChars);
    TV.println(receivedChars);
}
    newData = false;
  }

What can I modify to solve the problem?

Thanks in advance! :slight_smile:

ftc-jordan:
Why is this happening? Is it some kind of timing issue?

Very likely. You are trying to perform two tasks that both require a lot of processor time and very precise timing, purely in software.

As I am using the TX and RX for my Bluetooth module, I can't remove the Serial.print.

If some device is sending data to the Arduino, via the Bluetooth modules, why is it necessary to send that same data back to the sender?

if (newData == true) {
[color=red]    Serial.println(receivedChars);
[/color]    TV.println(receivedChars);
}