Example of 20x4 LCD with I2C that works?

Well, the frustration is reaching the boiling point.

I'd like to find an example of an Arduino sketch (for Arduino UNO) that writes "Hello, world" to a 20x4 LCD display that has an I2C interface to the Arduino.

It'd be nice if you could include where to find the particular LiquidCrystal_I2C.h libraries you used to make it work.

I've also found out the hard way that LiquidCrystal_I2C.h calls for the LCD.h library. Where can I get the one that works with your example?

Sorry for the vague questions. But I keep loading LiquidCrystal_I2C.h files from various places, only to get messages like "candidate expected four arguments, but was provided eight" etc. Clearly there are many different versions of LiquidCrystal_I2C.h around, all with the same name. This might also be true of LCD.h.

It would be nice to start with a set of libraries that definitely work. I can change the wire numbers, no doubt my I2C interface is wired to my Arduino differently from yours.

But if I can just get something that compiles without errors, that would be a HUGE step forward.

Thanx all!

I don't use I2C but,

Have you seen:

Sorry for the vague questions. But I keep loading LiquidCrystal_I2C.h files from various places, . . .

In general you should load the library files from the same place that you get your I2C adapter. The libraries are not interchangeable even though they have the same names.

Have you looked through any of the recent threads with I2C in the title? Don't just look for ones about 20x4 displays, the 16x2 is handled with the same hardware and software.

Don

In general you should load the library files from the same place that you get your I2C adapter. The libraries are not interchangeable even though they have the same names.

Thank you for your reply, floresta.

Yes, just tried that. I got this LCD display (with I2C board installed) from SainSmart (thru Amazon.com).

Just looked at SainSmart's website, the section for this LCD display, its URL is:
http://www.sainsmart.com/sainsmart-iic-i2c-twi-serial-2004-20x4-lcd-module-shield-for-arduino-uno-mega-r3.html

They give links for their code etc. Went to the link and downloaded the latest version of their library.

I found an example of a simple write-to-the-display sketch and compiled it. Naturally, it didn't compile cleanly... but it was close.

The sketch's code is:

#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(20,4,LCD_5x8DOTS);

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

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

....and the error messages look like:

HelloWorld_test_26Mar2016:5: error: invalid conversion from 'int' to 't_backlighPol' [-fpermissive]

 LiquidCrystal_I2C lcd(0x27,16,2);

                                ^

In file included from C:\Users\lilab\HelloWorld_test_26Mar2016\HelloWorld_test_26Mar2016.ino:2:0:

C:\Users\lilab\Documents\Arduino\libraries\NewliquidCrystal/LiquidCrystal_I2C.h:53:4: error:   initializing argument 3 of 'LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t, uint8_t, t_backlighPol)' [-fpermissive]

    LiquidCrystal_I2C (uint8_t lcd_Addr, uint8_t backlighPin, t_backlighPol pol);

    ^

Multiple libraries were found for "LiquidCrystal_I2C.h"
 Used: C:\Users\lilab\Documents\Arduino\libraries\NewliquidCrystal
 Not used: C:\Program Files (x86)\Arduino\libraries\NewliquidCrystal
exit status 1
invalid conversion from 'int' to 't_backlighPol' [-fpermissive]

I don't understand the statement "invalid conversion from 'int' to 't_backlighPol' [-fpermissive]".

Did they define some new data type "t_backlighPol" that isn't compatible with a simple integer? How can I find out what it IS compatible with?

(I tried this code with numbers 0x27, 16 and 2 as it originally came. Also tried it later with 0x3F, 20, and 4 to denote a 20x4 display (which mine was). Same result. I wouldn't think having different numbers like that would cause it to fail during compile time, though perhaps it might fail during run time. But I could never get it to compile in the first place without errors.

I get the feeling that I'm very close to a successful compile now. If I can just straighten out that invalid conversion from 'int' to 't_backlighPol' , hopefully it will compile without error.

Of course, whether it will run correctly on my Arduino is a different matter. But I'll cross that bridge when I come to it.

Well, I assumed this lcd() command did something different with this library, than it did in the sketch I had dug up from another source.

So I changed it to correspond with the error message, changed the address from 0x27 to 0x3f, and now it compiles without error!

When downloaded, the display now lights up, and a flashing cursor appears in the first line, about seven characters from the left. There's no "Hello world" message visible in the display. Press the RESET button, and the flashing cursor is now maybe 15 characters from the left.

Progress!

Still got a ways to go.

Thank you everybody for your help so far!

Present code:

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

// Set the LCD address to 0x27 for a 16 chars and 2 line display
/* Original statement: LiquidCrystal_I2C lcd(0x27,16,2);  */
/* LiquidCrystal_I2C (uint8_t lcd_Addr, uint8_t backlighPin, t_backlighPol pol); */
LiquidCrystal_I2C lcd(0x3F,3,POSITIVE);

void setup()
{
 // initialize the LCD
 lcd.begin(20,4,LCD_5x8DOTS);

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

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

The second paragraph of my reply #2 mentions looking at other recent threads on this topic. If you have done that you surely have seen references to using the 'New LiquidCrystal' library by Francisco Malpartida.

Don

Hello,

But if I can just get something that compiles without errors, that would be a HUGE step forward.

have you check this side ? >> https://arduino-info.wikispaces.com/LCD-Blue-I2C

nielyay:
have you check this side ? >> https://arduino-info.wikispaces.com/LCD-Blue-I2C

To whom are you posting this?

"LilAbner" has not been on this forum for the last 20 months. :astonished:


And ...

The new answer to the OP is to use bperrybap's "HD44780" library, now integrated into the IDE library manager as detailed in this post.

Well, I just took a vacation from Arduino programming for health reasons, and before everything worked fine, tried again, and many things don't work anymore. The I2C LCD libraries are not working, and I have deleted and installed every library for the displays, and nothing works now. To the point that I burned two Arduinos and having tried everything, now I am really disappointed. Anyone can explain very clearly how to install a working library and where to get the best display drivers for LCD I2C ? This has me very sad. I know I had success before, but new versions of Arduino and many libraries is discouraging. I suspect this is a very difficult Arduino issue, when I see that almost every kit for newbies don't include the part. Please help.
WELL, I FINALLY SOLVED! After much verification, almost to become mad, I used a ohmmeter to check the cables and the cables that went to the pins A4 and A5 were open, so, the sketch would never could work. So, put new cables and the LCD is working on I2C. Just to be clear here, we must check even whatever is not logical to us. Simple cables that were open was the cause of almost me becoming mad and abandon Arduino programming.

You should start you own thread.

Hope you are feeling better now.

Did you look at these sites?

https://learn.sparkfun.com/tutorials/installing-an-arduino-library

@PedroVazquezCasta
If you purchase an lcd display with I2C backpack (any brand as far as I could test so far) the easiest way to get it working is to use
bperrybap's library which comes integrated with the latest IDE's.
There are some great features and advantages coming with thsi library as you don't have to care about the I2C address, automatic generation of the correct constructor when the complier starts etc.

Have a look at: GitHub - duinoWitchery/hd44780: Extensible hd44780 LCD library to learn a bit more what the library does for you.

"LilAbner" has not been on this forum for the last 20 months. :astonished:

oah. Sorry i didnt see the date.

Always look at the date! :sunglasses:

Always look at the date!

Sure, Sorry.

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

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address

void setup()
{

lcd.begin(20,4); // initialize the lcd
lcd.clear();
lcd.home (); // go home = lcd.setCursor(0,0);
lcd.print("Hello there!");
lcd.setCurosr(0,1);
lcd.setCurosr(0,1);

And your point is?

Arduino: 1.8.9 (Windows Vista), Board: "Arduino/Genuino Uno"

C:\Users\RADIO\Documents\Arduino\sketch_apr25b\sketch_apr25b.ino: In function 'void setup()':

sketch_apr25b:15:7: error: 'class LiquidCrystal_I2C' has no member named 'setCurosr'

lcd.setCurosr(0,1);

^

sketch_apr25b:16:21: error: expected '}' at end of input

lcd.setCursor(0,1);

^

exit status 1
'class LiquidCrystal_I2C' has no member named 'setCurosr'

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

And again I say - "your point is?"

I don't know what the 2 posts above are for, but I just read through the whole post and tried to figure out how someone else has had the EXACT same problem as me! I lost my LCD code and libraries when my computer fried itself. I recently looked through some old backups of the drive and found the code, which had links to libraries for the I2C! I guess I am not the only one with the problem, here is the code and the library link:
https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads/

liquid_crystal_display.ino (1.02 KB)