LCD 20*4 I2C problem

Hi everyone,

I've bought some lcd at banggood store : link

I've run a I2C scan to know the I2C adress, it's : 0x3F

Every exemple I've found on the net doens't work. The screen light on but no display. I've allready worked succesfully with a 16*2 LCD, but I don't understand what I do wrong.

Here is one of the sketchs I've test. The screen blink every 8 seconds :

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>  // F Malpartida's NewLiquidCrystal library


#define I2C_ADDR    0x3F  // Define I2C Address for controller
#define BACKLIGHT_PIN  7
#define En_pin  4
#define Rw_pin  5
#define Rs_pin  6
#define D4_pin  0
#define D5_pin  1
#define D6_pin  2
#define D7_pin  3

#define  LED_OFF  0
#define  LED_ON  1
LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

void setup() 
{
  lcd.begin (20,4);  // initialize the lcd
// Switch on the backlight
  lcd.setBacklightPin(BACKLIGHT_PIN,NEGATIVE);
  lcd.setBacklight(LED_ON);
}

void loop()  
{

// Reset the display 
  lcd.clear();
  delay(1000);
  lcd.home();
 
// Print on the LCD
  lcd.backlight();  
  lcd.setCursor(0,0); 
  lcd.print("Hello, world!");
  delay(8000);
}

Thanks for your help !

The issue with PCF8574 based backpacks is that there is no standard way to wire the PCF8574 output port pins to the hd44780 LCD pins. As a result different backpacks use different pin mappings.
Some libraries hard code the pin mappings and other like the one you are using allows configuring the pin mappings.

Given the backlight is blinking but you don't have anything in your loop() code to turn off the backlight, the issue is likely to be that the pin mapping you have provided in the constructor is incorrect.
The lcd will not work correctly until you configure that library with the proper pin mappings for your backpack.

If you want, you can try my hd44780 library.
It is designed to make configuration easier.
It will automatically locate backpack and automatically detect the pin mappings so you don't have to fill in any of that type of information in the constructor (you can if you want, but it isn't necessary).
The library can easily and quickly be installed using the IDE library manager right from the GUI.
You can read more about it here:

The i/o class for i2c lcd backpacks is hd44780_I2Cexp.

The library includes many examples and includes a diagnostic sketch (I2CexpDiag) that will test the i2c connections and the LCD memory inside the LCD module.

It should automatically autodetect your backpack and pin mappings "out of the box" so that the included examples "just work".

If the examples aren't working, then run the diagnostic sketch and it will provide lots of diagnostic information on the serial port.

--- bill

Thanks for your help, your solution works.

I've also found this one :

/*
** Example Arduino sketch for SainSmart I2C LCD2004 adapter for HD44780 LCD screens
** Readily found on eBay or http://www.sainsmart.com/ 
** The LCD2004 module appears to be identical to one marketed by YwRobot
**
** Address pins 0,1 & 2 are all permenantly tied high so the address is fixed at 0x27
**
** Written for and tested with Arduino 1.0
** This example uses F Malpartida's NewLiquidCrystal library. Obtain from:
** https://bitbucket.org/fmalpartida/new-liquidcrystal 
**
** Edward Comer
** LICENSE: GNU General Public License, version 3 (GPL-3.0)
*/
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR    0x3F // Define I2C Address where the PCF8574A is
#define BACKLIGHT_PIN     3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7

int n = 1;

LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

void setup()
{
  lcd.begin (20,4);
  
// Switch on the backlight
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home ();                   // go home

  lcd.print("SainSmart I2C test");  
  lcd.setCursor ( 0, 1 );        // go to the next line
  lcd.print("F Malpartida library");
  lcd.setCursor ( 0, 2 );        // go to the next line
  lcd.print("Test By Edward Comer");
  lcd.setCursor ( 0, 3 );        // go to the next line
  lcd.print("Iteration No: ");
}

void loop()
{
  // Backlight on/off every 3 seconds
  lcd.setCursor (14,3);        // go col 14 of line 3
  lcd.print(n++,DEC);
  lcd.setBacklight(LOW);      // Backlight off
  delay(500);
  lcd.setBacklight(HIGH);     // Backlight on
  delay(3000);
}

There is no magic to the pin mappings.
They correspond to how the PCF8574 output port pins are wired up to the hd44780 pins and backlight circuit.
Guessing or using trial and error is not a good way to get these correct.
You have to look at the PCB and etch traces to see how the pins are wired.
It isn't too difficult and can be done in just a few minutes.

I wrote the auto configuration code in hd44780_I2Cexp because I got tired of doing it and wanted a "plug and play" / "it just works" solution.
With the hd44780 library you can mix and match backpack types and even mix with MCP23008 based backpacks.
With the i2c address auto detection in the hd44780 library you don't have to recompile the sketch if you swap in a backpack with a different address.

--- bill