display.print() does not accept \r ???

I am new to arduino but not new to programming, even though I did it long time ago. :*
I am playing with a LCD TFT module and I want to show some variables on the display ( like: "Time: 10:30:24") and have the data update.

I used to use the \r control character to have the cursor come back to the beginning of the same line and rewrite the same line with the new variable, something like that:

display.print("Time: ");
display.print(GPS.hour, DEC); display.print(':');
display.print(GPS.minute, DEC); display.print(':');
display.print(GPS.seconds, DEC); display.print("\r")

But it does not work, the cursor does not come back, it just ignores the \r:
Time: 6:12:46Time: 6:12:48Time: 6:12:50Time: 6:12:53Time: 6:12:55Time: 6:12:57

Any thoughts?

P.S.: I'm using the following Adafruit libraries:
Adafruit_GFX.h
Adafruit_HX8340B.h

I don't really use screens, but maybe a display.println()?

Thank you for the answer, but display.println() makes the cursor go to a new line:

Time: 6:12:24
Time: 6:12:27
Time: 6:12:29
Time: 6:12:31

and I don't want that...

usgine2003:
I am playing with a LCD TFT module and I want to show some variables on the display ( like: "Time: 10:30:24") and have the data update.

Which TFT? Which library?

It doesn't surprise me that \r isn't supported. Use the cursor function (or whatever it is called in this undisclosed library) to move the cursor back.

I use the 2.2" 18-bit color TFT LCD display with microSD card breakout - HX8340BN (2.2 18-bit color TFT LCD display with microSD card breakout [HX8340BN] : ID 797 : $29.95 : Adafruit Industries, Unique & fun DIY electronics and kits)

and the Adafruit libs: Adafruit_GFX.h and Adafruit_HX8340B.h

Thanks for the tip: I will check what cursor functions are supported.

I used the display.setCursor(0,0) to make the cursor come back, and it works, but the numbers are overwritten, and it shows a mess where the numbers change, because it draws new pixels without clearing the previous ones... :0

I can clear the whole screen and refresh it, but the only function I found is * display.fillScreen(BLACK);* and it takes too long...

but the numbers are overwritten

That's exactly what \r would do.

Try adding some spaces after the data to overwrite what was there before.

Done that:

display.setCursor(0,0);
display.print("Time: ");
display.print(GPS.hour, DEC); display.print(':');
display.print(GPS.minute, DEC); display.print(':');
display.print(GPS.seconds, DEC); display.print('.');
display.println(GPS.milliseconds);
display.setCursor(0,0);
display.print("Time:                  ");  // bunch of spc to clear the line

still the numbers are not cleared!

display.setCursor(0,0);
display.print("Time: ");
display.print(GPS.hour, DEC); display.print(':');
display.print(GPS.minute, DEC); display.print(':');
display.print(GPS.seconds, DEC); display.print('.');
display.println(GPS.milliseconds);
display.setCursor(0,0);
display.print("Time:                  ");  // bunch of spc to clear the line

Just as a sanity check, change the last line to:

display.print("Time:xxxxxxxxxxxxxxxxxx");  // bunch of spc to clear the line

What happens?

What do you expect println() to do? I would NOT be using println() to put data on an LCD of any sort.

PaulS:
Just as a sanity check, change the last line to:

display.print("Time:xxxxxxxxxxxxxxxxxx");  // bunch of spc to clear the line

What happens?

What do you expect println() to do? I would NOT be using println() to put data on an LCD of any sort.

Does not work, it writes "xxxxxxxxxxxxxx" on top of the other characters.
println() appends a NEWLINE at the end, and this won't work, since I want the same line to be updated with the new time:
Time: 12:34:25 --> and the numbers change on the same line.

Does not work, it writes "xxxxxxxxxxxxxx" on top of the other characters.

As opposed to? Erasing the existing characters?

println() appends a NEWLINE at the end, and this won't work

So, why are you using it?

PaulS:

Does not work, it writes "xxxxxxxxxxxxxx" on top of the other characters.

As opposed to? Erasing the existing characters?

YES

println() appends a NEWLINE at the end, and this won't work

So, why are you using it?
[/quote]

It does not matter on the last line, before printing the blanks, i have a setCursor(0,0) that brings the cursor back to the beginning of the SAME line.

display.println(GPS.milliseconds);
[b]display.setCursor(0,0);[/b]
display.print("Time:                  ");  // bunch of spc to clear the line

It does not matter on the last line, before printing the blanks

Can you humor me, and change it to print(), instead? Just to see if it has any impact.

So you are saying that drawing just ORs the new pixels over the existing ones? Strange. Well you will have to find a "clear rectangle" function then.

Can you post all your code please? Not just the bits you think are relevant.

I note in their library this bit of code:

void Adafruit_GFX::setTextColor(uint16_t c) {
  textcolor = c;
  textbgcolor = c; 
  // for 'transparent' background, we'll set the bg 
  // to the same as fg instead of using a flag
}

Sounds like you are in transparent mode.

I've looked into both libraries Adafruit_GFX and Adafruit_HX8340B and I can't see anything related to a function named "print", how is it possible that display.print or println can be used? Is there a magic trick? I would like to understand.

Yepp...That's exactly what it does...
I will take a picture this evening.

I will try to set the text color BLACK (or whatever the background is) and write the spaces...

guix:
I've looked into both libraries Adafruit_GFX and Adafruit_HX8340B and I can't see anything related to a function named "print", how is it possible that display.print or println can be used? Is there a magic trick? I would like to understand.

It is derived from Print:

class Adafruit_GFX : public Print {
 public: