LCD_I2C problem

The LCD_I2C display will only print the first character.
Here is my code:

#include <LiquidCrystal_I2C.h>

#include <Wire.h>

LiquidCrystal_I2C lcd (0x27,20,4);

void setup() {
  lcd.init();
  lcd.backlight();
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Hi");
}

void loop() {
}

The lcd.print function is only printing the first letter, no matter what I try to print, or no matter what cursor`setting. I purchased two boards ( SunFounder IIC I2C TWI Serial 2004 20x4 LCD Module Shield Compatible with Arduino R3 Mega2560 on Amazon) and they both have the same problem. This is proven code, running on a proven nano. Would appreciate some help.

Which are you using, Nano or Mega?

If it's a Mega, are you using 20 (SDA) and 21 (SCL) ?

And, as always, show your wiring.

This is a known library issue.
There are many different "LiquidCrystal_I2C" libraries out there.
Not sure where you got the library you have but, you are using a library that appears to have this known issue.
It is a silent hidden bug that existed for years but didn't show up until the Print class was changed a few years ago.
It will only print the first character of a string and will drop all the rest.

You can try removing the library and installing the one from the IDE library manager. I think that one has this issue fixed.
But that library is no longer maintained.

I would recommend that you switch to the hd44780 library and use the hd4478_I2Cexp i/o class.
It is available in the IDE library manager, and is actively maintained - by me.

--- bill

1 Like

Being Ok on a Nano but not a Mega?
"This is proven code, running on a proven nano."

The outputting of only a single character library bug will exist on any/all boards. It is a bug in the LiquidCrystal_I2C library code. It is not board specific.

I assumed that the "proven code" comment was about the sketch code shown not the library code.
i.e. this sketch code was built by someone else and worked on their nano.

@model14 can you clarify what you meant by:
"This is proven code, running on a proven nano."
and where you got your LiquidCrystal_I2C library code.

--- bill


One additional comment that is unrelated to this "only one character" issue,
I just noticed in the sketch code that <Wire.h> is being included after <LiquidCrystal_I2C.h> it should be before <LiquidCrystal_I2C.h>

The reason the code is still compiling because this version of LiquidCrystal_I2C library is already including <Wire.h> in <LiquidCrystal_I2C.h>

Since <LiquidCrystal_I2C.h> is already including <Wire.h> the include of <Wire.h> by the sketch code is effectively being ignored since it is not being used due to the conditional guards in <Wire.h> which technically means that for this version of the LiquidCrystal_I2C library the include for <Wire.h> could be removed.

That said, since older versions of the IDE, are not smart enough to see library dependencies in library header files it safer to include the library header files since the include in the sketch is necessary on older IDE versions.
So while for this combination of IDE and LiquidCrystal_I2C library the <Wire.h> include in the sketch could be eliminated, it is safer to go ahead and include int, but to be correct, it should be included before <LiquidCrystal_I2C.h> not after.

--- bill

1 Like

What I meant by "proven" is that the nano I am using has been in use for many previous projects (so I know it works properly), and the code I posted is from a youTube video which shows the results as being satisfactory. That having been said, I followed your suggestion to use the hd44780 library and used the hd4478_I2Cexp i/o class. Here is the code from the library example. Unfortunately, I now get an "error compiling for board Arduino nano" error. This whole business has been so frustrating!

#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h> // include i/o class header

hd44780_I2Cexp lcd; // declare lcd object: auto locate & config display for hd44780 chip

void setup()
{
  // initialize LCD with number of columns and rows:
  lcd.begin(20, 4);

  // Print a message to the LCD
  lcd.print("Hello, World!");
}

void loop()
{
  lcd.setCursor(0, 1);
  lcd.print(millis() / 1000);
  delay(1000);
}

Heers hoping yo8u can help. 

Posted code compiles for me and works on my Uno with 2004 LCD.

Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.

Ok so that clears up that the issue you are seeing is the known "single character" issue in the LiquidCrystal_I2C library.
i.e. you didn't actually build the example code with the installed LiquidCrystal_I2C library and have it working on a nano board.

I think it will be good to focus on getting the hd44780 library up and going.
My suggestion, which is also stated in the hd44780 library documentation,
start with the included example diagnostic sketch: I2CexpDiag
This is useful to test the type of device you are using to ensure that everything is working properly.

If you have any compile issues with that example,
Please, as @groundFungus suggested, post the error messages you are getting.

--- bill

Here is the error message:`

Arduino: 1.8.19 (Windows 10), Board: "Arduino Nano, ATmega328P"

In file included from C:\Users\richa\Desktop\LCD\LCD.ino:5:0:

C:\Users\richa\Documents\Arduino\libraries\UncleRus\src/hd44780.h:46:10: fatal error: driver/gpio.h: No such file or directory

 #include <driver/gpio.h>

          ^~~~~~~~~~~~~~~

compilation terminated.

exit status 1

Error compiling for board Arduino Nano.



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

I have no clue what this means.

That does NOT look like a proper installation. I would expect the IDE Library Manager to put it in

C:\Users\richa\Documents\Arduino\libraries\hd44780/hd44780.h

For example. This is where my file is on my PC.

C:\Users\David Prentice\Documents\Arduino\libraries\hd44780\hd44780.h

Regarding verbose errors.

File->Preferences->Show verbose output during: compilation = YES

How do I delete libraries associated with LCD's so I can start all over with a new installation of hd44780? I have three different libraries installed in my IDE.

Depends on the IDE version; later versions have a delete/remove library option.


Google arduino delete library

No clue what that UncleRus library is.
It appears that you have not installed the hd44780 library.
Install the hd44780 library; that is the library you need.
Use the IDE library manager. Search for it and then let the IDE do download and install for you.
Do not attempt to installed it using a zip file.
Installs from github zip files will not be installed properly. This is stated in the Installation sections of the documentation on the github page.

You won't need to uninstall that other library.
The IDE will give priority to using the hd44780.h header from the hd44780 library based on the directory the hd44780 library will be installed in so it will use the hd44780 library instead of the UncleRus library.

--- bill

I removed the UncleRus library file. I searched for, and was unable to find the hd44780 library file, although the Library Manager says it is installed. When i try to compile the example "Hello World" program from the hd44780 example I get the following error file:

Arduino: 1.8.19 (Windows 10), Board: "Arduino Nano, ATmega328P"

LCD:5:10: fatal error: hd44780.h: No such file or directory

 #include <hd44780.h>

          ^~~~~~~~~~~

compilation terminated.

exit status 1

hd44780.h: No such file or directory

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

Here is the verbose output:

Arduino: 1.8.19 (Windows 10), Board: "Arduino Nano, ATmega328P"

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\richa\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\richa\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\richa\Documents\Arduino\libraries -fqbn=arduino:avr:nano:cpu=atmega328 -vid-pid=1A86_7523 -ide-version=10819 -build-path C:\Users\richa\AppData\Local\Temp\arduino_build_657632 -warnings=none -build-cache C:\Users\richa\AppData\Local\Temp\arduino_cache_286961 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Users\richa\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Users\richa\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.arduinoOTA.path=C:\Users\richa\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Users\richa\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.avrdude.path=C:\Users\richa\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Users\richa\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -verbose C:\Users\richa\Desktop\LCD\LCD.ino

C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\richa\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\richa\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\richa\Documents\Arduino\libraries -fqbn=arduino:avr:nano:cpu=atmega328 -vid-pid=1A86_7523 -ide-version=10819 -build-path C:\Users\richa\AppData\Local\Temp\arduino_build_657632 -warnings=none -build-cache C:\Users\richa\AppData\Local\Temp\arduino_cache_286961 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Users\richa\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Users\richa\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.arduinoOTA.path=C:\Users\richa\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Users\richa\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.avrdude.path=C:\Users\richa\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Users\richa\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -verbose C:\Users\richa\Desktop\LCD\LCD.ino

Using board 'nano' from platform in folder: C:\Users\richa\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4

Using core 'arduino' from platform in folder: C:\Users\richa\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4

Detecting libraries used...

"C:\\Users\\richa\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR "-IC:\\Users\\richa\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.4\\cores\\arduino" "-IC:\\Users\\richa\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.4\\variants\\eightanaloginputs" "C:\\Users\\richa\\AppData\\Local\\Temp\\arduino_build_657632\\sketch\\LCD.ino.cpp" -o nul

Alternatives for Wire.h: [Wire@1.0]

ResolveLibrary(Wire.h)

  -> candidates: [Wire@1.0]

"C:\\Users\\richa\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR "-IC:\\Users\\richa\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.4\\cores\\arduino" "-IC:\\Users\\richa\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.4\\variants\\eightanaloginputs" "-IC:\\Users\\richa\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.4\\libraries\\Wire\\src" "C:\\Users\\richa\\AppData\\Local\\Temp\\arduino_build_657632\\sketch\\LCD.ino.cpp" -o nul

Alternatives for hd44780.h: []

ResolveLibrary(hd44780.h)

  -> candidates: []or: hd44780.h: No such file or directory



 #include <hd44780.h>

          ^~~~~~~~~~~

compilation terminated.

Using library Wire at version 1.0 in folder: C:\Users\richa\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4\libraries\Wire 

exit status 1

hd44780.h: No such file or directory

Like I said, the Library Manager says the Library is installed, but I can't find it !

I am sure this is testing your patience, as it is mine. Thanks for the help.

One for you Bill! :face_with_raised_eyebrow: :grin:

I see the build error and it indicates that the IDE is unable to locate the hd44780 library - which means the library is not installed or not installed in the proper location.

You are saying that you used the IDE Library manager, used the search function in the library manager to locate the hd44780 library from the available libraries that can be installed (there is only 1 library named "hd44780"), and then told the IDE to install the hd44780 library and now the IDE library manager says the library is installed, but you now can't find the library?

If the IDE library manager does the install from its list of known libraries, there should not be any build issues as the library manager and the builder tool should be using the same directory for libraries libraries.

I asked you to build a specific hd44780_I2Cexp i/o class sketch that came from the library: I2CexpDiag
It is the first sketch that should be run. This is indicated in the hd44780 library documentation.
See the wiki: ioClass: hd44780_I2Cexp · duinoWitchery/hd44780 Wiki · GitHub
If the IDE doesn't see the hd44780 library and its examples:
i.e. [File]->Examples->hd44780 is not there
Then the hd44780 library is not installed properly.

I think that there is more to this story than you have told us.

The 1.x library manager is very simplistic. It does not have any cache, database, or config files for tracking user installed libraries.
It simply looks in the sketchbook/libraries directory to "see" what libraries are installed. This is the same place the IDE arduino builder tool looks.
This location can be re-configured in the IDE using preferences, but that directory location preference is used by both the library manager and the build tool.

I would like to see a screen capture of the IDE library manager indicating that the hd44780 library is installed.

And what was up with installing the UncleRus library?
That library does not appear to be for the AVR platform core.

--- bill

Bill,
Please forgive me for wasting your time. Previously hen I searched for "hd44780" in the library manager, I installed the first library item that came up (named LiquidCrystal)! I didn't realize that the LM search function pulled up matches from within the file description, not the header name. So, I wasn't using your library file. Dumb, stupid. After your last post I scrolled down and found the correct item named "hd44780".
I hope you don't refuse me help in the future. The LCD's now work fine. Thank you.

Tick :white_check_mark: a solution and give some love :heart:

No problem. Don't beat yourself up over it. We've all been there.
And the IDE library manager does have some odd behaviors.
So no worries.

I assume the hd44780 library hd44780_I2Cexp i/o class is working for you.
If you have any other questions or issues, just post followup questions.

--- bill