0

I try to interface my 2004-LCD display with wiringPi (in Python 3). The display is connected to a PCF8574-chip, so I need to use I2C.

This is my test code:

import wiringpi2 as wiringpi

wiringpi.wiringPiSetupSys();

af_base = 100

af_rs = af_base + 0
af_e = af_base + 2
af_db4 = af_base + 4
af_db5 = af_base + 5
af_db6 = af_base + 6
af_db7 = af_base + 7

af_backlight = af_base + 3

def backlight_on():
    wiringpi.digitalWrite(af_backlight, 1)

def backlight_off():
    wiringpi.digitalWrite(af_backlight, 0)

wiringpi.pcf8574Setup(af_base, 0x27)

lcd_handle = wiringpi.lcdInit(4, 20, 4, af_rs, af_e, af_db4, af_db5, af_db6, af_db7, 0, 0, 0, 0)

backlight_on()

wiringpi.lcdPrintf(lcd_handle, "Hello World!")

The code runs without any errors. The backlight on the LCD first turns out and then turns on again, when I run backlight_on().

However, the text doesn't show up on the display.

To check if the LCD or the I2C-chip is damaged, I followed the instructions from this website.

Now comes the strange part:
When I now run the test code from above again, it works without any hassle.

It seems, the other project loads some stuff which is essential for controlling the LCD.

What is missing in my test code to interface the LCD in the first place?

  • Presumably the other set of code is doing some required initialisation. – joan Sep 17 '15 at 21:43
  • @joan I also think so. However, I looked through the other code and didn't find anything special... – speendo Sep 17 '15 at 21:44
2

I have exactly the same problem. I did some research and found out the following code works. I don't know why it works but it just works. Add the following to the beginning of your script:

port=1   # Depends on your pi rev. Run i2cdetect to find out
bus = smbus.SMBus(port)
bus.write_byte_data(self.i2caddr, self.port, 0x28 >> 4)
bus.write_byte_data(self.i2caddr, self.port, 0x28 & 0x0F)
bus.write_byte_data(self.i2caddr, self.port, 0x0)

Also you might want to force the RW pin to be LOW:

af_rw = pinbase + 1
wiringpi.pinMode(af_rw, 1)
wiringpi.digitalWrite(af_rw, 0)
  • Update: just these two lines will work, bus = smbus.SMBus(port) bus.write_byte_data(self.i2caddr, self.port, 0x0) – Timothy Wong Mar 30 '16 at 23:05
1

The python code in this page works fine, just follow all the directions there: http://hardware-libre.fr/2014/03/en-raspberry-pi-using-a-4x20-characters-display/

to find the address of your pcf8574 (in my case it is pcf8574AT therefore the address is 0x3f), once you get it, change the value in the python code, get a terminal screen and execute the following command: sudo ./i2cdetect -y 1

Good luck !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.