What am I doing wrong? LCD with I2C interface

Hello!

I recently bought an Arduino Nano Every and a 16x2 LCD with I2C interface. I set up the board, I installed it in the "Boards Manager", I downloaded the library from here and I installed the library as instructed. I ran a few codes to test the board (Blink) and after I connected the I2C interface I ran I2C Scanner to find the adress.

Everything good until I connected the display and ran the example "HelloWorld" from the LiquidCristalI2C library and got the error:

Arduino: 1.8.12 (Windows 10), Board: "Arduino Nano Every, ATMEGA328"

In file included from C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.cpp:1:0:

C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.h:60:40: error: expected class-name before '{' token

 class LiquidCrystal_I2C : public Print {

                                        ^

C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.cpp: In member function 'virtual size_t LiquidCrystal_I2C::write(uint8_t)':

C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.h:51:12: warning: 'B00000001' is deprecated: use 0b00000001 instead [-Wdeprecated-declarations]

 #define Rs B00000001  // Register select bit

            ^

C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.cpp:207:14: note: in expansion of macro 'Rs'

  send(value, Rs);

              ^~

In file included from C:\Users\vladg\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.6\cores\arduino/api/ArduinoAPI.h:26:0,

                 from C:\Users\vladg\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.6\cores\arduino/Arduino.h:23,

                 from C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.cpp:3:

C:\Users\vladg\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.6\cores\arduino/api/Binary.h:53:3: note: declared here

   B00000001 DEPRECATED(0b00000001) = 1,

   ^~~~~~~~~

In file included from C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.cpp:1:0:

C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.cpp: In member function 'void LiquidCrystal_I2C::pulseEnable(uint8_t)':

C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.h:49:12: warning: 'B00000100' is deprecated: use 0b00000100 instead [-Wdeprecated-declarations]

 #define En B00000100  // Enable bit

            ^

C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.cpp:234:24: note: in expansion of macro 'En'

  expanderWrite(_data | En); // En high

                        ^~

In file included from C:\Users\vladg\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.6\cores\arduino/api/ArduinoAPI.h:26:0,

                 from C:\Users\vladg\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.6\cores\arduino/Arduino.h:23,

                 from C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.cpp:3:

C:\Users\vladg\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.6\cores\arduino/api/Binary.h:73:3: note: declared here

   B00000100 DEPRECATED(0b00000100) = 4,

   ^~~~~~~~~

In file included from C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.cpp:1:0:

C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.h:49:12: warning: 'B00000100' is deprecated: use 0b00000100 instead [-Wdeprecated-declarations]

 #define En B00000100  // Enable bit

            ^

C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.cpp:237:25: note: in expansion of macro 'En'

  expanderWrite(_data & ~En); // En low

                         ^~

In file included from C:\Users\vladg\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.6\cores\arduino/api/ArduinoAPI.h:26:0,

                 from C:\Users\vladg\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.6\cores\arduino/Arduino.h:23,

                 from C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.cpp:3:

C:\Users\vladg\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.6\cores\arduino/api/Binary.h:73:3: note: declared here

   B00000100 DEPRECATED(0b00000100) = 4,

   ^~~~~~~~~

C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.cpp: In member function 'void LiquidCrystal_I2C::printstr(const char*)':

C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.cpp:256:2: error: 'print' was not declared in this scope

  print(c);

  ^~~~~

C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.cpp:256:2: note: suggested alternative: 'printf'

  print(c);

  ^~~~~

  printf

exit status 1
Error compiling for board Arduino Nano Every.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I don't quite understand this error message because it referes to the library which should pe coded properly. What am I doing wrong?

Edit: I've tried using the hd44780 library but for the example "HelloWorld" I get the same error:

Arduino: 1.8.12 (Windows 10), Board: "Arduino Nano Every, ATMEGA328"

In file included from C:\Program Files (x86)\Arduino\libraries\LiquidCrystal\src\LiquidCrystal.cpp:1:0:

C:\Program Files (x86)\Arduino\libraries\LiquidCrystal\src\LiquidCrystal.h:45:36: error: expected class-name before '{' token

 class LiquidCrystal : public Print {

                                    ^

C:\Program Files (x86)\Arduino\libraries\LiquidCrystal\src\LiquidCrystal.h:86:9: error: 'Print' has not been declared

   using Print::write;

         ^~~~~

exit status 1
Error compiling for board Arduino Nano Every.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Use CTRL T to format your code.
Attach your ‘complete’ sketch between code tags, use the </> icon in the posting menu.
[code]Paste your sketch here[/code]

I recently bought an Arduino Nano Every and a 16x2 LCD with I2C interface.
Edit: I've tried using the hd44780 library but for the example "HelloWorld" I get the same error:

You may not be using the hd44780 library correctly. With 1.8.9 compiling for a Nano Every with the AT328 emulation I get no errors with the hello world library example for the i2cexp io class.

hd44780 is the best library to use. If the problem was not the selection of the wrong io class, please post the code and error using that hd44780.h.

cattledog:
You may not be using the hd44780 library correctly. With 1.8.9 compiling for a Nano Every with the AT328 emulation I get no errors with the hello world library example for the i2cexp io class.

Thank you! You made me realize that I wasn't actually using the HD44780 library. I knew it was a dumb question, thank you for answering.

Hello
I have the same error compiling but with a Uno Wifi Rev2 card.

I do'nt realy undestand how you solved your problem

Could you telle me more ?

Many thanks

Well, the thing is that to use the HD44780 library, the code must actually use a "#include" for that library.

If you have installed the library, it includes some examples to try which should work directly.

AC74:
I do'nt realy undestand how you solved your problem

Could you telle me more ?

Hi!

Sure. I manually installed the library from here. I copied the files in the "libraries" folder in the installation folder of the IDE.

Before I realised I was using the wrong library I searched for "hd44780" in the library manager and it said that it was already installed but I couldn't find it so I tought maybe it was installed under a different name (as it says under my username I'm a newbie).

So yes, manual installation worked for me and, as user cattledog says, the examples from i2cexp io class works perfect.

vlad_ptr:
I manually installed the library from here.

Why a manual install?
I would HIGHLY recommend NOT doing that.
The instructions on the github page even recommend using the IDE library manager for all IDEs beyond 1.6.2 and includes step by step instructions of how to do it.

The hd44780 library is available in the IDE library manager. Use the GUI in the IDE to install it.
It is easier and faster than doing it manually.
There are way too many ways to install the library incorrectly,
This includes when importing it using a .zip file created by github.

And even if properly doing a manual install, I would advise putting the library in the user sketchbook area so that it is still available should the IDE be updated.

For the next release, I'm going to update the instructions with a BIG warning against doing manual installations.

--- bill

Thank you for your help, I succeded to install the hd44780 library.

The issue I was facing is like this:

I transfered rather big sketch that worked fine with an Arduino Uno rev3 on a Uno WiFi rev2.
Then I got different problems with the I2C (temperature sensors with Dallas Temperature and LCD HD44780 using LiquidCrystal.
The main issue was a blockage during a LCD writting then the Uno was stopped like in a very long delay().

With the help of the forum, I reduced the use of the LCD then I got no blockage.

A second isssue (but linked) was that it was impossible to compile with the last MegaAVR 1.8.6 , so I continued using 1.8.5 , the compiling message was :

"*** => In file included from C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.cpp:1:0:

C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.h:60:40: error: expected class-name before '{' token

class LiquidCrystal_I2C : public Print {

^ <=**" as described in a recent post (vlad_ptr)

The sketch is working now, with HD44780 lib instead of LiquidCrystal and withst 1.8.6 MegaAVR lib.
I've to wait to confirm.

The bad point is this: HD44780 lib is very heavy , the sketch use 90% instead of 75% of the memory.

Any way to reduce ?

AC74:
The sketch is working now, with HD44780 lib instead of LiquidCrystal and withst 1.8.6 MegaAVR lib.
I've to wait to confirm.

The bad point is this: HD44780 lib is very heavy , the sketch use 90% instead of 75% of the memory.

Can you explain more about what you mean by "memory"?
When I compile a simple "HelloWorld" using the hd44780_I2Cexp i/o class for the MegaAVR board,
I see that the code uses 6782 (13%) of flash and 375 bytes (6%) of SRAM.

Keep in mind that when using the hd44780_I2Cexp i/o class, the Wire library is dragged in, which also adds code and ram usage.

You can compile an empty sketch with a
#include <Wire.h>
to see how much the Wire library uses. (It actually uses a bit more when used by another library or sketch, but it will give you a general idea)

The short answer for reducing resource usage of the hd44780 library is that, currently, there isn't anything that can be done from the sketch that can reduce resource usage.

--- bill

The compilation message is (french)

"Le croquis utilise 43862 octets (90%) de l'espace de stockage de programmes. Le maximum est de 48640 octets.
Les variables globales utilisent 1094 octets (17%) de mémoire dynamique, ce qui laisse 5050 octets pour les variables locales. Le maximum est de 6144 octets."

The sketch uses 90% with HD44780 and 75% with LiquidCrystal.

Attach your sketch file. Then we can see what the problem might be.

David.

AC74:
The compilation message is (french)

"Le croquis utilise 43862 octets (90%) de l'espace de stockage de programmes. Le maximum est de 48640 octets.
Les variables globales utilisent 1094 octets (17%) de mémoire dynamique, ce qui laisse 5050 octets pour les variables locales. Le maximum est de 6144 octets."

The sketch uses 90% with HD44780 and 75% with LiquidCrystal.

So the code using hd44780_I2Cexp is about 7.3k larger vs LiquidCrystal.
Quite a bit of that extra code size is the Wire library.
You can get rough idea by including Wire.h in your LiquidCrystal code
and then somewhere in setup() do:

Wire.begin();
Wire.beginTransmission(8);
Wire.endTransmission();
Wire.requestFrom(8, 1);
Wire.read();

The code won't work, but should compile to get a rough idea how much of the extra code is just the Wire library.

--- bill

After a few days , the code with hd44780_I2C works fine and is accepted by the last Mega AVR Boards 1.8.6

Here attached result of compliation of the code you suggested

It looks like 3600 bytes is just the core Arduino stuff with the Wire library.

Same problem as reported here for the LiquidCrystal library, the megaavr core used for the atmega4809 based boards does not include the Print.h class file. Fix is to replace #include <Print.h> with #include <Arduino.h> in the library header file:

This warning can be ignored, it will still compile correctly, but the B to indicate a binary number has been replaced with 0b as the proper syntax.

C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.h:51:12: warning: 'B00000001' is deprecated: use 0b00000001 instead [-Wdeprecated-declarations]

 #define Rs B00000001  // Register select bit

            ^

david_2018:
Same problem as reported here for the LiquidCrystal library, the megaavr core used for the atmega4809 based boards does not include the Print.h class file. Fix is to replace #include <Print.h> with #include <Arduino.h> in the library header file:

Print.h not included in newer platforms · Issue #33 · arduino-libraries/LiquidCrystal · GitHub

Actually, the real problem is in LiquidCrystal.cpp and LIqudCrystal_I2C.cpp
Both of them included their library header file too soon (before the include for Arduino.h)

#include "LiquidCrystal.h"

#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "Arduino.h"
#include "LiquidCrystal_I2C.h"
#include <inttypes.h>
#if defined(ARDUINO) && ARDUINO >= 100

#include "Arduino.h"

And while it does work, both of them should be including <Arduino.h> not "Arduino.h" as that header is a system header and shouldn't ever come with the library.

It is a bit trickier to fix in LiquidCrystal_I2C.cpp as there is a conditional for the Arduino.h include, but it is still a trivial fix.

--- bill

david_2018:
This warning can be ignored, it will still compile correctly, but the B to indicate a binary number has been replaced with 0b as the proper syntax.

C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.h:51:12: warning: 'B00000001' is deprecated: use 0b00000001 instead [-Wdeprecated-declarations]

#define Rs B00000001  // Register select bit

^

That Bxxxxxxx issue is because Arduino invented all the Bxxxxx symbols and has now decided to remove them
This is a great example of Arduino silliness and why you should always use the C standard stuff (or at least gcc stuff) instead of Arduino proprietary types, functions etc....
I still don't understand why (at least in the past) the early Arduino.cc guys decided to re-invent so many things that already existed in many cases by just using different names.
And when confronted about it, vehemently defended the practice often saying the normal names were too "scary" or confusing.

--- bill

1 Like