1. Francisco Malpartida
  2. New LiquidCrystal
  3. Issues
Issue #42 invalid

LCD2004 and other "software backlight" support

626Pilot
created an issue

The LCD2004 display is a 20x4 line character display commonly sold on Amazon. They are advertised as Arduino-compatible, so when you search for "LCD2004" or "Arduino LCD" they will turn up.

The display uses only four wires: +5V, GND, SCL, and SDA. There is no additional pin for backlight, as this is handled by the I2C shift register onboard the display. (The shift register controls backlight on pin 8, so every time they send a command, they "or" the data with 0x08 to turn it on, or 0x00 to turn it off.) Power is pulled directly from +5V and controlled by an I2C command. However, the backlight control code seems to have a built-in assumption that backlights are only driven by pins on the MCU.

When I run HelloWorld_i2c, I get rapid flashing of the backlight (it stays off most of the time, probably the display reseting itself and defaulting backlight to on) with some unlit characters flashing around in the backbground.

I tried changing your code in I2CIO.cpp, like this: In I2CIO::write, change the sending line to this: Wire.send ( _shadow | 0x08 ); In I2CIO::digitalWrite, the sending line looks like: status = this->write ( _shadow | 0x08 );

This had no effect and I'm not sure what to try next.

Using the "LiquidCrystal_I2C" library (not yours) I am able to turn on the backlight in software and write characters to the display. There is no reseting or flashing. I was hoping to use your library since it's much faster!

Comments (8)

  1. 626Pilot reporter

    Figured out how to turn on the backlight - in I2CIO.cpp, there is an #ifdef block concerning the Arduino version that chooses whether to use Wire.send or Wire.write. I forgot to propagate the edit to both. Now the Wire.write line looks like: Wire.write ( _shadow | 0x08 );

    That does turn on the backlight. However, the display doesn't seem to be initialized properly. When it boots, there is a solid line of boxes on the 1st and 3rd lines, sort of a test pattern. When I run the Hello World or performanceLCD programs, after putting in the right number of rows/cols and the address 0x3F, characters will flash across the 1st and 3rd rows as a change in brightness of the white boxes. (As though the characters were being overlaid on top of them, making some pixels brighter.) Nothing appears on rows 2 or 4.

  2. Francisco Malpartida repo owner

    You should use the following constructor instead: LiquidCrystal_I2C(uint8_t lcd_Addr, uint8_t En, uint8_t Rw, uint8_t Rs, uint8_t backlighPin, t_backlighPol pol);

    Where backlightPin is the i2c extender module pin where your backlight is connected to. It works out of the box.

  3. Francisco Malpartida repo owner

    To get a 20x4 lcd going you should invoke the lcd.begin method with the geometry of your lcd, i.e. lcd.begin(20,4)

    You can browse through the html interface description tha go with the library.

  4. 626Pilot reporter

    Oh. I was using the I2C example sketch, which doesn't specify pins, so maybe that's why it didn't work. The I2C example has the Arduino turning on the backlight pin directly, which is why I assumed it didn't know how to do that over I2C.

    According to the http://www.sainsmart.com/sainsmart-iic-i2c-twi-serial-2004-20x4-lcd-module-shield-for-arduino-uno-mega-r3.html, these are the pin specs: 1 VSS Ground for Logic(0V) 2 VDD Power supply for Logic(+5V) 3 V0 Power supply for LCD Driver 4 RS H: Data;L: Instruction Code 5 R/W H: Read; L: Write 6 E Enable signal 7~14 DB0~DB7 Data Bus Line 15 A Backlight Power(+5V) 16 K Backlight Power(0V)

    I tried this:

    define LCD_ADDR 0x3f

    define EN 6

    define RW 5

    define RS 4

    define D4 7

    define D5 8

    define D6 9

    define D7 10

    define BACKLIGHT_PIN 15

    LiquidCrystal_I2C lcd(LCD_ADDR, EN, RW, RS, D4, D5, D6, D7, BACKLIGHT_PIN, POSITIVE);

    Result: Black screen.

    Then I changed the defines to all be -1 (except for the backlight) in case there might be a fencepost error:

    define LCD_ADDR 0x3f

    define EN 5

    define RW 4

    define RS 3

    define D4 6

    define D5 7

    define D6 8

    define D7 9

    define BACKLIGHT_PIN 15

    Now the backlight comes on, but it keeps reseting over and over.

    Any ideas?

  5. 626Pilot reporter

    The electronics are fine. I had the other LiquidCrystal_I2C library writing characters to it this morning. If you have a link to a particular thread, I will take a look. Thanks for helping.

  6. Log in to comment