Serial.print help please

Hello Forum. Having a bit of an issue trying to get text written on rows of my LCD, the “\e[i,0H” doesnt locate print as expected, it simply starts a new line of text after the contents of DATA with ;0H cant seem to stop that and get printing at the right location, i.e. each new row defined by the value of i. Any help appreciated please.

void loop() 

{  

  if (radio.receiveDone())  //check if something was received (could be an interrupt from the radio)   

  {

       for(int i=1; i <= 6; i++)

     {  

       Serial.print("\e[i;0H");

       delay(50);

       Serial.print(i);

       Serial.print((char*)radio.DATA);

       
       delay(1000);

     }      

  } 

  radio.receiveDone(); //put radio in RX mode

  Serial.flush(); //make sure all serial data is clocked out before sleeping the MCU

}

The problem is because you don’t

(This is just a snippet of the full answer. Hint)

What makes you think your LCD understands ANSI Escape codes for cursor positioning??

Regards,
Ray L.

Hello Ray. If I use Serial.print("\e[i;0H"); where the is an integer it works fine all the time.
Thanks. Pete

If I use Serial.print("\e[i;0H"); where the is an integer it works fine all the time.

What does? What, EXACTLY, do you see printed in the Serial Monitor application?

Serial.Print has no concept that the "i" in your passed parameter is anything but the letter "i". It has no way of knowing you wanted variable substitution there.

Consider using sprintf()

UKPete:
Hello Ray. If I use Serial.print("\e[i;0H"); where the is an integer it works fine all the time.
Thanks. Pete

Serial.print has absolutely nothing to do with any LCD. What LCD are you using? What driver are you using for that LCD? ESC codes have to be parse, and executed by the LCD driver, and I have a hard time believing ANY LCD for an Arduino would implement such an antiquated interface.

Regards,
Ray L.

Hello Ray.

Serial.print works fine when I use 0,1, etc in place of the letter . I am using…
#include <Wire.h>
#include <RFM69.h>
#include <SPI.h>
an adaptor on the back of my 128 x 64 LCD from ByVac
http://www.byvac.com/index.php/BV4611

I hope that clears up any confusion I have given.

Regards. Pete

Serial.print works fine when I use 0,1, etc in place of the letter . I am using…

So, either use sprintf, as suggested, or just break the ANSI code over three "Serial.print"s.

Thanks AWOL. As I am a complete novice (can you tell !) could you put the sprintf suggestion into actual code please? Thanks. Pete

To be honest, the three "Serial.print"s are a lot more intuitive, about the same amount of typing, and won't bloat your code, but there's plenty on sprintf online, if you decide to do it that way.