7 years, 5 months ago.

Connecting a 2004 LCD via I2C

Hi, I'm using and LPC1768 board and is trying to connect a 2004 LCD via I2C to it. I2C chip is labelled PCF8574T(I have attach pictures) I found this library online but it doesnt work well. (https://developer.mbed.org/cookbook/Text-LCD-Enhanced) I got the i2c address right because i can send data to it but everytime I send anything the LCD screen will blink and gibberish characters will be displayed.

/media/uploads/Khayhen/whatsapp_image_2016-11-20_at_1.09.28_am.jpeg /media/uploads/Khayhen/whatsapp_image_2016-11-20_at_1.08.51_am.jpeg /media/uploads/Khayhen/whatsapp_image_2016-11-20_at_1.09.10_am.jpeg

This is my code.

include the mbed library with this snippet

#include "mbed.h"
#include "TextLCD.h"
 
// Host PC Communication channels
Serial pc(USBTX, USBRX); // tx, rx
 
// I2C Communication
I2C i2c_lcd(p9,p10); // SDA, SCL

 
TextLCD_I2C lcd(&i2c_lcd, 0x4E, TextLCD::LCD20x4); // I2C bus, PCF8574 Slaveaddress, LCD Type

int main() {
   lcd.printf("hi");
 
}

Please help me I really need this for my project urgently. Thank you very much!

1 Answer

7 years, 5 months ago.

Did you check the notebook page which gives more info on how to use the PCF8574 I2C expander.?

Assuming the I2C address and I2C bus are OK, make sure that the connections between the PCF8574 and the LCD parallel bus are also OK. They need to match the wiring order selected in the library. There are multiple commercial portexpander modules available and they use different connections. Select the one (eg DF_ROBOT) that matches your hardware in the config file and recompile the LCD library.

There could be another, less likely, reason besides incorrect wiring that explains gibberish characters. It might mean that your controller has a non-standard characterset. What is the type of module and controller that you are using?

Let us know what the result is. What exactly is showing on screen.

PS You can typically upload pictures when you try to edit your original post..

Accepted Answer

thanks i manage to post the pictures after changing my browser. As you can see in the photos, there is no description on the module.

posted by Khayhen Sarveswarah 26 Nov 2016

Ok, so judging from your pictures above, the I2C port expander module is most likely a clone of the LCM1602. In order to make that work with the TextLCD library you need to modify the TextLCD_Config.h file to select the proper module:

Click on the TextLCD library and find the following list of #defines in the TextLCD_Config.h file, edit the list to select the LCM1602 as shown below:

//Pin Defines for I2C PCF8574/PCF8574A or MCP23008 and SPI 74595 bus expander interfaces
//Different commercially available LCD portexpanders use different wiring conventions.
//LCD and serial portexpanders should be wired accordingly.
//
//Select Serial Port Expander Hardware module (one option only)
#define DEFAULT   0
#define ADAFRUIT  0
#define DFROBOT   0
#define LCM1602   1
#define YWROBOT   0
#define GYLCD     0
#define MJKDZ     0
#define SYDZ      0
#define WIDEHK    0
#define LCDPLUG   0

Recompile your project after this modification and try your code to see if it solved the problem.

posted by Wim Huiskamp 27 Nov 2016

Yes i have tried that and it didnt work. In fact, I have tried everyone of it and some of it I get gibberish and some I don't get anything at all. If this helps I have tried with an arduino using this library(http://arduino-info.wikispaces.com/LCD-Blue-I2C) and it works perfectly fine. I would love to use an arduino instead but my proect requires me to use a MBED. My last resort will be to convert the arduino library to work with mbed but as I'm not very familiar to C++ and MBED it will be quite hard.

posted by Khayhen Sarveswarah 28 Nov 2016

I am not sure which one of the arduino examples you have tried successfully, there are three different versions mentioned on the page you referred. Anyhow, I think the most likely modules are the LCM1602 and YWROBOT. Do you see any response when trying these. Make sure you power down the LCD before trying a new version. The controller could be stuck when the wrong commands have been sent on the previous attempt. Make sure you have pull-up Resistors on the SDA and SCL lines. Make sure the powersupply to the display is 5V. Many dont work correctly on 3V3.

posted by Wim Huiskamp 28 Nov 2016

Yes I do power down the LCD every time I try a new code and I do have pull-up resistors on the SDA and SCL lines and the power supply is 5V. The arduino library im using is the NewliquidCrystal_1.3.4 and the example sketch labeled "HelloWorld_i2c" which uses the <LiquidCrystal_I2C.h> from the zip file.

Although I just realised my config file does not have as many options as you do and my library is downloaded from the same link. This is my config file

include the mbed library with this snippet

//Select Serial Port Expander Hardware module (one option only)
#define DEFAULT        1
#define ADAFRUIT       0
#define DFROBOT        0
#define YWROBOT        0
#define GYLCD          0
#define SYDZ           0

posted by Khayhen Sarveswarah 01 Dec 2016

You must have an older version of the lib if you don't have the port expander options shown in my list above. Your list does not yet have the LCM1602, which is what you probably need for your display.. Try rightclick on the TextLCD lib in your project and select ''update'' to get the most recent one. Then modify the list to enable LCM1602 and disable all others. The TextLCD_Config.h file should be revision v09.

Note that when you import an example program instead of the library itself, you always get the option to either update the libs to the latest revision or to use the same revision that was used in the example.

Just to check and make sure: please post the line in your working arduino code where the display is declared. That line provides not only the I2C address but also the pinmapping for the portexpander.

UPDATE: I have successfully tested the TextLCD lib with a 20x4 display and using the same FC-113 portexpander that is shown in your pictures above. The config settings are LCM1602 and I2C address 0x4E.

posted by Wim Huiskamp 02 Dec 2016

Sorry for a late reply. I had exams for the past month. I manage to update the libraries and use the config settings mentioned above and manage to get it working succesfully. Thank you so much for your help. Can't believe I solved the problem with just an update. This is my first time using MBED so I'm not familiar with the IDE, so I apologize for my lack of knowlegde. Thanks again! Cheers!

posted by Khayhen Sarveswarah 14 Dec 2016