User avatar
dentex
Posts: 180
Joined: Sun May 20, 2012 7:58 am
Location: Italy
Contact: Website

Debugging a I2C 20x4 LCD [SOLVED - hardware issue]

Fri Sep 16, 2016 5:46 pm

Hello!
I have this 20x4 LCD. I know they are not all the same: in fact many libraries I tried had the address 0x03 or 0x3f, but my LCD returns:

Code: Select all

$ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- 27 -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- -- 
...so I changed the address in those libraries... and this is the only thing I managed to change. Anyway, the display remains blank... Nothing seems to work.

My question (before posting code examples I used):
What else may I need to look at, other than the address, to modify the python scripts and write on this LCD?

Libraries I tried:
https://github.com/alinleonard/LCD-I2C-Raspberry-Pi-2
https://github.com/mmmarq/raspberry_lcd
https://github.com/khelif96/piClock
viewtopic.php?p=291313#p291313

This is it:
Image
Last edited by dentex on Sat Oct 01, 2016 1:52 pm, edited 1 time in total.
One of my projects with the Raspberry Pi:
--------------------------------------------------------
(Raspberry) Pi Aquarium Controller: https://github.com/dentex/piac

User avatar
joan
Posts: 14847
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Debugging a I2C 20x4 LCD

Fri Sep 16, 2016 6:44 pm

My example at http://abyz.co.uk/rpi/pigpio/examples.h ... i2c_lcd_py defaults to address 0x27 so may be compatible with your backpack.

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5554
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: Debugging a I2C 20x4 LCD

Fri Sep 16, 2016 7:42 pm

joan wrote:My example at http://abyz.co.uk/rpi/pigpio/examples.h ... i2c_lcd_py defaults to address 0x27 so may be compatible with your backpack.
Most of the I2C backpacks I've tried use that address too** by default (but my code is 'C' based).
dentex wrote: ...
...so I changed the address in those libraries... and this is the only thing I managed to change. Anyway, the display remains blank... Nothing seems to work.
...
W.r.t. a blank display - did you also try tweaking the contrast pot on the backpack? Before any code is run you should see one or two rows of "blocks" on an uninitialised display****
Trev.
** https://www.cpmspectrepi.uk/raspberry_p ... D_Backpack onwards
**** as shown here: https://www.cpmspectrepi.uk/raspberry_p ... cklight.29 (16x2 & 20x4 displays)
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

User avatar
dentex
Posts: 180
Joined: Sun May 20, 2012 7:58 am
Location: Italy
Contact: Website

Re: Debugging a I2C 20x4 LCD

Fri Sep 16, 2016 9:25 pm

joan wrote:My example at http://abyz.co.uk/rpi/pigpio/examples.h ... i2c_lcd_py defaults to address 0x27 so may be compatible with your backpack.
Thanks Joan, I'll try your library tomorrow and I'll let you know how it goes.
FTrevorGowen wrote: W.r.t. a blank display - did you also try tweaking the contrast pot on the backpack? Before any code is run you should see one or two rows of "blocks" on an uninitialised display
Trevor, thanks to you too.
Yes I've played with the contrast knob and it should be ok. Also, I see the two lines when the LCD is not initialized.

Interesting link; my backpack is the black generic one with the 0x27 address.
One of my projects with the Raspberry Pi:
--------------------------------------------------------
(Raspberry) Pi Aquarium Controller: https://github.com/dentex/piac

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5554
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: Debugging a I2C 20x4 LCD

Sat Sep 17, 2016 2:16 pm

dentex wrote: ...
FTrevorGowen wrote: W.r.t. a blank display - did you also try tweaking the contrast pot on the backpack? Before any code is run you should see one or two rows of "blocks" on an uninitialised display
Trevor, thanks to you too.
Yes I've played with the contrast knob and it should be ok. Also, I see the two lines when the LCD is not initialized.

Interesting link; my backpack is the black generic one with the 0x27 address.
That backpack is very common, often supplied "pre-wired" to the display. It's also the type, when operating as a 4-bit interface, I discovered that the E-strobe timings (in 'C') had to be significantly increased to ensure reliable working with some of the displays I've tried:
https://www.cpmspectrepi.uk/raspberry_p ... gData.html
Whilst I suspect that might be due to variations of the (on-board) display controller's clock between samples, or the exact controller i.c. (which may be a "compatible" device) or even "logic-level" voltage tolerances, since I (no longer) have access to an oscilloscope I've not been able to diagnose further. When I flagged this up in the forum some time ago there was some indication that some software libraries used longer timings than others.
Trev.
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

User avatar
dentex
Posts: 180
Joined: Sun May 20, 2012 7:58 am
Location: Italy
Contact: Website

Re: Debugging a I2C 20x4 LCD

Mon Sep 19, 2016 12:26 pm

Thanks for the additional information. Unfortunately I didn't have time to check again this LCD...
Do you think there's anything on the LCD IC itself that is worth looking at? (To identify IC packages, etc...)

Thanks.
One of my projects with the Raspberry Pi:
--------------------------------------------------------
(Raspberry) Pi Aquarium Controller: https://github.com/dentex/piac

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5554
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: Debugging a I2C 20x4 LCD

Mon Sep 19, 2016 12:55 pm

dentex wrote: ...
Do you think there's anything on the LCD IC itself that is worth looking at? (To identify IC packages, etc...)
Unlikely, given that none of the "ic blobs" on the displays I've tried have any "identifying" codes etc. (However, if yours does - please post a photo! )
Trev.
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

User avatar
dentex
Posts: 180
Joined: Sun May 20, 2012 7:58 am
Location: Italy
Contact: Website

Re: Debugging a I2C 20x4 LCD

Mon Sep 19, 2016 1:06 pm

FTrevorGowen wrote:...please post a photo! )
Trev.
Sure! It's just a few messages above. The one with the "2004A" mark on its back.
One of my projects with the Raspberry Pi:
--------------------------------------------------------
(Raspberry) Pi Aquarium Controller: https://github.com/dentex/piac

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5554
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: Debugging a I2C 20x4 LCD

Mon Sep 19, 2016 3:53 pm

dentex wrote:
FTrevorGowen wrote:...please post a photo! )
Trev.
Sure! It's just a few messages above. The one with the "2004A" mark on its back.
Forgot you'd done that :oops: (Or, rather I'd scrolled past it to read your previous post)
Just like mine - lot's of unidentifiable "ic blobs", so no new info. there!
Trev.
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

User avatar
dentex
Posts: 180
Joined: Sun May 20, 2012 7:58 am
Location: Italy
Contact: Website

Re: Debugging a I2C 20x4 LCD

Mon Sep 19, 2016 5:57 pm

Don't worry... Thanks again Trev.

I suspected those black hard material drops on the back were the "IC blobs" you were referring to...

We'll see what I can do.
One of my projects with the Raspberry Pi:
--------------------------------------------------------
(Raspberry) Pi Aquarium Controller: https://github.com/dentex/piac

User avatar
dentex
Posts: 180
Joined: Sun May 20, 2012 7:58 am
Location: Italy
Contact: Website

Re: Debugging a I2C 20x4 LCD

Sun Sep 25, 2016 6:41 pm

dentex wrote:
joan wrote:My example at http://abyz.co.uk/rpi/pigpio/examples.h ... i2c_lcd_py defaults to address 0x27 so may be compatible with your backpack.
Thanks Joan, I'll try your library tomorrow and I'll let you know how it goes.
Sorry for the delay...
Just tried your library, but nothing... the LCD stays blank. The script proceed anyway without errors (after launching `pigpiod`).

If I may ask, what can I try to tweak, in your opinion?
Unfortunately all the stuff regarding those LCDs seems a bit out of reach for me. :?
Thanks.
One of my projects with the Raspberry Pi:
--------------------------------------------------------
(Raspberry) Pi Aquarium Controller: https://github.com/dentex/piac

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5554
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: Debugging a I2C 20x4 LCD

Sun Sep 25, 2016 6:59 pm

@dentex this might be a "red herring" but are you using a 5V display + I2C backpack (powered by 5V) without any level-shifters (I2C compatible)? (I've always used such, even though some 5V I2C devices can respond to 3.3V I2C levels). If you're not using level-shifters it's been suggested that a diode in the display's power line (dropping the supply to ~4.3V) may get things working (YMMV).
Trev.
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

User avatar
dentex
Posts: 180
Joined: Sun May 20, 2012 7:58 am
Location: Italy
Contact: Website

Re: Debugging a I2C 20x4 LCD

Sun Sep 25, 2016 7:04 pm

FTrevorGowen wrote:@dentex this might be a "red herring" but are you using a 5V display + I2C backpack (powered by 5V) without any level-shifters (I2C compatible)? (I've always used such, even though some I2C devices can respond to 3.3V I2C levels). If you're not using level-shifters it's been suggested that a diode in the display's power line (dropping the supply to ~4.3V) may get things working (YMMV).
Trev.
Hi,
yes, 5V display + I2C backpack + powered by RPi's 5V and NO level-shifter.
I must try your suggestion.

Anyway, the LCD should be one of those designed for Arduino...
One of my projects with the Raspberry Pi:
--------------------------------------------------------
(Raspberry) Pi Aquarium Controller: https://github.com/dentex/piac

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5554
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: Debugging a I2C 20x4 LCD

Sun Sep 25, 2016 7:09 pm

dentex wrote:
FTrevorGowen wrote:@dentex this might be a "red herring" but are you using a 5V display + I2C backpack (powered by 5V) without any level-shifters (I2C compatible)? (I've always used such, even though some I2C devices can respond to 3.3V I2C levels). If you're not using level-shifters it's been suggested that a diode in the display's power line (dropping the supply to ~4.3V) may get things working (YMMV).
Trev.
Hi,
yes, 5V display + I2C backpack + powered by RPi's 5V and NO level-shifter.
I must try your suggestion.
Anyway, the LCD should be one of those designed for Arduino...
FWIW, these are the level-shifters I've tried (4 out of six types so far) with links to the circuit schematics etc.):
https://www.cpmspectrepi.uk/raspberry_p ... dules.html
Trev.
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

User avatar
joan
Posts: 14847
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Debugging a I2C 20x4 LCD

Sun Sep 25, 2016 7:41 pm

@dentex

I just downloaded http://abyz.co.uk/rpi/pigpio/code/i2c_lcd_py.zip and ran it without problems on an I2C backpack connected to a LCD display.

The most likely problem is in the initialisation. I found several methods on line but can't remember why I chose the method I use. Perhaps search for alternative initialisation sequences.

I'm referring to this code.

Code: Select all

   def _init(self):

      self._inst(0x33) # Initialise 1
      self._inst(0x32) # Initialise 2
      self._inst(0x06) # Cursor increment
      self._inst(0x0C) # Display on,move_to off, blink off 
      self._inst(0x28) # 4-bits, 1 line, 5x8 font
      self._inst(0x01) # Clear display

User avatar
dentex
Posts: 180
Joined: Sun May 20, 2012 7:58 am
Location: Italy
Contact: Website

Re: Debugging a I2C 20x4 LCD

Sun Sep 25, 2016 7:49 pm

Thanks guys. At least I have something to try.

@Trev
I'm waiting for a couple of those level-shifters. They are the generic F type (that seems the same of the red D one). They were advertised as I2C level-shifters, bidirectional.

@joan
Thanks for the hint on the initialization. I'll search for more info on this part.

:)
One of my projects with the Raspberry Pi:
--------------------------------------------------------
(Raspberry) Pi Aquarium Controller: https://github.com/dentex/piac

User avatar
dentex
Posts: 180
Joined: Sun May 20, 2012 7:58 am
Location: Italy
Contact: Website

Re: Debugging a I2C 20x4 LCD

Tue Sep 27, 2016 2:09 pm

No luck until now.
The seller sent me a datasheet, but it seems to be for another LCD... It's for the J204A while mine is marked as 2004A... I don't know if it's the same thing and other than that, the PDF it's like Arab to me:
https://drive.google.com/open?id=0B1Ewr ... GlSSjZ4Tjg

So I decided to buy another LCD, due to the small price found on Amazon (just 5€; same as from China): this time should be really a J204A.
One of my projects with the Raspberry Pi:
--------------------------------------------------------
(Raspberry) Pi Aquarium Controller: https://github.com/dentex/piac

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5554
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: Debugging a I2C 20x4 LCD

Tue Sep 27, 2016 2:37 pm

W.r.t. initialisation sequences (8-bit or 4-bit), FWIW I based my 'C' code functions upon those in wiringPi with modifications derived from the information in this datasheet**:
http://www.hobbytronics.co.uk/datasheets/HD44780.pdf
together with, where appropriate, the 'E' strobe timing length variations (for stability between different display samples) referred to in a previous post.
Trev.
** Figures 23 and 24. NB: the I2C backpack uses the 4-bit interface method and thus the display needs to be initialised correctly since, otherwise, the it will assume an 8-bit interface AFAICT. It is possible to have an I2C + additional GPIO pins based 8-bit interface, eg. something like what I did here:
https://www.cpmspectrepi.uk/raspberry_p ... alLCD.html
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

User avatar
joan
Posts: 14847
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Debugging a I2C 20x4 LCD

Tue Sep 27, 2016 3:06 pm

I had another look at my code and saw

Code: Select all

   """
   This class provides simple functions to display text on an I2C LCD
   based on the PCF8574T I2C 8-bit port expander.

   PCF8574T P7   P6   P5   P4   P3   P2   P1   P0
   HD44780  B7   B6   B5   B4   BL   E    RW   RS

   This code defaults to working with an adapter with the above
   configuration.

   If yours is different you will have to specify the mapping
   when you instantiate the LCD.
   """
That will probably be dentex's problem. The init method allows you to specify the position of B4, BL, E, RW, RS.

If I remember rightly a common alternative would be RS=4, RW=5, E=6, BL=7, B4=0.

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5554
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: Debugging a I2C 20x4 LCD

Tue Sep 27, 2016 3:16 pm

joan wrote:I had another look at my code and saw

Code: Select all

   """
   This class provides simple functions to display text on an I2C LCD
   based on the PCF8574T I2C 8-bit port expander.

   PCF8574T P7   P6   P5   P4   P3   P2   P1   P0
   HD44780  B7   B6   B5   B4   BL   E    RW   RS

   This code defaults to working with an adapter with the above
   configuration.

   If yours is different you will have to specify the mapping
   when you instantiate the LCD.
   """
That will probably be dentex's problem. The init method allows you to specify the position of B4, BL, E, RW, RS.

If I remember rightly a common alternative would be RS=4, RW=5, E=6, BL=7, B4=0.
Most of the backpacks I've tried had the first arrangement, apart from this one:
https://www.cpmspectrepi.uk/raspberry_p ... D_Backpack
(which also had a different default I2C address). However, IIRC, in one of @texy's threads there was another variant.
Trev.
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

User avatar
dentex
Posts: 180
Joined: Sun May 20, 2012 7:58 am
Location: Italy
Contact: Website

Re: Debugging a I2C 20x4 LCD

Wed Sep 28, 2016 3:22 pm

@Trevor
You do wonderful things, as I can see at https://www.cpmspectrepi.uk/raspberry_p ... alLCD.html
Needless to say they're too far from me to reach. But thanks anyway.

@joan
joan wrote:...The init method allows you to specify the position of B4, BL, E, RW, RS.
If I remember rightly a common alternative would be RS=4, RW=5, E=6, BL=7, B4=0.
I tried the second scheme, again, no luck...
All I can say is that from Trevor's page, the default sequence seems to be the right one:
bp_.jpg
bp_.jpg (57.58 KiB) Viewed 3837 times
Another thing: the seller confirmed that the 2004A and J204A are the same LCD. Looking at some pictures online, they are identical. Is there something useful I can find into its datasheet, to fix this stuff?
https://drive.google.com/open?id=0B1Ewr ... GlSSjZ4Tjg

Thanks again for all the assistance.
One of my projects with the Raspberry Pi:
--------------------------------------------------------
(Raspberry) Pi Aquarium Controller: https://github.com/dentex/piac

User avatar
DougieLawson
Posts: 38527
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Debugging a I2C 20x4 LCD

Wed Sep 28, 2016 6:43 pm

What you've got looks very like the (discontinued) RyanTech 20x4 I²C LCD
https://ryanteck.uk/displays/35-20x4-ch ... 07313.html

Try this library: https://bitbucket.org/ryanteckltd/16x2-python-i2c-lib

It looks like the I2C board has a SSOP MCP23017, so we just need to work out what pins on that are wired to RS and EN on the LCD. Once you have the RS & EN pins identified it's easy to send random bytes on the other MCP23017 output pins and random characters should appear (bit of guess work needed) unless you can read the signals.

HD44780 LCDs are not difficult to program and driving them with MCP23017s is trivial.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

I'll do your homework for you for a suitable fee.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
dentex
Posts: 180
Joined: Sun May 20, 2012 7:58 am
Location: Italy
Contact: Website

Re: Debugging a I2C 20x4 LCD

Sat Oct 01, 2016 8:17 am

Thanks for the suggestions, I already tried both libraries... Still nothing.
One of my projects with the Raspberry Pi:
--------------------------------------------------------
(Raspberry) Pi Aquarium Controller: https://github.com/dentex/piac

User avatar
joan
Posts: 14847
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Debugging a I2C 20x4 LCD

Sat Oct 01, 2016 8:34 am

It might be worth trying to see if the device is a MCP23017 or not.

After boot, and before trying to talk to the chip, try the following.

Code: Select all

$ sudo pigpiod
$ pigs i2co 1 0x27 0
0
$ pigs i2cwd 0 0 i2crd 0 18
18 255 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
$ pigs i2cc 0

User avatar
dentex
Posts: 180
Joined: Sun May 20, 2012 7:58 am
Location: Italy
Contact: Website

Re: Debugging a I2C 20x4 LCD

Sat Oct 01, 2016 10:09 am

joan wrote:It might be worth trying to see if the device is a MCP23017 or not.

After boot, and before trying to talk to the chip, try the following.

Code: Select all

$ sudo pigpiod
$ pigs i2co 1 0x27 0
0
$ pigs i2cwd 0 0 i2crd 0 18
18 255 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
$ pigs i2cc 0
Hello joan,
this is what I get with the above commands:

Code: Select all

~ $ sudo pigpiod
~ $ pigs i2co 1 0x27 0
0
~ $ pigs i2cwd 0 0 i2crd 0 18
18 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
~ $ pigs i2cc 0
~ $
Anyway, I have an MCP23017 that I used to play with some LEDs and its address is 0x20. Can it be different?
Last edited by dentex on Sat Oct 01, 2016 10:16 am, edited 1 time in total.
One of my projects with the Raspberry Pi:
--------------------------------------------------------
(Raspberry) Pi Aquarium Controller: https://github.com/dentex/piac

Return to “Interfacing (DSI, CSI, I2C, etc.)”