Pages: [1]   Go Down
Author Topic: 20x4 LCD acting odd  (Read 1322 times)
0 Members and 1 Guest are viewing this topic.
St. Peters, MO
Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm having trouble with my program and a serial 20x4 LCD.  (This is the exact one: http://www.nkcelectronics.com/20x4-Serial-LCD-Module-Blue-with-White-backlight_p_346.html)  I'm using their library also.

For some reason it cuts off the first 3 characters on the second line and only in a particular section of my code. No where else in my code does it act like this, so I wouldn't think the LCD is defective in any way.

Code:
void displayRootMenu() {
  //Root Menu
  if (changed(PreviousMenuItem,CurrentMenuItem)){
    selected = PreviousMenuItem;
    lcd.clear();
    lcd.setCursor(1, 1);
    lcd.print(F("---- Root Menu ----"));
    if (PreviousMenuItem == 100){
      //only display if we are displaying for the first time
      lcd.setCursor(2, 1);
      lcd.print(F("Rotate knob to"));
      lcd.setCursor(3, 1);
      lcd.print(F("access menu items"));
      selected = 0;
    }
    lcd.setCursor(4, 1);
    lcd.print(F("--------------------"));
    PreviousMenuItem = CurrentMenuItem;
  }
    selected -= readEncoder();
    if (selected<1) selected=6;
    if (selected>6) selected=1;
    if (moved || subMenuReturn) {
      subMenuReturn = false; //reset
      lcd.setCursor(2,1);
      switch(selected) {
        case 1:
          lcd.print(" 1: Time Format     ");
          lcd.setCursor(3,1);
          lcd.print("    ");
          lcd.write(B00101000);
          lcd.print(timeFormat);
          lcd.print("-hr");
          lcd.write(B00101001);
          lcd.print("            ");
          break;
        case 2:
          lcd.print(" 2: Time Zone Offset");
          lcd.setCursor(3,1);
          lcd.print("    ");
          lcd.write(B00101000);
          lcd.print(timeZone);
          lcd.write(B00101001);
          lcd.print("          ");
          break;
        case 3:
          lcd.print(" 3: LCD Backlight   ");
          lcd.setCursor(3,1);
          lcd.print("    ");
          lcd.write(B00101000);
          lcd.print(lcdBacklightBrightness);
          lcd.write(B00101001);
          lcd.print("            ");
          break;
        case 4:
          lcd.print(" 4: Use GPS Time    ");
          lcd.setCursor(3,1);
          lcd.print("    ");
          lcd.write(B00101000);
          if (useGPSTime){
            lcd.print("On ");
          }else{
            lcd.print("Off");
          }
          lcd.write(B00101001);
          lcd.print("          ");
          break;
        case 5:
          lcd.print(" 5: View GPS Data   ");
          lcd.setCursor(3,1);
          lcd.print("    ");
          lcd.write(B00101000);
          lcd.print("UTC Time,Sat.");
          lcd.write(B00101001);
          break;
        case 6:
          lcd.print(" 6: Exit Settings   ");
          lcd.setCursor(3,1);
          lcd.print("                   ");
          break;
      }
    }
    if (buttonRuniquePress == true){
      CurrentMenuItem = selected;
      buttonRuniquePress = false; //reset
    }
}

The LCD flickers for the first 3 characters or so (really almost too fast to notice). 

Now, here is what is odd. I tested out adding in a delay right after I print the second line.  Like this:

Code:
      switch(selected) {
        case 1:
          lcd.print(" 1: Time Format     ");
          delay(1000);
          lcd.setCursor(3,1);

And the first 3 characters show up on the LCD for 1 second, then disappear.

Also, If I comment out this:
Code:
//lcd.print(timeFormat);
then it displays just fine.  my variable timeFormat is an int.
 smiley-sad

Here is a video showing what it is doing (when I added in the delay(1000)smiley-wink
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 99
Posts: 3626
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why do this, "lcd.print(" 1: Time Format     ");" when you can set the cursor to display it at what ever row or column you want? Why include white space?
Have it as,
Quote
lcd.setCursor(2,3);  //setCursor(row, col)
lcd.print("1: Time Format");"
Result=> |___1:_Time Format____|
            |_______(24-Hrs)_______|

Do you know, if you add too much space, you will overlap the next row.
« Last Edit: May 01, 2013, 02:19:23 pm by HazardsMind » Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 36
Posts: 4325
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Why include white space?
Obviously you haven't tried this with messages of varying length displayed in the same location.

It is done so that when you go from a long message to a short message you don't leave remnants of the old, longer, message on the screen.


Quote
Do you know, if you add too much space, you will overlap the next row.
I guess you haven't tried this either.

It will overlap the row after the next row.


Don
« Last Edit: May 01, 2013, 02:27:01 pm by floresta » Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 99
Posts: 3626
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Why include white space?
Obviously you haven't tried this with messages of varying length displayed in the same location.

It is done so that when you go from a long message to a short message you don't leave remnants of the old, longer, message on the screen.


Quote
Do you know, if you add too much space, you will overlap the next row.
I guess you haven't tried this either.

It will overlap the row after the next row.


Don
No I have tried it, and I understand why white space is needed, but for him, he doesn't really needed it. And yes I do know how the rows work.
11111111111111111111 Row 1
33333333333333333333 Row 2
22222222222222222222 Row 3
44444444444444444444 Row 4

Look at his third row, and look at what he is printing after the closing parentheses, "lcd.print("            ");". That is enough to spill over onto the next row(2), and judging by the amount of spaces, it looks like it is just enough to cover "_1:", which is why it disappears when the (24-Hrs) is displayed.

Which is why I asked, "Why include white space?"

I will test his code when I get home tonight, provided he posts the FULL code.

Edit: Actually I can just test that one part, I know how it needs to look.
« Last Edit: May 01, 2013, 03:10:13 pm by HazardsMind » Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Queens, New York
Offline Offline
Faraday Member
**
Karma: 99
Posts: 3626
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tested it and I was correct.
He needs to take out this line, in bold.
Quote
case 1:
          lcd.print(" 1: Time Format     ");
          lcd.setCursor(3,1);
          lcd.print("    ");
          lcd.write(B00101000);
          lcd.print(timeFormat);
          lcd.print("-hr");
          lcd.write(B00101001);
          lcd.print("            ");
          break;
Once he does that, he will be working fine.

@johnhuebbe,
Might I suggest you clear the lcd when switching between cases. That way you won't need to use white space to clear your rows.
Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

St. Peters, MO
Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'll test the change tonight and get back with you. (at work now). At first glance it looks like it was a simple mistake on my part that I overlooked.

As to why I don't clear the screen, it's a long story.  I have other things going on with my program loop that are time critical and don't want to clear it. I also don't need to clear everything, just what changes (which is why I've included white space).  If I do use lcd.clear();  then it takes too long. I think around 70 or 80ms.

Thanks for all the help.
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 99
Posts: 3626
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'll test the change tonight and get back with you. (at work now). At first glance it looks like it was a simple mistake on my part that I overlooked.

As to why I don't clear the screen, it's a long story.  I have other things going on with my program loop that are time critical and don't want to clear it. I also don't need to clear everything, just what changes (which is why I've included white space).  If I do use lcd.clear();  then it takes too long. I think around 70 or 80ms.

Thanks for all the help.

Ok, white space is fine.
But just remember, the lcd is 20 by 4, so anything longer than 20 spaces, will spill over onto the next line and write over anything that is there.
Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 36
Posts: 4325
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
But just remember, the lcd is 20 by 4, so anything longer than 20 spaces, will spill over onto the next line and write over anything that is there.

Just keep in mind the layout in reply #3.  The 'next line' is not the same as the 'next row'.

Don
Logged

St. Peters, MO
Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yup, it was a simple mistake;  too many spaces.  Got it fixed now. Thanks!
Logged

Pages: [1]   Go Up
Jump to: