RGB 16x2 LCD+ Serial Coding

So I'm using an LCD + Serial display but am having trouble coding it. I'm making a controlled water bath and on the screen I want to display:

SV: 100F PV: 098F

so some basic texts and then variable inputs. One variable will be defined in the program and not changed (SV=Set Value) and the other variable is an input of the current temperature (PV=Present Value).

The problems I'm having with the coding are: -Not having the display loop, so SV and PV are always in the same spots. Currently when I'm coding I'm putting the lcd.print("PV: ") in the while loop which I assume this is why it is happening. To solve this I have been putting it in the void setup() -Another problem I am having is displaying the variable. When I use lcd.write(variable) it doesn't give the correct output because lcd.write function only takes in ascii values so do I need to convert the variable into three ascii values for the ones, tens, and hundreds place.

I'm having trouble finding any sort of support for coding using the Serial + LCD RGB 16x2 other than the tutorial but even that hasn't been helpful in the problems I'm having. I can upload the code and pictures if need be.

Thanks in advance.

write doesn't take ascii values. write sends out raw bytes. print sends out ascii values and that's what you want to use.

To keep the LCD displaying in the same spots, clear the screen between prints or set the cursor back to the beginning of the line. Read the documentation for the LCD you have or the library you are using for how to do that.

OR do the obvious thing and post your code so we can help you with it.

#include <SoftwareSerial.h>

// Create a software lcd port!
SoftwareSerial lcd = SoftwareSerial(0,4);

void setup() {
lcd.begin(9600);

// set the size of the display if it isn’t 16x2 (you only have to do this once)
lcd.write(0xFE);
lcd.write(0xD1);
lcd.write(16); // 16 columns
lcd.write(2); // 2 rows
delay(10);
// we suggest putting delays after each command to make sure the data
// is sent and the lcd is updated.

// set the contrast, 200 is a good place to start, adjust as desired
lcd.write(0xFE);
lcd.write(0x50);
lcd.write(200);
delay(10);

// set the brightness - we’ll max it (255 is max brightness)
lcd.write(0xFE);
lcd.write(0x99);
lcd.write(255);
delay(10);

// turn off cursors
lcd.write(0xFE);
lcd.write(0x4B);
lcd.write(0xFE);
lcd.write(0x54);

// create a custom character
// clear screen
lcd.write(0xFE);
lcd.write(0x58);
delay(10); // we suggest putting delays after each command

// go ‘home’
lcd.write(0xFE);
lcd.write(0x48);
delay(10); // we suggest putting delays after each command

delay(1000);
}

void loop() {
int PV11;
int PV1;
int PV21;
int PV2;
int PV31;
int PV3;
int SV11;
int SV1;
int SV21;
int SV2;
int SV31;
int SV3;

int PV=163;
int SV=89;

lcd.write(0xFE);
lcd.write(0x58);

PV11=one(PV);
PV21=ten(PV);
PV31=hund(PV);
SV11=one(SV);
SV21=ten(SV);
SV31=hund(SV);

SV1=decToASCII(SV11);
SV2=decToASCII(SV21);
SV3=decToASCII(SV31);
PV1=decToASCII(PV11);
PV2=decToASCII(PV21);
PV3=decToASCII(PV31);

lcd.write(0xFE);
lcd.write(0x48);
lcd.print(“SV:”);
lcd.write(0xFE);
lcd.write(0x4D);
lcd.write(SV3);
lcd.write(SV2);
lcd.write(SV1);
lcd.println(" ");

lcd.print("PV: ");
lcd.write(0xFE);
lcd.write(0x4D);
lcd.write(PV3);
lcd.write(PV2);
lcd.write(PV1);

delay(10);

}

int hund(int value){
int i=0;
while((value%10)!=0){
value=value-1;
}
while((value%100)!=0){
value=value-10;
}
while((value%1000)!=0){
value=value-100;
i=i+1;
}

return i;
}

int ten(int value){
int i=0;
while((value%10)!=0){
value=value-1;
}
while((value%100)!=0){
value=value-10;
i=i+1;
}
return i;
}

int one(int value){
int i=0;
while((value%10)!=0){
value=value-1;
i=i+1;}
return i;
}

int decToASCII(int value){
int a=0;
while(a!=value){
a=a+1;
}
a=a+48;
return a;
}

The Arduino provides you with methods to do most things. The really annoying “missing” part is leading zeros or spaces. But this trick will do what you want.

void loop(void)
{
    int PV = 58;
    int SV = 103;
    lcd.write(0xFE); lcd.write(0x48);  //special escape sequence for HOME
// another way of doing the escape.   Safer to use the write() method.
//    lcd.print("\xFE\x48");
    lcd.print("PV: ");
    lcd.write(0xFE); lcd.write(0x4D);  //special escape sequence
    if (PV < 100) lcd.print("0");  //leading zero
    if (PV < 10) lcd.print("0");   //leading zero
    lcd.print(PV);
    ...
}

I suspect that your LCD supplier has already written a library for your display. So there are probably specific method()s for doing your escape sequences. i.e. if makes it easier to understand.

David.