LCD HD44780U based, 3,3V, I2C library for Arduino SAMD21 mini

Hello to everyone.
I'm moving my project from arduino nano to arduino zero.
I've problem let's LCD display work, like 16x2 or 20x4 (3.3V, I2c, SDA SCL).
On nano I was using LiquidCrystal I2C.h library(5V supplyLCD) , but this library do not work on Zero.
Is there some other similar library compatible with zero or some other method? (need it work on native SDA SCL ports(D20,D21).

Thanks in advance to everyone

Have you checked out Bill's HD44780 library in the IDE?

The original "LiquidCrystal I2C.h" is essentially, deprecated!

What do you mean by "do not work on Zero" ?
Do you mean that the library does not compile or something else?

If you have a 5v i2c lcd slave device that you want to use with a 3v master, you will need to deal with the voltage differences of the various devices.
This is a h/w issue and cannot be solved by a library.

Typically you would use a level shifter to shift the i2c bus signals between the 3v master on a 3v bus and the 5v slave on a 5v bus.

There is a way to cheat by running a single i2c bus at 3v.
This typically requires modifying the i2c backpack to remove any on board pullups and rewiring new pullups to 3v instead of 5v.
While this typically can work, I prefer to do it correctly and use two i2c busses.
The 3v master on the 3v bus, and the 5v i2c lcd slave on the 5v bus, and using level shifter to connect the two busses.

--- bill

BUMMER.....
I just noticed there is a bug in certain samd variant files that will cause the hd44780 I2CexpDiag sketch to fail to compile.
Any samd board that uses these variants will fail:

  • mkrfox1200
  • mkrgsm1300
  • mkrwan1400
  • mkrzero

This corresponds to these samd board types:

  • Arduino MKR FOX 1200
  • Arduino MKR GSM 1300
  • Arduino MKR WAN 1400
  • Arduino MKRZERO

The variant files is missing the SDA and SCL symbols.
In the other samd files this is handled through const int variables like this:

static const uint8_t SDA = PIN_WIRE_SDA;
static const uint8_t SCL = PIN_WIRE_SCL;

Just after the PIN_WIRE_SDA and PIN_WIRE_SDA defines

I will file a bug for this.

While this won't keep the hd44780 hd44780_I2Cexp i/o class form working, it will prevent the I2CexpDiag sketch from being able to compile.

In the mean time until Arduino releases a new core with this fixed, if you are using any of the affected boards, I would recommend that you go manually patch the variant.h file to add the SDA and SCL constants, as they are needed for certain s/w - like the hd44780 I2CexpDiag sketch.

--- bill

UPDATE:
here is a link to the github issue for this bug:

Thanks a lot to everybody, , I will clarify your advice and and I will let you know of any progress...

Well, I've solved the issue and I want to share the solution.

First of all I checked the variant.h file and it was correct, that is to say that the definition of SDA and SCL were not missing inside the file.

I used the LiquidCrystal_PCF8574.h library, the display is a 20x4 5V LCD.

I then inserted two 330 ohm resistors in series to the SDA SCL buses to make the signals compatible between the 3.3V logic of the Zero and the 5v logic of the LCD (temporary solution because I think it is appropriate to directly use a 3.3V LCD).

Very importantly, I inserted two pull-up resistors (connected to 3.3V) on the SDA and SCL lines before the 330 ohm resistors( that is to say between SDA pin and 3.3v and SCL pin and 3.3v).

I recommend always putting these 4.7K pullup resistors because I noticed that without the program it could work badly.

In particular I noticed that by disconnecting the display (disconnecting it physically I mean) the bluetooth module connected to RX (D0) and TX (D1) no longer worked.

So, evidently, the absence of pullup resistors, until the display was physically connected all worked well, while disconnecting it, the bluetoot no longer worked well and after a while, the program stopped running too.

With pullup resistors, instead, with or without display connected, everything always works well.

Thank you all for the suggestions and I hope this solution can be useful to many.

I asked in post #2, but you never specified what "do not work on Zero" means.
There are many types of issues and failures so just saying it doesn't work does not provide enough information.

When it comes to h/w issues like mismatched voltages and missing pullups, the library used should not be a factor unless it doesn't compile.

Pullups are required.
Many of the Arduino boards do not have the required i2c pullups on them; if the pullups are not added externally, the Wire library will hang.

None of the non AVR based processors I've seen allow turning on the pullups on the SDA and SCL pins when they are in i2c mode. The Wire library on those processors will hang without some sort of external pullups.

Most of AVR based boards don't have pullups on them (Mega2560 boards do); however, the AVR Wire library cheats and turns on the internal pullups on the SDA and SCL pins.
While that can work in many cases, it is not guaranteed to work in all cases since the internal pullups in the AVR are too weak and are way out of spec for i2c pullups.

If you run the I2CexpDiag sketch that is included in the hd44780 library hd44780_I2Cexp i/o class, it will test the i2c signals for missing pullups and for shorts on the SDA and SCL signals.

--- bill

Thank you very much Bill for the clarifications, your help was still basic to solve the problem even if I did not specify whether it compiled or not. This your last interentation has further clarified the reasons and provided additional input.
G.Nicola