LCD 2 Line messages + extra data

Hi looks so simple but.

I like to have more then a hello world text in the display.
What I need is 3 characters with behind it a space and the data comming from a strinf which are max 3 digits.
I tried several things to add behind this standard code.

  lcd.clear(); 
  lcd.begin(16, 2);
  lcd.setCursor(0,0); 
  lcd.print("LINE 1 + ");
  lcd.setCursor(0,1); 
  lcd.print("LINE 2 + ");
  lcd.clear(); 
  lcd.begin(16, 2);
  lcd.setCursor(0,0); 
  lcd.print("LINE 1 + ", (stringdata));
  lcd.setCursor(0,1); 
  lcd.print("LINE 2 + ", (stringdata));

I am missing the correct context for adding the stringdata to the same line.

Thanks, Paco

You need some simple math

  lcd.clear(); 
  lcd.begin(16, 2);
  lcd.setCursor(0,0); 
  lcd.print("LINE 1 + ");

  lcd.setCursor(9,0); 
  lcd.print(x);  // your var
  lcd.print("  ");

Homework: do the 2nd line :slight_smile:

Rob,

Did my homework.

  lcd.clear(); 
  lcd.begin(16, 2);
//1st line
  lcd.setCursor(0,0); 
  lcd.print("SSP ");
  lcd.setCursor(4,0); 
  lcd.print(speedstartValue);
  lcd.setCursor(9,0); 
  lcd.print("SPC");
  lcd.setCursor(13,0); 
  lcd.print(speedcurveValue);
//2nd line
  lcd.setCursor(0,1); 
  lcd.print("BK");
  lcd.setCursor(4,1); 
  lcd.print(brakeValue);
  lcd.setCursor(9,1); 
  lcd.print("BKC");
  lcd.setCursor(13,1); 
  lcd.print(brakecurveValue);

Problem solved.
What I did not understand and could filter from other samples on the web is that you use lcd.setCursor to specify the new data on the same line.

Up to the next hurdle.

Thanks,

Paco

Well done, you got an A :wink:

The next homework will be to only write the changing fields to the screen.
The static text does not need to be send over and over again.
The Arduino will win a lot of time that can be used for other processing.

Succes !

Did not tought of the speed of the program would suffer with that.
If you remove lcd.clear from the void loop and check if data<>olddata and take action to update the display would that be suffcient to speed up?
Or do we have to go deeper?

Bleh I hate homework.
:stuck_out_tongue:

If you remove lcd.clear from the void loop and check if data<>olddata and take action to update the display would that be suffcient to speed up?

not only remove lcd.clear but all the static strings from loop. and put these in a function for reuse…

something like this

void setup()
{
  ...
  printFixed()
}

void loop()
{
  ....
  if (digitalRead(ScreenPIN) == HIGH) printFixed();  
  printVars();
  ...
}

void printFixed()
{
  lcd.clear(); 
  lcd.begin(16, 2);
  // variation
  lcd.setCursor(0,0); 
  lcd.print("SSP       SPC ");
  lcd.setCursor(0,1); 
  lcd.print("BK        BKC");
}


void printVars()
{
  // 1st line
  if (speedstartValue != prevSpeedstartValue)
  {
    lcd.setCursor(4,0); 
    lcd.print(speedstartValue);
  }
  if (speedcurveValue != prevSpeedcurveValue)
  {
    lcd.setCursor(13,0); 
    lcd.print(speedcurveValue);
  }
  etc
}

If you want to completely format your output, try sprintf. Lots of times your current code will be broken. Just try to print hour:minute you will see any minute below 10 is just printed as 0-9 so 10:05 is printed as 10:5, very ugly.

Here's how to get started with sprintf to solve that type of problems and put output entirely under control:

Also, if your LCD shared data pins with another device, for example a keypad, it will be necessary to add a small delay before printing to the LCD... correction... the delay is not necessary :blush:

void lcdGetPassword()
{
  delay(200);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("   Enter Password   ");
  lcd.setCursor(0, 1);
  lcd.print("    [          ]    ");
  lcd.setCursor (5, 1);
 }

I wanted to understand how to the initialization process.

You can find a complete explanation of the process by following the LCD Initialization link at http://web.alfredstate.edu/weimandn.

Note: You really should have started a new thread for this question.

Don