LCD 2x16 and PCF8574AP works well for limited time

Hi

I have got a problem with operating my typical 2x16 LCD with PCF8574AP. I have read the eniter internet about that, other topics etc but none of them can relate to my problem. The thing is that my circuit works for a limited time only. It varies, it may be 15 mintues, sometimes 5 minutes. Here are the pictures how it looks like:

  1. perfectly working
  2. still good enough
  3. well at least humidity, almost...
  4. are you kidding me?

I belive the connections are right as I get what I want at the beggining. I used pull up resistors between SDA/+5V and SCL/+5V. Here is the used code:

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include "DHT.h"

#define DHTPIN 8
#define DHTTYPE DHT22

LiquidCrystal_I2C lcd(0x38, 6, 5, 4, 0, 1, 2, 3, 7, POSITIVE);

DHT dht(DHTPIN,DHTTYPE);

// Creat a set of new characters
const uint8_t charBitmap[][8] = {
  { 0xc, 0x12, 0x12, 0xc, 0, 0, 0, 0 },
  { 0x6, 0x9, 0x9, 0x6, 0, 0, 0, 0 },
  { 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0, 0x0 },
  { 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0, 0x0 },
  { 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0x0 },
  { 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0x0 },
  { 0x0, 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0x0 },
  { 0x0, 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0x0 }
  
};

void setup()
{
  int charBitmapSize = (sizeof(charBitmap ) / sizeof (charBitmap[0]));

 
 lcd.begin(16,2);               // initialize the lcd 
 dht.begin();
  for ( int i = 0; i < charBitmapSize; i++ )
  {
     lcd.createChar ( i, (uint8_t *)charBitmap[i] );
  }

 lcd.home ();                   // go home
 lcd.print("Hello, ARDUINO! ");  
 lcd.setCursor ( 0, 1 );        // go to the next line
 lcd.print ("   YO   ");
 delay ( 1000 );
}

void loop()
{
  delay(1000);
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  
  lcd.home();
  lcd.print("Humidity: ");
  lcd.print(h);
  lcd.setCursor(0,1);
  lcd.print("Temp: ");
  lcd.print(t);
  lcd.home();
  
}

What is going on in here? Is this arduino's fault or pcf's? I used this library for LCD: https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home

EDIT: interesting thing is that when I put LCD out of breadboard and insert it again it starts to work again.

This looks a lot like the DHTtester example from Adafruit. I see that you have reduced the delay time in the loop. What happens when you change that back to 2 seconds?

You haven't mentioned which Arduino you are using and I see that that example has a 'NOTE:' dealing with modifications that can be tried with other than a 16MHz device.

I would test the unaltered version of that example. In other words get rid of the code relating to creating custom characters and send the output to the serial monitor.

If that works then add in the LCD code without removing the serial monitor code and see where the problems start showing up.

Don

floresta:
This looks a lot like the DHTtester example from Adafruit. I see that you have reduced the delay time in the loop. What happens when you change that back to 2 seconds?

You haven't mentioned which Arduino you are using and I see that that example has a 'NOTE:' dealing with modifications that can be tried with other than a 16MHz device.

I would test the unaltered version of that example. In other words get rid of the code relating to creating custom characters and send the output to the serial monitor.

EDIT: now LCD has been running well for 30 minutes

If that works then add in the LCD code without removing the serial monitor code and see where the problems start showing up.

Don

DHT has nothing to do with that. I was printing random things in loops and had the same result. Delay with 2s, 5s, 10s gives the same result.

Arduino Uno R3.

Serial monitor gives perfect result. The only problem is in LCD which does not always work as it is supposed to.

EDIT: Now LCD has been running well for the past 30 minutes.

DHT has nothing to do with that. I was printing random things in loops and had the same result.

My crystal ball did not inform me about the other things that you tried.

Try getting rid of one of the redundant lcd.home statements in loop() and replacing the remaining one with an lcd.setCursor(0,0).

Also, you don't need the lcd.home() in setup since that is taken care of in the initialization.

Don

I had the EXACT same problem.

Someone kindly informed that I should read up on the (F) macro.

I suggest you do the same, I'd be willing to put money that all of your problems go away. What is happening is that you are calling a print function in the loop that is printing static information, which means you are using up dynamic memory, this continues the longer the sketch runs, eventually you run out and get the results you are seeing there.

Try changing all of your:

lcd.print("Hello, ARDUINO! ");

To something like this:

lcd.print(F("Hello, ARDUINO! "));

Here is a link to my thread where I asked the same question :wink:
http://forum.arduino.cc/index.php?topic=313827