Go Down

Topic: (SOLVED) LiquidCrystal_I2C library, Compile error. (Read 53787 times) previous topic - next topic

jack wp

Aug 21, 2013, 05:36 pm Last Edit: Aug 22, 2013, 10:01 pm by jackwp Reason: 1
I just received a LCD using I2C from
http://dx.com/p/funduino-iic-i2c-1602-lcd-adapter-board-w-2-5-lcd-screen-black-green-red-173588
I am using 1.5.2 ide. Board set to Leonardo.
I downloaded the LiquidCrystal_I2C library from
http://arduino-info.wikispaces.com/file/view/LiquidCrystal_I2C2004V1.zip/341635418/LiquidCrystal_I2C2004V1.zip

My code is
Code: [Select]

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

#define I2C_ADDR    0x27
#define BACKLIGHT_PIN     3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

void setup()
{
 // Switch on the backlight
 pinMode ( BACKLIGHT_PIN, OUTPUT );
 digitalWrite ( BACKLIGHT_PIN, HIGH );  
 lcd.begin(16,2);               // initialize the lcd
 lcd.home ();                   // go home
 lcd.print("Hello, ARDUINO ");  
 lcd.setCursor ( 0, 1 );        // go to the next line
 lcd.print (" WORLD!  ");      
}

void loop()
{
}


I get a compile error on the line:
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
Quote
no matching function for call to 'LiquidCrystal_I2C::LiquidCrystal_I2C(int,int,int,int,int,int,int,int)'


Thanks for any advice.

groundFungus

Are you sure that the library is installed properly?  Is that the only error?  Your code is identical to my working LCD code with the exception of the address.

jack wp

I am not sure the library is installed properly, or If I have the most recent library.

I have seen several examples of the line
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

I have seen some that only had the I2C_ADDR,
and I have seen others that added an extra, something after D7_pin such as NEGATIVE. I have tried both these and still got errors on that line.
Can you show me the line you are having success with? (I know the addresses may be different, but how about the count)?

Maybe I should download a different library (from another location), I don't know.

I do have C:\arduino\arduino-1.5.2\libraries\LiquidCrystal_I2C, and I used the the IDE option "Sketch/Import Library" to get the include line into my code.

jack wp

I may have the wrong library. I just found an example inside that library that used
LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display
And it compiled with no errors. I am guessing their comment for 16X2 was not updated when they changed the code..

If I don't have the latest library for LiquidCrystal_I2C, then where should I look for it?

groundFungus

Yeah, I have seen a few versions of the library, too.  To tell the truth I don't remember where I got the library that I use.  It has the same name as yours.  I had some troubles at first and when I found a library that worked I stopped looking.

bperrybap

There are many different i2c to hd44780 lcd libraries out there.
They do not work the same.
They use different constructors, have different capabilities, and have different
ways of initializing using different initialization functions and parameters.
Most of them them use hard coded output pin mappings.
And that makes things even more complex since I2C boards
don't all use the same pin mappings.


My recommendation is to use fm's  library:
https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home
It replaces the LiquidCrystal library that ships with the IDE.
Some sites repost this library but this is the location for the original source.

This library works very well and offers the same capabilities across several interfaces,
including 4 bit parallel, 2 wire shift register, 3 wire shift register, and I2C using a PCF8574.
It is also faster than the others.

This site has some good examples of using fm's library:
http://arduino-info.wikispaces.com/LCD-Blue-I2C

In the near future there will be an update that will add support for the MCP23008
and for using a shift register with only a single Arduino pin.

--- bill


jack wp

I am happy to say, after several hours, I have it working.
My solutions:
1. I am using a Leonardo board, and didn't realize that A4 and A5 don't work on that board (there are dedicated pins near AREF).
2. bperrybap, explained to me that;
Quote
There are many different i2c to hd44780 lcd libraries out there.
They do not work the same.
They use different constructors, have different capabilities, and have different
ways of initializing using different initialization functions and parameters.
Most of them them use hard coded output pin mappings.
And that makes things even more complex since I2C boards
don't all use the same pin mappings.

My recommendation is to use fm's  library:
https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home
It replaces the LiquidCrystal library that ships with the IDE.
Some sites repost this library but this is the location for the original source.

This library works very well and offers the same capabilities across several interfaces,
including 4 bit parallel, 2 wire shift register, 3 wire shift register, and I2C using a PCF8574.
It is also faster than the others.

I downloaded the library suggested.

My init working code is.
Code: [Select]
#include <Wire.h>
#include <FastIO.h>
#include <I2CIO.h>
#include <LCD.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
#include <LiquidCrystal_SR.h>
#include <LiquidCrystal_SR2W.h>
#include <LiquidCrystal_SR3W.h>


#define I2C_ADDR    0x27
#define BACKLIGHT_PIN     3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin,BACKLIGHT_PIN,POSITIVE);

bperrybap


1. I am using a Leonardo board, and didn't realize that A4 and A5 don't work on that board (there are dedicated pins near AREF).


Oh bummer on the i2c pin confusion.
They are still there and available, but not on the same pins.
Atmel moves things around in the internal registers on the different chips which really complicates things
when transitioning to a new chip.

Have a look at these diagrams:
http://forum.arduino.cc/index.php/topic,148308.0.html
You will see that the SDA and SCK signals are now on
digital pins 2 and 3 vs analog pins 4 an 5.
So be careful if you decide to use digital pins 2 and 3 as they
are already being used by your I2C connection.

And here is the Arduino Uno version:
http://forum.arduino.cc/index.php/topic,146315.0.html


--- bill

bperrybap

Just noticed your code example.
You shouldn't have to include all those headers.
For i2c you should only have to include:

Code: [Select]
#include <Wire.h>
#include <LiquidCrystal_I2C.h>


Can't see your setup code but you also will need a

Code: [Select]
    lcd.begin(cols, rows);

in your setup() code.

And the backlight will come on by default.

Maybe post your full working example code
like your first example for those others that may stumble upon this thread later.


--- bill

jack wp

#9
Aug 23, 2013, 01:22 pm Last Edit: Aug 23, 2013, 01:48 pm by jackwp Reason: 1
Here is the full working sketch I am using to test with.
Code: [Select]

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

#define I2C_ADDR    0x27
#define BACKLIGHT_PIN     3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin,BACKLIGHT_PIN,POSITIVE);

int loopCount = 0;

void setup()
{
 // Switch on the backlight
 pinMode ( BACKLIGHT_PIN, OUTPUT );
 digitalWrite ( BACKLIGHT_PIN, HIGH );

 lcd.begin(16,2);               // initialize the lcd

 lcd.home ();                   // go home
 lcd.print("Hello, ARDUINO ");  
 lcd.setCursor ( 0, 1 );        // go to the next line
 lcd.print ("     WORLD!  ");      
}

void loop()
{
 lcd.clear();                // clear LCD screen
 delay(200);
 lcd.print("Hello, ARDUINO ");
 lcd.setCursor ( 0, 1 );        // go to the next line
 delay(200);
 lcd.print ("    WORLD!  ");      
 delay(500);
 lcd.setCursor ( 0, 1 );        // go to the next line
 lcd.print (loopCount++);
 blink2();
 delay(500);  
}

void blink2(){
 static byte lastState ;
 pinMode ( 13, OUTPUT );
 if (lastState != HIGH){
   digitalWrite ( 13, HIGH );
   lastState = HIGH;
 }
 else {
   digitalWrite ( 13, LOW );
   lastState = LOW;
 }
}  

BTW the LCD I2C board I am using came from here:
http://dx.com/p/funduino-iic-i2c-1602-lcd-adapter-board-w-2-5-lcd-screen-black-green-red-173588

bperrybap


Your setup() code is incorrect.
You need to remove this code:
Code: [Select]

 // Switch on the backlight
 pinMode ( BACKLIGHT_PIN, OUTPUT );
 digitalWrite ( BACKLIGHT_PIN, HIGH );



This is not doing what you think as it is not controlling the backlight.
It should never have been there including in the first initial example code.

This is setting Arduino digital pin 3 (BACKLIGHT_PIN is defined as 3)
to an output and setting it HIGH.
On a Leonardo it also sets the I2C pin SCL to HIGH
since on that board the SCL pin is the same as digital pin 3.
You can see this pin sharing in the Leonardo Pinout diagram.
Look across the line for digital pin 3 and you can see [SCL] in blue
on the right.

The library is configured with the pin/bit information in the constructor.
The numbers in the constructor are not Arduino pin numbers.
The numbers in the constructor represent output bit number of the PCF8574 output port.
It tells the library how the PCF8574 output port pins are wired up to the hd44780 lcd pins
and how to control the backlight.
In PCF8574 datasheets the output port pins are labeled p0, p1, p2, p3, p4, p5, p6, p7.
And each "pin" is controlled by the corresponding bit in the 8 bit byte.

Code: [Select]
lcd.begin(cols,rows);
turns on the backlight automatically.

After the library has been initialized by using begin()
the backlight can be controlled by:
Code: [Select]
lcd.backlight();
lcd.noBacklight();




You can see these being used in the examples on Terry King's site.
(The LCD BLUE link I provided above).

You could try one of those examples to see if your backlight is working.
Just make sure to fill in constructor with the proper information to match
your board.

--- bill







jack wp

Thanks Bill, for the update. I agree with all you said, and have tested it. The new backlight codes work fine.

VT91

I am using Arduino Micro and a SPLC780 controlled 20X4 LCD screen.
I2C is wired correctly.

For some reason this code doesn't work. (I changed screen size, ofcourse but that didn't effect anything.)

Is pinout between SPLC780 different than what is in the code?

Code: [Select]
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin,BACKLIGHT_PIN,POSITIVE)

What does POSITIVE stand for?

Thank you!

Code: [Select]

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

#define I2C_ADDR    0x27
#define BACKLIGHT_PIN     3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin,BACKLIGHT_PIN,POSITIVE);

int loopCount = 0;

void setup()
{
 // Switch on the backlight
 pinMode ( BACKLIGHT_PIN, OUTPUT );
 digitalWrite ( BACKLIGHT_PIN, HIGH );

 lcd.begin(20,4);               // initialize the lcd

 lcd.home ();                   // go home
 lcd.print("Hello, ARDUINO "); 
 lcd.setCursor ( 0, 1 );        // go to the next line
 lcd.print ("     WORLD!  ");     
}

void loop()
{
 lcd.clear();                // clear LCD screen
 delay(200);
 lcd.print("Hello, ARDUINO ");
 lcd.setCursor ( 0, 1 );        // go to the next line
 delay(200);
 lcd.print ("    WORLD!  ");     
 delay(500);
 lcd.setCursor ( 0, 1 );        // go to the next line
 lcd.print (loopCount++);
 blink2();
 delay(500); 
}

void blink2(){
 static byte lastState ;
 pinMode ( 13, OUTPUT );
 if (lastState != HIGH){
   digitalWrite ( 13, HIGH );
   lastState = HIGH;
 }
 else {
   digitalWrite ( 13, LOW );
   lastState = LOW;
 }




floresta

#13
Apr 01, 2016, 07:57 pm Last Edit: Apr 01, 2016, 07:59 pm by floresta
You really should start a new thread as you have a new problem.

This thread is marked as SOLVED so many of those who provide answers may not even open it.


I believe that 'POSITIVE' refers to the logic that drives the backlight.

Don

multimedia

Im also getting error:

'POSITIVE' was not declared in this scope


no idea how to fix it, and it makes no sense opening a new thread until the issue has been resolved!

Go Up