LCD display gets mixed up

Hello, with my Mega project, I am using a direct wired LCD that is 16x2.

I noticed that after a while, the display gets confused and displays some bad chars on the edges. I didn't think the program is corrupt as my Serial display looks good.

What I am doing is that when the program outputs to the screen periodically, I rapidly scroll right to reorient the display. Then after each 700 ms, I scroll to the left a char. This way, it acts as a banner. To clear a row, I LCD.print(' ') to overwrite. I wonder if I'm blasting it too quickly. Is there a more featured library?

Eventually I plan to switch to I2C two wire 40x2 column display. I don't want to overwhelm it.

Show the code you are using.

1 Like
#define SCROLLDELAY 700
#include <LiquidCrystal.h>
LiquidCrystal realLcd(7, 8, 9, 10, 11, 12);
class MyLCD {
  private:
  void clearLine(){
    for(int i=0;i<40;i++) realLcd.print(" ");
  }
  
  public:
  
  
  int lefts;
  unsigned long scrolled;

  MyLCD():lefts(0),scrolled(millis()){}

  void begin(int a,int b){
    realLcd.begin(a,b);
  }

  void scrollLeft(){
    if( scrolled+SCROLLDELAY <millis()){
        realLcd.scrollDisplayLeft();
        scrolled=millis();
        lefts++;
    }  
  }
  void recenter(){
    while(lefts>0){
      realLcd.scrollDisplayRight();
      lefts--;
    } 
  }
  

  void setCursor(int col,int row){
    realLcd.setCursor(col,row);
    recenter();
    clearLine();
    realLcd.setCursor(col,row);
  }
    
  // Templated member function
  template <typename T>
  void print(const T& value) {
     realLcd.print(value);
     scrolled=millis()+2000;
  }

  void print(char* label,unsigned long lt){
    realLcd.print(label);
    if(lt<10000) {
      realLcd.print(lt);
      realLcd.print("ms");
    }else if(lt>60000){
      lt/=100;
      realLcd.print(lt/10.0);
      realLcd.print("s");
    }else{
      realLcd.print(lt/1000.0);
      realLcd.print("s");
    }
  }
  
  

};

@bperrybap knows the LCD and libraries.

I see a function that appears to write 40 blanks to a 16 char wide display. How does that work?
You have an awful lot of extra code plus a class. I use that display and don't need any of that. Mine is the I2C, maybe that makes a difference?

What exactly do you mean by this?

I noticed that after a while, the display gets confused and displays some bad chars on the edges.

Can you clarify what this means.
i.e. it could mean that things are still functioning properly but you see some unexpected characters on the left or right side of the display, or maybe you mean that things are worse than that.

But more importantly we can't really offer suggestions since we can't see the code you are running that you are having issues with since you only provided a limited portion of your code.
i.e. We should be able to see all the code to fully understand what is being done and if desired, use the code to replicate the problem.

I can think of a several things that can cause issues but without knowing more about your code I can't narrow down to specifics.

--- bill

@c-compute
Have you got any power supply decoupling capacitors in your circuit?

If you do not know what this means then read this:-

Not solving the problem

will cause problems when millis() overflows; you should never use addition when working with millis().

if( millis() - scrolled >= SCROLLDELAY){
1 Like

There are 40 characters in the first row and 40 in the second row. If you were to write a 41st character in either row, the next character would appear as the first character in the other row.

i doubt that. Your for loop to print blanks will not put out the data faster than a single line
LCD.print(F(" "));

in the end there are 40 single lcd.writes() to print a blank.

Please post a schematic and
good pictures of your installation to see each wire connection including the soldering on your LCD.
Please post a FULL CODE to enable helpers to reproduce the problem.

There are a series of myLcd.print(...) calls.
I noticed the chars get funky at the beginning or the end of the strings. Only the LCD shows such mess. I noticed this with unshielded slot cars driving by. They are known to kick out RF.

Reading the older forum articles, appears another person had a similar issue 10 years ago. His solution was to use "10ms in front of lcd.print". His last post he was going to try 1ms. So I will do the same.

I now remember, I refactored my code. I used to have big clumsy sprintf(buf,"format",...) so instead I changed it to a series of print().

Reading the LCD source code, it is littered with a lot of guessed wait states. Clearly there is room for improvement there.

Hi, @c-compute

Good idea to start with.
What are you using as a power supply?

Tom.. :smiley: :+1: :coffee: :australia:

Have you looked at the hd44780 library? It is a considerable improvement over the numerous LiquidCrystal libraries.

2 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.