LCD I2C and level shifting problems

Hi everyone, recently i've been working on a very important project that includes connecting a I2C LCD display (a common 1602 that uses PCF8574) to an Arduino Nano 33 IoT board. Since the board works at 3.3V and the display works at 5V, i had to use a level shifter for the SDA and SCL lines, and i chose the TXS0108E. Because the board has a arm architecture, i chose the hd44780.h library because i read that it includes that architecture. But i can't manage to print any words on the display, it always show a row of white squares. I've tried connecting the display to 3.3V directly and the display works, but the characters' light is so little that they are almost invisible and that isn't good for my project.
I tried to upload the I2CexpDiag sketch while using the level shifter, and it gives me differents results every time. Sometimes it gives:


Serial Initialized

I2CexpDiag - i2c LCD i/o expander backpack diagnostic tool

hd44780 lib version: 1.1.1

Reported Arduino Revision: 1.8.12
CPU ARCH: arm - F_CPU: 48000000

SDA digital pin: 18 A4
SCL digital pin: 19 A5

Checking for required external I2C pull-up on SDA - YES
Checking for required external I2C pull-up on SCL - YES
Checking for I2C pins shorted together - Not Shorted

Scanning i2c bus for devices..
i2c device found at address 0x27
i2c device found at address 0x60
i2c device found at address 0x6A
Total I2C devices found: 3

Scanning i2c bus for all lcd displays

and it stops here. Some other times it stops earlier, at "Scanning i2c bus for devices.."
Some other times it gives:


Serial Initialized

I2CexpDiag - i2c LCD i/o expander backpack diagnostic tool

hd44780 lib version: 1.1.1

Reported Arduino Revision: 1.8.12
CPU ARCH: arm - F_CPU: 48000000

SDA digital pin: 18 A4
SCL digital pin: 19 A5

Checking for required external I2C pull-up on SDA - STUCK LOW
Checking for required external I2C pull-up on SCL - YES


ERROR: SDA or SCL stuck pin


I2C bus not usable

I don't know if it's a problem with the level shifter or maybe the library doesn't include the Nano 33 IoT board. Please, i really need to solve this in a few days. I really appreciate any kind of help.

The hd44780 library has so far worked on all architectures.
While I have not tested on that specific board, It has been tested on many architectures, including ARM.

It looks like there is an issue with i2c communication.
When running I2CexpDiag, you should first run it with no other devices attached to the bus other than the LCD device.
I.e. start simple and work up to more devices.

I'm guessing that there is some kind of issue with the level shifter or a wiring issue with the i2c signals and/or devices.
Can you show a schematic of how you have things wired up?
and a photo.

I'm not familiar with the level shifter you are using. I don't understand how it works.
It seems to be capable of driving the signals high and low, which is not compatible with an open drain bus like i2c.
I've seen some threads in various forums about people having trouble using this device with i2c.
Some of them are wire issues (lengths of wires/pcb traces) and some are issues related to pullups on the i2c slaves interfering with the logic inside the txs0108e chip.
But overall since I don't fully understand the chip, I don't see how it can work since i2c is open drain and both master can slave can potentially both drive the same signal low at certain times - so there is not a simple/clean "owner" or direction of the signal. This can happen for i2c clock stretching where the slave can hold SCL down to pause the master.

I use the small (8 pin module) / simple 2 channel open drain level shifters that are designed for i2c applications.
They are inexpensive, and simple to hookup and include the required signal pullups on the module.
Just hook up to 5v, gnd, and then connect the two high and two low side signals appropriately.

--- bill

When i ran the I2CexpDiag, the LCD display was the only device attached to the bus. I attached a schematic of my connections.
It really seems that it's an issue with the TXS0108E because i tried to drive with it a TM1637 display that uses a protocol similar to I2C and it doesn't work either. But when i tried to drive a HC SR04 sensor, it worked. So probably that shifter is incompatible with the I2C communication.
Since i have to get this done as soon as possible, can you please send the link of the level shifters you mentioned, or any other level shifter that might work with the LCD I2C display? Or maybe there's a way to make the TXS0108E work with I2C?
Thanks a lot for the help

schema.png

Locate the two 4k7 ("472") resistors on the LCD backpack which connect to SDA and SCL. Remove them with a soldering iron. Connect two new 4k7 resistors from SDA and SCL to your 3.3 V supply. Levels now shifted! :sunglasses:


Usual I2C level converter modules are these (Just buy the module, don't bother trying to assemble it!):

bperrybap:
I use the small (8 pin module) / simple 2 channel open drain level shifters that are designed for i2c applications.

Ten pins!

The ones I like to use are the 2 channel 8 pin modules like this:
https://www.ebay.com/itm/5pcs-2-channel-Bi-Directional-Logic-Level-Shifter-Converter-3-3V-5V-For/322698576638?hash=item4b225582fe:g:zHQAAOSwTDpcCedN

There is also this kind which I have also used: (what Paul showed)

Not as small and a bit different.
The smaller one has a on board 3v regulator with a 3v OUTPUT which can be used to power a slave if it doesn't need much current.
For interfacing a 3v master to 5v slave the it isn't used.

On the 2 channel design, the 3v is an output and the 5v is an input.
On the 4 channel design HV and LV are both inputs.

--- bill

Paul__B:
Locate the two 4k7 ("472") resistors on the LCD backpack which connect to SDA and SCL. Remove them with a soldering iron. Connect two new 4k7 resistors from SDA and SCL to your 3.3 V supply. Levels now shifted! :sunglasses:

The Nano 33 has i2c slaves on the board so there would be no need to connect additional pullups as it should have them on the board.
UPDATE: yes there are 4k pullups to 3v on board
This hack is the quickest way that might get something working.

It is quite likely that it may not be reliable since it is running the 5v slave out of spec by only pulling up the high signals to around 3v.
It might be worth testing to see if it "works" to get something up and going quickly, but I would not want to depend on it.
i.e. it may be an ok stop gap until you can get a proper level shifter.

--- bill

bperrybap:
The ones I like to use are the 2 channel 8 pin modules like this:
https://www.ebay.com/itm/5pcs-2-channel-Bi-Directional-Logic-Level-Shifter-Converter-3-3V-5V-For/322698576638

There is also this kind which I have also used: (what Paul showed)
10PCS IIC I2C Logic Level Converter Bi-Directional Module 5V to 3.3V For Arduino | eBay

Links corrected!

Yes, I found the 8-pin one while you were posting but even the earlier listing is at least twenty times the price of the 4-channel ones on eBay and the extra channels draw no power! It is useful (I have some from when they were cheaper) because the regulator is more capable than the auxiliary 3.3 V from some USB chips on Duemilanove (supposedly "UNO") and Nano clones. I used them to run the RC522 RFID module.

Paul__B:
Links corrected!

Yeah, the text for links looked ugly ,but they worked, at least for me.

Yes, I found the 8-pin one while you were posting but even the earlier listing is at least twenty times the price of the 4-channel ones on eBay and the extra channels draw no power! It is useful (I have some from when they were cheaper) because the regulator is more capable than the auxiliary 3.3 V from some USB chips on Duemilanove (supposedly "UNO") and Nano clones. I used them to run the RC522 RFID module.

Not sure what is going on with the pricing and avialability of the 8 pin modules. I didn't see many sellers selling them but didn't look too hard as the link I provided was just to show the type of module not a specific vendor.
I purchased 10 of the 8 pin modules for $2.64 USD, including shipping, back in June 2019.
I much prefer the 8 pin modules. I prefer the smaller size and they also easily fit on a WeMos shield.

Thanks a lot for the help guys! I hope that replacing the level shifter will solve the problem... I'm planning to buy the 4 channel one (the one that Paul showed), because in the project there is another device that needs to get shifted.

As long as that other "device" is not a NeoPixel/ WS2812 because these level shifters do not work for that!

In the meantime, I believe just exchanging the pull-ups on the backpack for ones to 3.3 V should do the job. While it specifies a 3.5 V HIGH, the PCF8574 is unlikely to be excessively fussy about the 3.3 V levels.

Paul__B:
In the meantime, I believe just exchanging the pull-ups on the backpack for ones to 3.3 V should do the job. While it specifies a 3.5 V HIGH, the PCF8574 is unlikely to be excessively fussy about the 3.3 V levels.

I've done it for some testing with esp8266 modules.
But again, for the nano 33, the 3v pullups are already on the Arduino board, so all that is necessary is to remove the 5v pullups on the backpack.

--- bill

I bought the shifter but the issue is still showing up... It's the same shifter that Paul showed, but it doesn't work... This time i really have no idea how to solve this...

I tried to run I2CexpDiag and this time it gives me always the same output:


Serial Initialized

I2CexpDiag - i2c LCD i/o expander backpack diagnostic tool

hd44780 lib version: 1.1.1

Reported Arduino Revision: 1.8.12
CPU ARCH: arm - F_CPU: 48000000

SDA digital pin: 18 A4
SCL digital pin: 19 A5

Checking for required external I2C pull-up on SDA - YES
Checking for required external I2C pull-up on SCL - YES
Checking for I2C pins shorted together - Not Shorted

Scanning i2c bus for devices..
i2c device found at address 0x5A
i2c device found at address 0x60
i2c device found at address 0x6A
Total I2C devices found: 3

Scanning i2c bus for all lcd displays
No working LCD devices

It seems that it can't find the lcd display. Do you have any idea of what can be the cause?

bperrybap:
Yeah, the text for links looked ugly ,but they worked, at least for me.

They worked, but unnecessarily contained the encoded details of the search that you made.

robecanc:
Scanning i2c bus for devices..
i2c device found at address 0x5A
i2c device found at address 0x60
i2c device found at address 0x6A
Total I2C devices found: 3

Your previous search found 0x27 which should have been the I2C backpack. What other device(s) have you now connected and how?

I think we need a photo or photos according to the unwritten rules: taken in full daylight outside, not in the sun however and not in a dim room. Perfectly focused and with sufficient resolution to show all the detail. :roll_eyes:

I believe those other slave devices are on the Arduino board not external slaves.

The only thing I can think of is that the level shifter is not wired up properly.

Post some photos so we can verify the wiring.

--- bill