LiquidCrystal Display using I2C

I have connected a I2C display to an Arduino board and ran a scanner program which comes back with the address 0x27. When I include LiquidCrystal_I2C and add the lines for initializing the display, the file will not compile.

When you encounter an error you'll see a button on the right side of the orange bar "Copy error messages". Click that button. Paste the error in a message here USING CODE TAGS (</> button on the toolbar).

When your code requires a library that's not included with the Arduino IDE please always post a link(using the chain link icon on the toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger(Sketch > Include Library > Manage Libraries) then say so and state the full name of the library.

Arduino: 1.8.3 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\rsmit\Documents\Arduino\HelloWorld\HelloWorld.ino:5:31: fatal error: LiquidCrystal_I2C.h: No such file or directory

#include <LiquidCrystal_I2C.h>

^

compilation terminated.

exit status 1
Error compiling for board Arduino/Genuino Uno.

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

You forgot the code tags...

You need to install the library that has the file LiquidCrystal_I2C.h. There are multiple libraries that have a file of that name so I can't tell you which you need to install. Please post a link to where you found this HelloWorld sketch. Always use the chain links icon on the toolbar to make the URL clickable when you post links.

Arduino: 1.8.3 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\rsmit\Documents\Arduino\HelloWorld\HelloWorld.ino: In function 'void setup()':

HelloWorld:15: error: expected unqualified-id before '.' token

LiquidCrystal_I2C.begin();

^

HelloWorld:18: error: expected unqualified-id before '.' token

LiquidCrystal_I2C.backlight();

^

HelloWorld:19: error: expected unqualified-id before '.' token

LiquidCrystal_I2C.print("Hello, world!");

^

exit status 1
expected unqualified-id before '.' token

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

And still no code tags, and still you haven't answered my question.

Using code tags and other important information is explained in the How to use this forum post. Please read it.

This is not the actual LiquidCrystal_I2C.h library you can find using the manager, so...

you either post your whole code or you either tell us exactly how you got that example. There is no other way.

The easiest way to solve such problem is to use the actual Helloworld from the actual LiquidCrystal_I2C.h library from the manager.

Ps: this is the "Display" subforum, while your problem is all about the IDE. You are not asking in the right place.

#include <LiquidCrystal_I2C.h>
#include <Wire.h>

// Set the LiquidCrystal address to 0x27 for a 20 chars and 4 line display
// LiquidCrystal_I2C(uint8_t lcd_Addr,uint8_t lcd_cols,uint8_t lcd_rows);
   LiquidCrystal_I2C Lcd(0x27, 20, 4);

void setup()
{
  Wire.begin;
  
	// initialize the LiquidCrystal_I2C
	LiquidCrystal_I2C begin();

	// Turn on the blacklight and print a message.
	LiquidCrystal_I2C backlight();
	LiquidCrystal_I2C print("Hello, world!");
}

void loop()
{

LiquidCrystal I2C by Frank de Brabander 1.1.2

Compare your code to the code in the examples included with the library like the HelloWorld example.
When you do, you should see what you have done wrong in your code.

--- bill

That is not the Hello World example from Frank de Brabander. The code you posted will never run nor compile.

This is the Hello World example from Frank de Brabander (as you can see, it's quite different and actually compiles, and runs etc etc).

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup()
{
 // initialize the LCD
 lcd.begin();

 // Turn on the blacklight and print a message.
 lcd.backlight();
 lcd.print("Hello, world!");
}

void loop()
{
 // Do nothing here...
}

I don't know where you found that example, but it looks like someone deliberately messed up the whole syntax (hoping it wasn't you. If it was you... just don't).

Btw, you can find a very similar library and a very similar examples in the manager. No need to surf the net searching.

Nicola_Fu,
While it appears that rsmith7837 wonked up his code using improper syntax, the example code you provided doesn't look like the HelloWorld from any of the Frank de Brabander LiquidCrystal_I2C libraries and their derivatives I've seen.
All the ones I've seen use init() rather than begin(cols, rows), including the one in the IDE library manager.
The init() function calls Wire.begin() which initializes the i2c library, whereas begin(cols, rows) does not.

In fact, some versions of the LiquidCrystal_I2C library don't even have a begin() function.

And therein lies the problem, there are many different libraries that all have a header file named LiquidCrystal_I2C.h and because of their differences the sketch code must be modified to work with the specific library.

They are not all the same. The lcd objects are declared in different ways and they are initialized differently, work differently and provide slightly different API functions.
They are also not installed the same way and some require modifying your IDE bundled LiquidCrystal library.

Not only that but then there is the issue of pin mappings.
(how the PCF8574 is wired up to the hd44780 lcd signals)
This is an issue because not i2c lcd backpacks connect the pcf8574 output pins to the hd44780 signals the same way.
Most of LiquidCrystal_I2C.h "libraries" (including the one in the IDE library manager) hard code the pin mappings. Some like Fm's new LiquidCrystal library have the ability to configure pin mappings using the lcd object constructor.

If the pin mappings used by the library don't exactly match the specific pin mappings used on the i2c lcd backpack it will not work. The code will compile and run but the display will not work.


I created the hd44780 library to avoid all this mess and provide a much simpler and easier to use solution.
I would recommend switching to this library.
hd44780 can be quickly and easily installed using the IDE library manager.
hd44780 can automatically locate the i2c backpack address, and self configure the pin mappings and backlight control.
It is also faster than the LiquidCrystal_I2C libraries.
You can read more about it here: https://github.com/duinoWitchery/hd44780
The github page includes information about the library and how to install it.
Use the IDE library manager to install it vs trying to install it manually or using a zip install.
The IDE library manager is easier, faster, and ensures that it is properly installed.

The i/o class for i2c backpacks that use a PCF8574 i/o expander is hd44780_I2Cexp
It includes a diagnostic sketch (I2CexpDiag) that will test the i2c signals and test the internal RAM of the LCD module to verify that the library is able to communicate with the LCD module.

I would recommend running the diagnostic sketch first.
The library also includes several example hd44780_I2Cexp i/o class sketches.
You can look at the HelloWorld code to see what header files to include and how to declare the lcd object.
Other than the header files and the lcd object declaration, the library is fully LiquidCrystal library compatible.
So if you have any LiquidCrystal sketches you can simply modify the includes and the lcd declaration and none of the actual code in your sketch will need to be modified.

hd44780 also has some additional API functions over LiquidCrystal, you can see a summary of them on the hd44780 github page.

--- bill

@ bill

This is the actual example from Frank de Brabander library. What I've done its nothing but a copy&paste from Frank's Github

It was updated last march so it's quite recent.

Btw, my intention was to post the correct version of what rsmith7837 posted, not the "most beautiful Helloworld there is".

Here's the example in question:

This is a great example why the "LiquidCrystal_I2C" library is so problematic.
Here is a link to the github repository to the "LiquidCrystal_I2C" library you get when you use the IDE library manager: GitHub - johnrickman/LiquidCrystal_I2C: LiquidCrystal Arduino library for the DFRobot I2C LCD displays
The library.properties file says the original author was Frank de Brabander
It is probably a version of the library that Marco found somewhere, committed, and then made it available to the IDE library manager.

Marco's version of library (the one available through the IDE library manager), like all the other versions of LiquidCrystal_I2C I had seen so far, requires calling init()
While it has a begin(cols, rows) function, if you only call that instead, the Wire library will not be initialized.

And here is the HelloWorld that comes with that library:

It is not a particularly good example as it has two calls to init() and doesn't have enough comments to explain things.

And there are many other versions of the LiquidCrystal_I2C library floating around out there that are on peoples private sites, blogs, and LCD vendor sites that also have their own various idiosyncrasies.

These libraries will vary in how you declare the LCD object, how to initialize the library and what API functions are included and available in the library.

And this demonstrates the problem with trying to use the "LiquidCrytsal_I2C" library; There isn't just one:
so you never know quite what you have and how to use it unless you go in and read the code as there are so many critical differences that requires using library specific code.
So code examples for the "LiquidCrystal_I2C" library that people may find somewhere may or may not work with the particular "LiquidCrystal_I2C" library that they have installed.
This is awful for newbies and less technical users.

My hd44780 library provides a much more complete and LiquidCrystal consistent API as it contains nearly all the API functions from both LiquidCrystal and the LCD API 1.0 specification.
And it does it in a way that provides a consistent set of API functions regardless of the h/w interface used to communicate with the LCD which ensures that the mainline sketch code does not have to change when using a different interface. (Just change the header files and the lcd object declaration)
The only functions not provided are init() and keypad()
init() is not provided for two reasons, 1) it really isn't necessary, 2) the init() function in LiquidCrystal is h/w specific and I want to ensure that hd44780 provides API functions that work the same way on all h/w interfaces.

keypad() is not provided as it is h/w specific, unrelated to the the LCD and therefore does not belong in an LCD API library.

hd44780 will also emit warnings and/or errors at compile time when users attempt to use certain functions that are either not supported or have been deprecated.
One of things that this does is that it will prevent users from wondering why their println() calls are not working.
While eventually this will be supported, since it currently is not supported, using println() will get a compile error if sketch code attempts to use it.
All the other LCD libraries will compile when using println() but will not work as expected.

--- bill

I think the version using "begin" is supposed to be easier for beginners, because it uses the same terminology of Liquidcrystal.h from Adafruit.

Nicola_Fu:
I think the version using "begin" is supposed to be easier for beginners, because it uses the same terminology of Liquidcrystal.h from Adafruit.

I think you have missed the point.
There are many different libraries out there called "LiquidCrystal_I2C" and they don't all work the same.
They install differently, initialize differently, and provide different API functions.
This makes installation prone to errors and potentially requires modifying sketch code to make it work.

That is why I recommend using my hd44780 library as it provides a consistent and more complete API which includes all the API functions from LiquidCrystal and the LCD API 1.0 specification.

This means that when using hd44780, you can count on the API working just like the IDE bundled LiquidCrystal library API which means using begin(cols, rows) to do the initialization.

--- bill