LCD behaves odd

I have an 128x64 LCD connected to an arduino uno, reading from 18B20 sensors.

Generally it works fine, but from time to time, the LCD screws up and print garbage on the screen.
What annoys me, is that I can't seem to find the right way to reset it any way fast.
I always have to power the LCD on/off a few times, then the same with the uno board, before it starts to work again.

So is there any basic weay to reset an LCD?

It's a cheap dx LCD, it that should make any difference.

Reseting everything will be just be masking the problem.
It is best to work out what the real problem is.
Often it comes down to a few common things.
Some of those tend to be:

  • bad power or electrical noise
  • incorrect s/w which could be the library or the sketch
  • incorrect pin configuration
  • bad wiring/poor connections

In order for us to help we will need to know which libraries and which specific GLCD
you are using and more about the actual issue.

--- bill

This is the LCD:

Libraries I use:
U8glib.h
LCD.h
FastIO.h
Constructor: U8GLIB_ST7920_128X64_1X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
The program is one I found online and modified, which basicly means I just made it read 4 18B20's instead of just 1.
When it works I get this:

When it doesn't work:

The problem seems random, but is very likely to occur when powering up?!

#include "U8glib.h"
#define TEMP_PIN  2 // Sensor 1
#define TEMP_PIN1 11 // Sensor 2
#define TEMP_PIN2 4 // Sensor 3
#define TEMP_PIN3 7 // Sensor 4

U8GLIB_ST7920_128X64_1X u8g(18, 16, 17);	// SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17

void OneWireReset(int Pin);            // Sensor 1
void OneWireOutByte(int Pin, byte d);  // Sensor 1
byte OneWireInByte(int Pin);           // Sensor 1

void OneWireReset1(int Pin1);            // Sensor 2
void OneWireOutByte1(int Pin1, byte d1); // Sensor 2
byte OneWireInByte1(int Pin1);           // Sensor 2

void OneWireReset2(int Pin2);            // Sensor 3
void OneWireOutByte2(int Pin2, byte d2); // Sensor 3
byte OneWireInByte2(int Pin2);           // Sensor 3

void OneWireReset3(int Pin3);            // Sensor 4
void OneWireOutByte3(int Pin3, byte d3); // Sensor 4
byte OneWireInByte3(int Pin3);           // Sensor 4

int HighByte, LowByte, TReading, SignBit, Tc_100, Whole, Fract;           // Sensor 1
int HighByte1, LowByte1, TReading1, SignBit1, Tc_1001, Whole1, Fract1;    // Sensor 2
int HighByte2, LowByte2, TReading2, SignBit2, Tc_1002, Whole2, Fract2;    // Sensor 3
int HighByte3, LowByte3, TReading3, SignBit3, Tc_1003, Whole3, Fract3;    // Sensor 4


void draw(void) {
  // graphic commands to redraw the complete screen should be placed here  
  u8g.setFont(u8g_font_gdr10);
  //u8g.setFont(u8g_font_osb21);
  u8g.drawStr( 0, 12, "Tp: ");
  u8g.drawStr( 40, 12, ",");
    
  u8g.drawStr( 65, 12, "Tw: ");
  u8g.drawStr( 105, 12, ",");
  
  u8g.drawStr( 0, 42, "Tb: ");
  u8g.drawStr( 40, 42, ",");
  
  u8g.drawStr( 65, 42, "Ty: ");
  u8g.drawStr( 105, 42, ",");
    
  
    u8g.setPrintPos(25, 12);     // Sensor 1
    u8g.print(Whole);
    u8g.setPrintPos(44, 12);     // Sensor 1
    u8g.print(Fract);
  
    u8g.setPrintPos(90, 12);   // Sensor 2
    u8g.print(Whole1);
    u8g.setPrintPos(109, 12);   // Sensor 2
    u8g.print(Fract1);
   
    u8g.setPrintPos(25, 42);   // Sensor 3
    u8g.print(Whole2);
    u8g.setPrintPos(44, 42);   // Sensor 3
    u8g.print(Fract2);
    
    u8g.setPrintPos(90, 42);  // Sensor 4
    u8g.print(Whole3);
    u8g.setPrintPos(109, 42);  // Sensor 4
    u8g.print(Fract3);
        
}

void setup(void) {
  digitalWrite(TEMP_PIN, LOW);      // Sensor 1
    pinMode(TEMP_PIN, INPUT);      // sets the digital pin as input (logic 1)

 digitalWrite(TEMP_PIN1, LOW);      // Sensor 2
    pinMode(TEMP_PIN1, INPUT);      // sets the digital pin as input (logic 1)
    

 digitalWrite(TEMP_PIN2, LOW);      // Sensor 3
    pinMode(TEMP_PIN2, INPUT);      // sets the digital pin as input (logic 1)
    
 digitalWrite(TEMP_PIN3, LOW);      // Sensor 4
    pinMode(TEMP_PIN3, INPUT);      // sets the digital pin as input (logic 1) 
    

  // assign default color value
  if ( u8g.getMode() == U8G_MODE_R3G3B2 ) { //                   <---------
    u8g.setColorIndex(255);     // white
  }
  else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
    u8g.setColorIndex(3);         // max intensity
  }
  else if ( u8g.getMode() == U8G_MODE_BW ) {
    u8g.setColorIndex(1);         // pixel on
  }
  else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
    u8g.setHiColorByRGB(255,255,255);
  }
}

void loop(void) {
  // picture loop
 
//______________________________________________________________ Sensor 1

  OneWireReset(TEMP_PIN);          
  OneWireOutByte(TEMP_PIN, 0xcc);
  OneWireOutByte(TEMP_PIN, 0x44); // perform temperature conversion, strong pullup for one sec

  OneWireReset(TEMP_PIN);            
  OneWireOutByte(TEMP_PIN, 0xcc);
  OneWireOutByte(TEMP_PIN, 0xbe);

  LowByte = OneWireInByte(TEMP_PIN);
  HighByte = OneWireInByte(TEMP_PIN);
  TReading = (HighByte << 8) + LowByte;
  SignBit = TReading & 0x8000;  // test most sig bit
  if (SignBit) // negative
  {
    TReading = (TReading ^ 0xffff) + 1; // 2's comp
  }
  Tc_100 = (6 * TReading) + TReading / 4;    // multiply by (100 * 0.0625) or 6.25

  Whole = Tc_100 / 100;  // separate off the whole and fractional portions
  Fract = Tc_100 % 100;

//______________________________________________________________ Sensor 2

  repeats...  

  //______________________________________________________________ Sensor 3
  
  repeats
  //______________________________________________________________ Sensor 4
   
   repeats
   //______________________________________________________________ Sensor 1
    
  void OneWireReset(int Pin) // reset.  Should improve to act as a presence pulse
{
     digitalWrite(Pin, LOW);
     pinMode(Pin, OUTPUT); // bring low for 500 us
     delayMicroseconds(500);
     pinMode(Pin, INPUT);
     delayMicroseconds(500);
}

void OneWireOutByte(int Pin, byte d) // output byte d (least sig bit first).
{
   byte n;

   for(n=8; n!=0; n--)
   {
      if ((d & 0x01) == 1)  // test least sig bit
      {
         digitalWrite(Pin, LOW);
         pinMode(Pin, OUTPUT);
         delayMicroseconds(5);
         pinMode(Pin, INPUT);
         delayMicroseconds(60);
      }
      else
      {
         digitalWrite(Pin, LOW);
         pinMode(Pin, OUTPUT);
         delayMicroseconds(60);
         pinMode(Pin, INPUT);
      }

      d=d>>1; // now the next bit is in the least sig bit position.
   }

}

byte OneWireInByte(int Pin) // read byte, least sig byte first
{
    byte d, n, b;

    for (n=0; n<8; n++)
    {
        digitalWrite(Pin, LOW);
        pinMode(Pin, OUTPUT);
        delayMicroseconds(5);
        pinMode(Pin, INPUT);
        delayMicroseconds(5);
        b = digitalRead(Pin);
        delayMicroseconds(100);
        d = (d >> 1) | (b<<7); // shift d to right and insert b in most sig bit position
    }
    return(d);
}  

//______________________________________________________________ Sensor 2

repeats

//______________________________________________________________ Sensor 3

repeats

//______________________________________________________________ Sensor 4

repeats
}

The program is one I found online and modified, which basicly means I just made it read 4 18B20's instead of just 1.

Just out of interest, does the original unmodified program suffer the same issues?

I don't see anything obvious from looking over the sketch code
other than it isn't the full sketch code, so we can't tell what is really
running.
Also, I don't see any other libraries besides u8glib being used.

You never said which Arduino board/variant you are using.

Are you using some kind of FastIO library?
If so, Where did you get it?
It could be that there is a mapping issue in FastIO
that is clobbering the u8glib pins.

Post your full sketch so we can see what you are really running.

--- bill

I have seen similar problems with my own ST7920 setup. The display seems to be very sensitive to the lenth of the wires.
Here are some ideas:

  • Use shorter wires
  • Switch to SW SPI (if HW SPI had been in use)
  • Apply chip select and proper reset signals (if those signals are not yet there)

Oliver

Hi, how are you powering the LCD?
If from the adruino 5V then you may be causing the regulator on the arduino to go into thermal shutdown due to too much load, that would also explain why you have to reset the arduino as well.

Tom..... :slight_smile: