4 years, 4 months ago.

LCD1602 I2C not working

Hello everybody, i am having a problem with LCD1602 I2C I am trying to make it work with a STM-F401RE Nucleo, but it always show me only dark rectangles on one line.

SDA and SCL have been connected to pins D14,D15. I have already changed the module in the Text_LCDConfig.h to LCM1602.

This is the code: /media/uploads/giuseppespera/unnamed.jpg

Text LCD

#include "mbed.h"
#include "TextLCD.h"
 
// Host PC Communication channels
Serial pc(USBTX, USBRX); // tx, rx
 
// I2C Communication
I2C i2c_lcd(D14,D15); // SDA, SCL
 
 
TextLCD_I2C lcd(&i2c_lcd, 0x7E, TextLCD::LCD16x2); // I2C bus, PCF8574 Slaveaddress, LCD Type
 
int main() {
   lcd.printf("hello world");
 
}

Thanks for your help.

3 Answers

2 years, 4 months ago.

Dear Giuseppe Spera, I have the same problem with my LCD Display. Have you solved it? What was the reason?

Hi, for some reason i2c module from aliexpress not working with Wim's lib or something like that. You can try this, maybe it will help maybe not.

Import programLiquidCrystal_I2C_for_Nucleo

This library is designed to work with LCD screens on the I2C bus. This library is an import of arduino library LiquidCrystal_I2C. This library was tested on the Nucleo F103 debug card using the LCD module 1602A.

posted by Jan Kamidra 09 Jun 2019

Thanks, Giuseppe ! I have already found the solution! My problem was connected with wrong i2c address. Now everithing is Ok.

posted by Alexander Urezchenko 09 Jun 2019
4 years, 4 months ago.

Hi, I have experience only with a LCD16x04 and 20x04 with parallel communication but dark rectangles on one line is visible when LCD is only powered / connected but not used. So a problem can be in I2C communication. https://github.com/ARMmbed/mbed-os/issues/4214 Test your I2C for avoid this library problem... Good luck. J.

4 years, 4 months ago.

Jan is right that dark rectangles indicate your display is getting power but is not getting initialised. I recommend that you first make sure you have the most recent TextLCD library installed: right click on the lib and select ''update''. Next modify the config file to select the correct backpack module. Next make sure you have the correct I2C slave address for the display. There are several different (clone) versions of the I2C backpack around. Some use the PCF8574 portexpander and some use the PCF8574A. The backpacks also have 3 address select switches or solderbridges that are not always set at the same default position. Post a picture of the module if possible. Try address 0x40 (0x42, 0x44, 0x46 etc through 0x4E) instead of (0x70 through) 0x7E. Obviously you need to make sure that the I2C wiring is OK and that the pull-up resistors are installed.

Thank you for your answer.

I already updated the library. The module is LCM1602 and that's the one I selected in the TextLCD_config.h I tried all the address from 0x40 to 0x4E, but nothing changed. What are the pullup resistors you are talking about? Thx

PS: I posted a pic of the module

posted by Giuseppe Spera 23 Jun 2017

If you are not sure with your I2C address you can import simple program like "i2c_scanner". Pull Up resistors hold logic value on SDA and SCL when Is not defined by any device. So take 3k3 or 4k7 resistors and connect it between SDA and +5V/+3V and same for SCL.

posted by Jan Kamidra 23 Jun 2017

Thx for the picture. The Sunfounder portexpander uses a PCF8574. The default address should be 0x4E. See here. The pull-ups may be included on the expander board, but you should try with 4K7 anyhow. Note that you may have to use a 5V powersupply for the LCD instead of 3V3. You can get 5V from the nucleo on CN6. Make sure you have also updated the mbed lib to the latest version (right click).

Are you sure the program is running? Try this:

#include "mbed.h"
#include "TextLCD.h"
 
// Host PC Communication channels
Serial pc(USBTX, USBRX); // tx, rx

DigitalOut myled(LED1); 

// I2C Communication
I2C i2c_lcd(D14,D15); // SDA, SCL
 
 
TextLCD_I2C lcd(&i2c_lcd, 0x4E, TextLCD::LCD16x2); // I2C bus, PCF8574 Slaveaddress, LCD Type
 
int main() {
   pc.printf("hello world");

   lcd.printf("hello world");

   lcd.setBacklight(TextLCD::LightOn);

    while(1) {
        myled = 1; // LED is ON
        wait(0.2); // 200 ms
        myled = 0; // LED is OFF
        wait(1.0); // 1 sec
    }
}

UPDATE: I have successfully tested the TextLCD I2C portexpander code with mbed lib version 145 on an F103 and F401 using an LCM1602 clone at default slave address 0x4E and 5V supply. The 20x2 display that I used did not work on 3V3.

posted by Wim Huiskamp 23 Jun 2017