Problem with Nucleo-L152RE with LCD through I2C

28 Nov 2014

Hi, I tried to connect a 16x2 LCD through one of those cheap I2C lcd pcb using a PCF8574. The configuration works fine on an Arduino UNO. If I connect a simple program using the same address (0x27) nothing happens on the screen. So I tried a little scan to see what the address should be. The address I got back is 0x4E which happens to be twice the address value on the UNO. SO I tried my hello world text program with address 0x4E. The display actually responds by some flashing. Then the backlight turns off but still no text. This is the program:

#include "mbed.h"
#include "TextLCD.h"

Serial pc(USBTX, USBRX);                                                     // Serial connection through USB

I2C i2c_lcd(I2C_SDA, I2C_SCL);                                           // I2C setup

TextLCD_I2C lcd(&i2c_lcd, 0x4E, TextLCD::LCD16x2);          //2C bus, PCF8574 Slaveaddress, LCD Type

int main() {

    lcd.printf("Hello World!\n");
}

I have tried this program using both the online MBED compiler as the GCC-ARM compiler under Eclipse. Same effect.

What am I doing wrong? Regards Nico

28 Nov 2014

Hi Nico, the difference in I2C slaveaddress format between arduino and mbed is well known. The Arduino I2C libraries use the 7bit version of the slaveaddress. The mbed libraries on the other hand use the 8bit address convention. That simply means you have to leftshift the arduino addressbits by one position, so 0x27 (Arduino) becomes 0x4E (mbed). This explains the first part of your problem.

The second part may be related to incorrect wiring between the PCF8574 and the LCD. Note that several different PCF8574 interface boards are found on the internet and not all use the same connections between the PCF8574 pins and the LCD pins. Check the pinmap table in TextLCD.h (or TextLCD_config.h if you use the latest version of my TextLCD lib). Look for the following module selection part and check that you have the selected the correct mapping for your PCF8574 interface board.

//Select Hardware module (one option only)
#define DEFAULT        1
#define ADAFRUIT       0
#define DFROBOT       0
#define YWROBOT      0
#define GYLCD            0
#define SYDZ               0
 
//Select Hardware module (one option only)
#if (DEFAULT==1)
//Definitions for default (WH) mapping between serial port expander pins and LCD controller
//This hardware supports the I2C bus expander (PCF8574/PCF8574A or MCP23008) and SPI bus expander (74595) interfaces
//See https://mbed.org/cookbook/Text-LCD-Enhanced
//
//Note: LCD RW pin must be connected to GND
//      E2 is used for LCD40x4 (second controller)
//      BL may be used to control backlight
#define D_LCD_PIN_D4   0
#define D_LCD_PIN_D5   1
#define D_LCD_PIN_D6   2
#define D_LCD_PIN_D7   3
#define D_LCD_PIN_RS   4
#define D_LCD_PIN_E     5
#define D_LCD_PIN_E2   6
#define D_LCD_PIN_BL   7

etc

Your module might be the Arduino-IIC-LCD GY-LCD-V1 since it seems to use 0x4E as default address. Try the GYLCD setting in the list above.

Also note that the powersupply for the LCD often needs to be 5V. The LCD modules may not work when you power them with 3V3. The datalines (and I2C bus) on the other hand will accept 3V3.

If that does not work please provide more details about your hardware (PCF8574 module and LCD).

29 Nov 2014

Damn I should have noticed that my self. I'll give it a try this weekend Thx Nico Verduin

02 Dec 2014

They always told me that "self knowledge is a virtue :)"..... So why didn't I just look in the Arduino I2C library where it is defined...... #$%^&^%$#$%^. It imatches the dfRobot.... works like a charm :) Thanks for the direction though!!!!