Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years, 4 months ago.
Recognition problem with the display LCD 20X4 module with I2C adapter PCF8574T and the NUCLEO-F401RE
Hi all, I'm trying to use the following basic example with an HD44780 LCD device and a Nucleo board F401RE:
#include "mbed.h" #include "TextLCD.h" // PCF8574T #define SLAVEADDRESS 0x4E //PCF8574AT //#define SLAVEADDRESS 0x7E // Instanzia un oggetto I2C assegnando i du pin SDA ed SCL //I2C i2c_lcd(PB_9,PB_8); // SDA, SCL I2C i2c_lcd(PB_7,PB_6); // SDA, SCL // Instanzia un oggetto TextLCD_I2C per la gestione del display via I2Cbus //TextLCD_I2C lcd(&i2c_lcd,SLAVEADDRESS, TextLCD::LCD16x2); // I2C exp: I2C bus, PCF8574AT Slaveaddress, LCD Type TextLCD_I2C lcd(&i2c_lcd,SLAVEADDRESS, TextLCD::LCD20x4); // I2C exp: I2C bus, PCF8574AT Slaveaddress, LCD Type int main() { // Spegne il cursore lcd.setCursor(TextLCD::CurOff_BlkOff); // Pulisce lo schermo lcd.cls(); // Stampa sullo schermo lcd.printf(" Welcome to"); // punta alla prima colonna del secondo rigo del display lcd.setAddress(0, 1); // Stampa sullo schermo lcd.printf("LCD display demo"); wait(2); }
The I2C PCF8574T adapter address is 0x27 (which becomes 0x4E in mbed format). After generated and loaded binary code, I do not see any message appear on the LCD screen. The strange thing is that the LCD device works properly with the same pins, the same Nucleo board, if I use an example code for a different platform (which accepts the slave address in "native" format 0x27). Furthermore, by modifying the code to handle a 16x2 LCD display (same type of I2C adapter but I2C address = 0x7E) the example posted works correctly. Could you please help me?
Thanks in advance
1 Answer
7 years, 4 months ago.
Not sure I understand the problem Note that PCF8574T has mbed baseaddresses 0x40..0x4E, while PCF8574AT has baseaddresses 0x70..0x7E. The I2C backpacks for LCDs differ in PCF type as well as in default baseaddress. First make sure you have selected the correct backpack type in the TextLCD config file (eg LCM1602). Next use the correct slaveaddress in the TextLCD declaration and then recompile all.
Hi wim, many thanks for your feedback. I have some request for clarification: 1) "Note that PCF8574T has mbed baseaddresses 0x40..0x4E, ..." Should I try the example above with all addresses in the range you have suggested? 2) "make sure you have selected the correct backpack type in the TextLCD config file (eg LCM1602)"
Could you please clarify which part of TextLCD config file should be modified? Thanks in advance
posted by 06 Aug 2017The info on the backpack types and configuration is on the handbook page here. The address settings can be checked by inspecting the module or just testing. Address 0x40, 0x4E and 0x7E are most common.
posted by 06 Aug 2017Hi Wim, again many thanks for the support. Unfortunately your notes do not solve my problem (somewhat intricate for me), maybe because I did not explain it well. I try to summarize what I'm experiencing: The 20x4 LCD display (with its I2C adapter) works properly, directly connected to the PB_7,PB_6 pins of my Nucleo Board if, instead of the simple "mbed" program shown above, I use a java script interpreter (relevant firmware previously loaded on the board) to print an "Hello world" on the LCD screen. The mentioned interpreter\program accepts 0x27 as the I2C address of the I2C adapter (0x4E in mbed format), nothing else to connect to the LCD display. Unfortunately, if I leave the configuration of the board + display connections unchanged, and load the sample program shown above, instead of the js interpreter, it does not work (e.g. nothing is printed on the screen). I suspect the mbed library could configure the I2C pins differently (perhaps referring to internal pullup resistors?) and this creates the difference in the behavior between the two platforms. Also using external pull ups resistors, between SDA, SCL and Vcc, I get the same result (OK with the interpreter, KO with the mbed example). Could you please help me to resolve such issue?
Thanks in advance... Regards, Luigi
posted by 06 Aug 2017Ok, so 20x4 works with js code using 0x27, but not with above mbed code using 0x4E. That probably means you have selected the wrong I2C expander module in the TextLCD config file. What module is currently selected in the config file? Please post the relevant lines of code and post a picture of the I2C module to verify which type it is. Next, rightclick on the TextLCD lib in your project and select update to make sure you have the most recent version. Modify the config file again to select the proper I2C module and recompile all. Given that the 16x2 LCD works with the mbed code above it seems that the problem is due to a different I2C backpack. The mbed code has selected the right one for the 16x2, the js code is probably hardcoded for the module used on the 20x4. The modules have different internal wiring which is why you need to change the config file for mbed.
posted by 07 Aug 2017Hi Wim, many thanks for your suggestions. I have updated the TextLCD library as you suggested, now my TextLCD revision is 41:b4ec0bc. The pin mapping definitions in TextLCD_Config.h is the following (I did not change the file content after the update):
Select Serial Port Expander Hardware module (one option only)
- define DEFAULT 0
- define ADAFRUIT 0
- define DFROBOT 0
- define LCM1602 0
- define YWROBOT 1
- define GYLCD 0
- define MJKDZ 0
- define SYDZ 0
- define WIDEHK 0
- define LCDPLUG 0
I have verified that this configuration works correctly with the 16x2 LCD display, but not with 20x4 display. Both devices works well by using: #define LCM1602 1. So to work with both displays I have to use that configuration for the file TextLCD_Config.h, Thanks again for your support!
Regards, Luigi
posted by 07 Aug 2017