No text but backlight control works.

Issue #61 resolved
Torsten Curdt
created an issue

I am a little puzzled. I have one of these SainSmart IIC/I2C/TWI Serial 2004 20x4 LCDs. After figuring out the the correct init parameters I can now control the backlight just fine - but I am not seeing any text. I am running out of ideas. Do you think it could be a hardware issue? Or a user error? Or a bug?

Here is my code:

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

void setup()
{
  lcd.begin(20,4);

  for(int i = 0; i< 3; i++) {
    lcd.backlight();
    delay(250);
    lcd.noBacklight();
    delay(250);
  }
  lcd.backlight();

  lcd.home();
  lcd.print("Hello");
  lcd.setCursor(0,1);
  lcd.print("World!");
}

Comments (10)

  1. Torsten Curdt reporter

    This also works fine

    lcd.begin(20,4);
    
    for(int i = 0; i<3; i++) {
      lcd.backlight();
      delay(250);
      lcd.noBacklight();
      delay(250);
    }
    lcd.backlight();
    
    lcd.home();
    lcd.cursor();
    lcd.blink();
    //lcd.print("Hello");
    

    but as soon as I add another lcd.print at the end the blinking cursor disappears and the display is just empty.

  2. Francisco Malpartida repo owner

    The way the library works is by mapping the pins of the LCD to the backpack. You will need to get the right pinout for the LCD in order for it to work correctly. Unless the LCD backpack supports a backlight and it's connected to the I2C extender's pin 3 it will not work. You can look at the html documentation or header files to get it going: /*! @Filip Valenta
    @abstract Class constructor. @Discussion Initializes class variables and defines the I2C address of the LCD. The constructor does not initialize the LCD.

    @param      lcd_Addr[in] I2C address of the IO expansion module. For I2CLCDextraIO,
    the address can be configured using the on board jumpers.
    @param      En[in] LCD En (Enable) pin connected to the IO extender module
    @param      Rw[in] LCD Rw (Read/write) pin connected to the IO extender module
    @param      Rs[in] LCD Rs (Reset) pin connected to the IO extender module
    @param      d4[in] LCD data 0 pin map on IO extender module
    @param      d5[in] LCD data 1 pin map on IO extender module
    @param      d6[in] LCD data 2 pin map on IO extender module
    @param      d7[in] LCD data 3 pin map on IO extender module
    */
    
  3. Torsten Curdt reporter

    Looking at the datasheet for the PCF8574 and the docs for the HD44780 I tested the connections and here is what I got:

    HD44780     PCF8574T
     1
     2
     3
     4 RS ------ 5 P1
     5 RW ------ 4 P0
     6 EN ------ 6 P2
     7 D0
     8 D1
     9 D2
    10 D3
    11 D4 ------  9 P4
    12 D5 ------ 10 P5
    13 D6 ------ 11 P6
    14 D7 ------ 12 P7
    15 BA ------  3 A2 + 2 A1 + 1 A0 (?)
    16 BC
    

    Now when I look at the header and signature I tried to work out the parameters.

    @param      lcd_Addr[in] I2C address of the IO expansion module. For I2CLCDextraIO,
    the address can be configured using the on board jumpers.
    @param      En[in] LCD En (Enable) pin connected to the IO extender module
    @param      Rw[in] LCD Rw (Read/write) pin connected to the IO extender module
    @param      Rs[in] LCD Rs (Reset) pin connected to the IO extender module
    @param      d4[in] LCD data 0 pin map on IO extender module
    @param      d5[in] LCD data 1 pin map on IO extender module
    @param      d6[in] LCD data 2 pin map on IO extender module
    @param      d7[in] LCD data 3 pin map on IO extender module
    
    LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t lcd_Addr, uint8_t En, uint8_t Rw,
                                         uint8_t Rs, uint8_t d4, uint8_t d5,
                                         uint8_t d6, uint8_t d7, uint8_t backlighPin, 
                                         t_backlighPol pol = POSITIVE )
    

    Given how they are connected and name D4-D7 needs to be mapped (the data 0-3 is a big confusing though). Now the question is: Do I need to put in the pin number? Or the P#? I assume P# but then I pretty much the same I had before:

    #define PIN_EN 2
    #define PIN_RS 1
    #define PIN_RW 0
    #define PIN_D4 4
    #define PIN_D5 5
    #define PIN_D6 6
    #define PIN_D7 7
    #define PIN_BA ?
    LiquidCrystal_I2C lcd(0x27, PIN_EN, PIN_RW, PIN_RS, PIN_D4, PIN_D5, PIN_D6, PIN_D7, PIN_BA, POSITIVE);
    

    ...where foremost the backlight is working. Some cursor positioning and screen cleaning works, too.

    Could it be a hardware failure? I am running out of ideas here.

  4. Francisco Malpartida repo owner

    You will need to connect the port number, P#. If the backlight is controlled with an native port in the board (say arduino pin 7) you will have use the library as follows:

    LiquidCrystal_I2C lcd(0x27, PIN_EN, PIN_RW, PIN_RS, PIN_D4, PIN_D5, PIN_D6, PIN_D7);

    You will then have to control the backlight pin through the regular Arduino IDE. Not all LCD backpacks are capable of controlling the backlight through the I2C. Do you have extra pins to control the backlight or are they connected directly through the PCF8574?

    If they are driven through the PCF8574 you will have to find which port controls the backlight.

    This is a fully configurable library to support many configurations. Therefore, each individual manufacturer should configure the initialisation of the library to match their HW.

    It may well be port 3 so PIN_BA 3.

  5. Francisco Malpartida repo owner

    Perhaps you are drawing too much current when you use the LCD's backlight. Have you tried using the entire library without the backlight and seen if it works? Even if you can't see it too well given the lack of backlight?

  6. Torsten Curdt reporter

    Thanks confirming about the P# scheme!

    The backlight is the only thing that actually works controlling via I2C. So the that pin number is for sure OK.

    Drawing too much current - that might be work to check. But I see all kinds of people using the LCD (and backpack) straight via UNO. So it's not very likely.

    I could also try to get a replacement unit - but to me this doesn't sound like a general hardware issue (to me).

  7. Log in to comment