lolouk44
Posts: 25
Joined: Sat Oct 20, 2012 11:01 pm

I2C LCD not detected

Wed Jun 26, 2013 9:12 am

Hi all,

I hope someone can help me.
trying to use a SainSmart 20x4 LCD (http://www.amazon.co.uk/gp/product/B007 ... UTF8&psc=1) connected via I2C.

1) I can manually drive pins 0 & 1 to high and low so I know they work.
2) I've commented the blacklist I2C-bcm2708 and blacklist SPI-bcm2708 entries from raspi-blacklist.conf
3) I've added i2c-dev in /etc/modules underneath snd-bcm2835
4) I've installed i2c-tools
5) Running ls -la /dev/i2c-0 returns crw-rw---T 1 root i2c 89, 0 Jun 15 10:21 /dev/i2c-0
6) I had the LCD replaced thinking it might be a faulty one, no difference.

Yet i2cdetect -y 0 (or i2cdetect -y 1) returns nothing:

Code: Select all

    0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --       
Any idea about what's wrong or what I could test?

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

Re: I2C LCD not detected

Wed Jun 26, 2013 10:22 am

What connections have you made between the Pi and the I2C device?

lolouk44
Posts: 25
Joined: Sat Oct 20, 2012 11:01 pm

Re: I2C LCD not detected

Wed Jun 26, 2013 10:26 am

Hi @Joan,

Thanks for your reply.
I have the LCD wired as in this picture:
Image

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

Re: I2C LCD not detected

Wed Jun 26, 2013 10:30 am

The only other thing I can think of is a loose connection. Everything you've done seems fine.

Do you have any other I2C devices you could try connecting?

lolouk44
Posts: 25
Joined: Sat Oct 20, 2012 11:01 pm

Re: I2C LCD not detected

Wed Jun 26, 2013 10:32 am

Hi @Joan,

I'm afraid not :(

Any other idea?

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

Re: I2C LCD not detected

Wed Jun 26, 2013 10:52 am

Are there any jumpers? Other Amazon users seems to have had problems getting it to work but that seemed to be an Arduino library problem. It should still be seen on the I2C bus.

lolouk44
Posts: 25
Joined: Sat Oct 20, 2012 11:01 pm

Re: I2C LCD not detected

Wed Jun 26, 2013 11:01 am

Hi @Joan,

Thanks for your continued support.
This is what I can see at the back of the LCD:
Image
Image

I'm thinking of getting a cheap I2C chip to run more I2C tests. Do you think this would work:
http://uk.rs-online.com/web/p/temperatu ... s/7747863/

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

Re: I2C LCD not detected

Wed Jun 26, 2013 11:13 am

That temperature sensor should work.

As a last test I'd switch the SDA/SCL connections on the LCD in case they have been mislabelled.

lolouk44
Posts: 25
Joined: Sat Oct 20, 2012 11:01 pm

Re: I2C LCD not detected

Wed Jun 26, 2013 11:42 am

Thanks.
Let's hope I find out what's wrong....

azerty
Posts: 10
Joined: Thu Jun 07, 2012 4:06 am

Re: I2C LCD not detected

Wed Jun 26, 2013 8:45 pm

It could be a logic threshold issue. I2C to LCD typically uses a PCF8574 or similar. With VCC = 5V, logic high is 0.7*VCC = 3.5V which is higher than the Pi's 3.3V I2C bus. You can try powering VCC from 3.3V, if i2cdetect picks up the I2C LCD then that's likely the problem. Unfortunately, many LCDs require a 5V supply even though they accept 3.3V logic inputs, so even if you can detect the device with VCC = 3.3V the display may not turn on.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12409
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: I2C LCD not detected

Wed Jun 26, 2013 10:35 pm

you could try using an I2C bidirectional level shifter, which consist actually simply of two fets and two extra pullups. like this one from sparkfun: https://www.sparkfun.com/products/8745

this is the schematic, (open in new window for full size). The resistor dividers are not needed/useable in the I2C application.

Image

Adafruit also sells level shifters like this, as do many others, Its quite common.

lolouk44
Posts: 25
Joined: Sat Oct 20, 2012 11:01 pm

Re: I2C LCD not detected

Wed Jun 26, 2013 10:53 pm

@Azerty you're the best !
Powering VCC from 3.3V makes it work. I would have never found this out (the docs clearly states +5V).
It's too late for tonight, but already I can't wait to get started.

Thank you so much :D

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

Re: I2C LCD not detected

Thu Jun 27, 2013 7:49 am

lolouk44 wrote:@Azerty you're the best !
Powering VCC from 3.3V makes it work. I would have never found this out (the docs clearly states +5V).
It's too late for tonight, but already I can't wait to get started.

Thank you so much :D
That's something to try and remember. Not a problem for Arduino devices as their logic 1 is +5V.

lolouk44
Posts: 25
Joined: Sat Oct 20, 2012 11:01 pm

Re: I2C LCD not detected

Sat Jun 29, 2013 3:07 pm

Hi @Azerty,

Guess I spoke too soon :(
The LCD is detected at address 0x3F as expected, however whenever I try to drive anything to it I get either nothing or it simply flashes :(

@mahjongg,
Do you reckon I do indeed need I2C bidirectional level shifter as per your suggestion? If so can you advise how I should connect it between the RPi and the LCD?

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

Re: I2C LCD not detected

Sat Jun 29, 2013 3:13 pm

I wonder if there is a way of dropping the 5V to something like 4.5V. The LCD may still work and 0.7*4.5 = 3.15 may be small enough for a gpio to still show an I2C logic 1.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12409
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: I2C LCD not detected

Sat Jun 29, 2013 3:29 pm

joan wrote:I wonder if there is a way of dropping the 5V to something like 4.5V. The LCD may still work and 0.7*4.5 = 3.15 may be small enough for a gpio to still show an I2C logic 1.
yes, simply connect a diode (1n4148) in series, with the 5V supply to the display, (cathode on the display side) the diode will drop 0.6V so the display get 4.4V.

are you sure the problem is hardware?

If the I2C device is detected, in principle I2C communication should work.

perhaps you are driving the display wrong!

if there is some other thing you can control, like turning backlight on/off, does that work?

How does the I2C driver work, or rather what chip is used? a simple I/O expander, or a microcontroller (PIC?).

lolouk44
Posts: 25
Joined: Sat Oct 20, 2012 11:01 pm

Re: I2C LCD not detected

Sat Jun 29, 2013 4:02 pm

Hi Joan, mahjongg,

The diode option doesn't work, the LCD is not recognised.
I guess I need the logic converter...
Would I just need to bring the +3.3v of the RPi to the input and +5V output to the SDA / SCL of the LCD?

lolouk44
Posts: 25
Joined: Sat Oct 20, 2012 11:01 pm

Re: I2C LCD not detected

Sat Jun 29, 2013 4:05 pm

Guess I replied too quickly.
I tried to use Adafruit's modified LCD Charplate script. (see http://crumpspot.blogspot.co.uk/2013/05 ... 23017.html)
I set up the correct address (0x3F) and bus (0).
The screen seems to flash and show a random flashing cursor... I'm not sure at this stage if the issue is hardware (+3.3V Vs +5V) or software. Haven't managed to reach that far...

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12409
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: I2C LCD not detected

Sat Jun 29, 2013 4:13 pm

does your device really use the MPC23017 I/O expander? Is that what it says on the chip?

If so you could simply try if you can set individual outputs high and low, by using the MCP23017 to set pins low and high, and check with a multimeter if they do go high and low.

If one output controls the backlight, you can check if the I/O expander works by trying to turn on/off the brightness. If this works reliably the hardware is probably OK, and it might be a driver issue.

if you cannot control the MCP23017 reliably it might still be a level problem, and you might need to use a level shifter like this:
Image

MCP23017 devices have proven to work reliably with a PI when powered with 3,3V, but as they need a logic high of 0.8 times their power supply, that means they need 4V for their logic high when powered with 5V! So a 3,3V level is insufficient.

so yes, you need level shifters if the device uses a MCP23017 on 5V!

in principle most of these LCD modules can be controlled with 3,3V levels, as they are designed so that they will accept a 2,0V level as high. That is why directly connecting them to the GPIO's of a PI works fine.

So a solution could be to power the I/O expander board with 3,3V, but the LCD module with 5V. I'm not sure how that would work out with the background led driving though. If the board also powers the background LED's they could become very dim with 3,3V supply.

the simplest solution would still be the level shifter. Most board would have (10K) pullups on both sides, and the PI already has 1K8 pullups on its side, but connecting extra 10K pullups wouldn't be a problem.

If you have the parts (suitable fets and 10K pullups) you could also use discrete parts, or you could buy one of the pre-made boards for a dollar or two.

lolouk44
Posts: 25
Joined: Sat Oct 20, 2012 11:01 pm

Re: I2C LCD not detected

Mon Jul 01, 2013 4:16 pm

Hi Mahjongg,

Having done a quick search (I'm at work now) the LCD seems to have a HD44780 instead of MPC23017, so I guess that explains why it's not working well ! (D'oh)

I need to study Sainsmart's solution and create my own RPi libraries I guess :(
(http://www.sainsmart.com/sainsmart-iic- ... ga-r3.html)

Being an amateur (nob) It's likely to take longer than I wanted / have free time for...
Ah well I guess it's part of the fun :!:

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12409
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: I2C LCD not detected

Mon Jul 01, 2013 8:44 pm

errr... no! Almost all LCD's of this type use a HD44780 LCD (compatible) controller, its not the chip I'm talking about.
So its not a software problem, like you seem to assume.
I am talking about the small add on board that accepts an I2C signal, and converts it into control signals for the LCD.

That small add on board is designed to work with an arduino, a board with a chip that uses 5V control signals, the PI uses a chip that uses 3V3 signals. The MPC23017 I/O expander on that small add on board can work with both 3,3V and with 5V levels, but in this case its powered with 5V, and thus also expect 5V compatible control signals!

It's designed to make "life easier" for Arduino users (less wires that can go wrong), but if you try to use it with a PI its not designed for that, and makes live more difficult.

Its completely possible to design such a board (even one with a MCP23017) to work with a PI, but in that case the MCP23017 must be fed with 3,3V, not with 5V!

Unfortunately in this MCP23017 based board the power supply probably also used to control, and/or feed, the backlight LED's. And lowering the LED voltage from 5V to 3,3V will probably make the LED's extremely dim! But if you feed the small add on board with 3V3 instead of 5V, controlling the MC23017 from a PI will probably start to work!
But the LCD module itself is still a 5V device, even though it can be reliably controlled with 3V3 control signals!
so for this setup to work the LCD module (and its backlight LED's) must be 5V powered while the small adapter board with the MCP23017 must be 3,3V powered. That of the whole thing must be 5V powered and considered a "5V I2C device", and the I2C levels between the PI and the whole LCD contraption must be level-converted with 3V3 levels on the PI side, and 5V on the "display side".

conclusion:
you cannot (always) use an I2C controlled device designed for an arduino with a PI unchanged. either the device must be able to run on 3V3, or it's I2C interface must be compatible with 3V3 logic levels, or you need to use a I2C level converter, (as described) to convert 3V3 I2C signals to 5V I2C signals.

lolouk44
Posts: 25
Joined: Sat Oct 20, 2012 11:01 pm

Re: I2C LCD not detected

Tue Jul 30, 2013 6:32 am

I've been busy and unable to spend as much time as I wanted, but wanted to confirm and close this thread:
I've got it all working powered via +3.3V. The screen is not as bright as if powered by +5V I guess but it's bright enough that it can be seen day or night

I've reused the code from @Nabett on this thread: http://www.raspberrypi.org/phpBB3/viewt ... 1&p=391390

Thanks all for your help.

rainierez
Posts: 7
Joined: Wed Apr 03, 2013 7:29 pm

Re: I2C LCD not detected

Thu Aug 01, 2013 1:18 am

mahjongg wrote:conclusion:
you cannot (always) use an I2C controlled device designed for an arduino with a PI unchanged. either the device must be able to run on 3V3, or it's I2C interface must be compatible with 3V3 logic levels, or you need to use a I2C level converter, (as described) to convert 3V3 I2C signals to 5V I2C signals.
Your assumption here is incorrect. Now I don't have that lcd he is using but after looking at it the setup is nearly identical to mine. (I wrote the library he is using) I have 5v powering both the lcd and the mcp I then have the sda and scl connected directly to the pi and have had no issues with the logic level issues. Not only that the mcp data sheet mentions this as a possible configuration.

Lolouk, Are you making sure you're sharing the ground between the pi and the display and sub board? PM and maybe I can take a look with you if you're still having issues.

lolouk44
Posts: 25
Joined: Sat Oct 20, 2012 11:01 pm

Re: I2C LCD not detected

Thu Aug 01, 2013 6:47 am

Hi rainierez,

Everything works fine when powered with +3.3V (when powering with +5V the LCD is not recognised.
I've been using the LCD for just a couple of weeks now and the only issue I still get is that sometimes the data will become scrambled on the LCD. would the same script be called simultaneously (or in very quick succession) send too much data at the same time on the I2C and therefore confuse the LCD?
If so, do you have a suggestion on how to manage data sent / received via I2C as I'm planning on adding more I2C devices.

I'm currently looking for a cheap temperature sensor with +-1ºC accuracy and a resolution of 0.1ºC for general purpose (so -20ºC to +50ºC should be enough). Any advice on this would be appreciated. (I have a DHT22 already but I find it unreliable)

rainierez
Posts: 7
Joined: Wed Apr 03, 2013 7:29 pm

Re: I2C LCD not detected

Thu Aug 01, 2013 5:33 pm

lolouk44 wrote:Hi rainierez,

Everything works fine when powered with +3.3V (when powering with +5V the LCD is not recognised.
I've been using the LCD for just a couple of weeks now and the only issue I still get is that sometimes the data will become scrambled on the LCD. would the same script be called simultaneously (or in very quick succession) send too much data at the same time on the I2C and therefore confuse the LCD?
If so, do you have a suggestion on how to manage data sent / received via I2C as I'm planning on adding more I2C devices.

I'm currently looking for a cheap temperature sensor with +-1ºC accuracy and a resolution of 0.1ºC for general purpose (so -20ºC to +50ºC should be enough). Any advice on this would be appreciated. (I have a DHT22 already but I find it unreliable)
I think there is still maybe something strange about that sub board. You should be able to get it working powered by 5v as long as you share the ground with the Pi. Anywhoooo if you have it working at 3.3 that's just fine. Now as for things getting scrambled, Yeah I would say minimizing your update times is a good idea. maybe add a screen clear between updates? I could test speeds to get a better idea on when things get crazy but yeah I have seen that too when moving a word to make it appear to scroll. If I do it to fast it gets messed up some times.

as for the temp sensor... You won't find a better digital one (that is cost effective). I have a few good analog ones I've used from time to time but the DHT22 would be best on the pi. keep in mind it is slow like 2-4 seconds delayed and takes a while to respond. So maybe only poll it once ever 5 seconds. But if you really need that kind of resolution I say get an analog sensor of some type or setup a thermocouple then use an SPI ADC. I2C is probably too slow if you intend to poll it constantly.

Return to “General discussion”