Problems with I2C 2004 display

I just recieved my I2c 20x4 display today (with what looks to be a LCM1602 IIC A0 A1 A2).
I just cant compile a single code, which will work.........
Can you help me?
I've downloaded several LiquidCrystal_I2C libraries, imported and added the LiquidCrystal_I2C.h - downloaded a Wire.h (Says it should have come with my arduino ide download, but cant seem to find it) and imported that.
But havent had any example code to verify. I'm going nuts.

https://code.google.com/p/arduino/source/browse/trunk/libraries/Wire/Wire.h?r=1092
This is the wire.h i'm using.
http://magnusglad.wordpress.com/tag/lcm1602/
These two example codes have i tried.

Hope you guys got some advice. Even if you slap me in the face and make me start over in understanding this...
Truly yours,
me

Do you have a link to the i2c backpack your trying to use or at least a good picture. There are several different flavours to be found and it could be as simple as the wrong address your using (use something like this to check) or it could be like mine where the pins between the i2c and the LCD were wired different to the libraries expect.

after you added the library (LiquidCrystal_i2c) you must close and restart the arduino IDE software before trying to compile the sketch?

Did you add the libraries to the sketch?

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

Hello runesmdk,

I have a 20x4 LCD with an I2C module attached in the project I'm working on right now.

I'm using:

And it all works, so I'm guessing something has gone wrong with the installation of your libraries.

If you can, I'd recommend:

  • Back up your sketchbook
  • Re-installing your Arduino IDE for a clean slate.
  • Download the liquid crystal library above
  • After extracting, place the folder named "LiquidCrystal" in your sketchbook/libraries folder. Not the Program FIles (x86)/Arduino/libraries folder.
  • Wire comes with the Arduino IDE so no need to install a new one.
  • Try verifying one of the examples.

If it still doesn't work, post the error that you get here.

Riva:
Do you have a link to the i2c backpack your trying to use or at least a good picture. There are several different flavours to be found and it could be as simple as the wrong address your using (use something like this to check) or it could be like mine where the pins between the i2c and the LCD were wired different to the libraries expect.


This is the board. It isn't the address that is wrong, it won't even verify/compile the code.

BulldogLowell:
after you added the library (LiquidCrystal_i2c) you must close and restart the arduino IDE software before trying to compile the sketch?

Did you add the libraries to the sketch?

#include <Wire.h>

#include <LiquidCrystal_I2C.h>

Didn't know you should restart the arduino program. I wrote in the code you wrote, but should i actively do more to add the librarys to the sketch? Like "Sketch->Add File" - or is it enough just to write that code you have there?

@Snowman815901
Will try that. Thank you.
Will report back soon

If you use the IDE to add the library to the sketch, it will insert those lines into your sketch, automatically by selecting:

Sketch
Import Library

and you are correct... if you cannot compile the sketch the problem is not hardware.

Uninstalled and reinstalled Arduino IDE.
Added the library LiquidCrystal_I2C directly from zip.
Restarted Arduino IDE.

Using the code i found on http://arduino-info.wikispaces.com/LCD-Blue-I2C#v3

/* YourDuino.com Example Software Sketch
 20 character 4 line I2C Display
 Backpack Interface labelled "LCM1602 IIC  A0 A1 A2"
 terry@yourduino.com */

/*-----( Import needed libraries )-----*/
#include <Wire.h>  // Comes with Arduino IDE
// Get the LCD I2C Library here: 
// https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
// Move any other LCD libraries to another folder or delete them
// See Library "Docs" folder for possible commands etc.
#include <LiquidCrystal_I2C.h>

/*-----( Declare Constants )-----*/
//none
/*-----( Declare objects )-----*/
// set the LCD address to 0x20 for a 20 chars 4 line display
// Set the pins on the I2C chip used for LCD connections:
//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x20, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address


/*-----( Declare Variables )-----*/
//none

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  Serial.begin(9600);  // Used to type in characters

  lcd.begin(20,4);         // initialize the lcd for 20 chars 4 lines and turn on backlight

// ------- Quick 3 blinks of backlight  -------------
  for(int i = 0; i< 3; i++)
  {
    lcd.backlight();
    delay(250);
    lcd.noBacklight();
    delay(250);
  }
  lcd.backlight(); // finish with backlight on  
  
//-------- Write characters on the display ----------------
// NOTE: Cursor Position: CHAR, LINE) start at 0  
  lcd.setCursor(3,0); //Start at character 4 on line 0
  lcd.print("Hello, world!");
  delay(1000);
  lcd.setCursor(2,1);
  lcd.print("From YourDuino");
  delay(1000);  
  lcd.setCursor(0,2);
  lcd.print("20 by 4 Line Display");
  lcd.setCursor(0,3);
  delay(2000);   
  lcd.print("http://YourDuino.com");
  delay(8000);
// Wait and then tell user they can start the Serial Monitor and type in characters to
// Display. (Set Serial Monitor option to "No Line Ending")
  lcd.setCursor(0,0); //Start at character 0 on line 0
  lcd.print("Start Serial Monitor");
  lcd.setCursor(0,1);
  lcd.print("Type chars 2 display");   


}/*--(end setup )---*/


void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
  {
    // when characters arrive over the serial port...
    if (Serial.available()) {
      // wait a bit for the entire message to arrive
      delay(100);
      // clear the screen
      lcd.clear();
      // read all the available characters
      while (Serial.available() > 0) {
        // display each character to the LCD
        lcd.write(Serial.read());
      }
    }
  }

}/* --(end main loop )-- */


/* ( THE END ) */

This yields this result when verifying:

In file included from DisplayI2C.ino:12:
C:\Users\RuMo Acer\Documents\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:80: error: conflicting return type specified for 'virtual void LiquidCrystal_I2C::write(uint8_t)'
C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/Print.h:48: error:   overriding 'virtual size_t Print::write(uint8_t)'
DisplayI2C:20: error: 'POSITIVE' was not declared in this scope

BulldogLowell:
If you use the IDE to add the library to the sketch, it will insert those lines into your sketch, automatically by selecting:

Sketch
Import Library

and you are correct... if you cannot compile the sketch the problem is not hardware.

I just copy-pasted the script, which uses LiquidCrystal_I2C library. The library is added to the arduino ide but not to the project (Sketch->Add file)

using the code tags, post your entire sketch.

use the # button when you reply (crosshatch, pound, whatever) and put your code in there.

I did 2 posts back :slight_smile:

Did you move the entire folder "LiquidCrystal" contained within the .zip or just one of the files within? The entire folder should be moved.

Also, try removing or renaming any other LCD libraries you have installed. Both in you sketchbook/Libraries and in Program Files (x86)/Arduino/Libraries. Just drag the whole folder of the old one out onto the desktop temporarily or something.

It's possible the one you installed may be conflicting with the one that comes with the IDE. I may have had to do that with my project but I don't remember.

Snowman815901:
Did you move the entire folder "LiquidCrystal" contained within the .zip or just one of the files within? The entire folder should be moved.

Also, try removing or renaming any other LCD libraries you have installed. Both in you sketchbook/Libraries and in Program Files (x86)/Arduino/Libraries. Just drag the whole folder of the old one out onto the desktop temporarily or something.

It's possible the one you installed may be conflicting with the one that comes with the IDE. I may have had to do that with my project but I don't remember.

I used the auto install feature within arduino ide 1.0.5 according to the arduino website guide - and the library is called LiquidCrystal_I2C, which shouldn't interfere with the other, as it is named otherwise (According to my understanding)

you are using an I2C board, but you are defining the pins here:

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

replace this with:

LiquidCrystal_I2C lcd(0x20, 20,4);  // Set the LCD I2C address

edit your sketch, save it, close it. restart the IDE and open the sketch. then try to compile it

then we have to check that 0x20 is your actual I2C address.

and the library is called LiquidCrystal_I2C, which shouldn't interfere with the other, as it is named otherwise (According to my understanding)

I does say directly in the code you posted in reply # 6 to: " Move any other LCD libraries to another folder or delete them"

I think it's worth doing.

If that doesn't work:

  • Make sure there are no LDC libraries (when I say libraries I mean the entire folder that contains .h files, .cpp files, examples, etc) in either your A) sketchbook/Libraries and B) Program Files (x86)/Arduino/Libraries or C) inside the folder for your sketch.
  • Then, unzip the new liquid crystal library I linked. That should result in a folder named "LiquidCrystal"
  • Drag this entire folder ("LiquidCrystal") into your sketchbook/Libraries folder.
  • Restart the IDE
  • Try to compile an example sketch.

Since you can't get the example to compile, I would bet cash money that this problem has to do with your library installation. And it definitely has nothing to do with the code you're using or the devices you're using.

runesmdk:

Snowman815901:
Did you move the entire folder "LiquidCrystal" contained within the .zip or just one of the files within? The entire folder should be moved.

Also, try removing or renaming any other LCD libraries you have installed. Both in you sketchbook/Libraries and in Program Files (x86)/Arduino/Libraries. Just drag the whole folder of the old one out onto the desktop temporarily or something.

It's possible the one you installed may be conflicting with the one that comes with the IDE. I may have had to do that with my project but I don't remember.

I used the auto install feature within arduino ide 1.0.5 according to the arduino website guide - and the library is called LiquidCrystal_I2C, which shouldn't interfere with the other, as it is named otherwise (According to my understanding)

The error of missing "POSITIVE" is indicating that the wrong library is being used,
which is due to the either the wrong library installed, or fm's LiquidCrystal library being installed incorrectly.

So I'm with snowman in that I would bet cash money, and lots of it, that there is a library
installation issue.

fm's LiquidCrystal library is not called LiquidCrystal_I2C
It is called LiquidCrystal
If LiquidCrystal_I2C was the name of the zip/library you installed,
you have installed the incorrect library.
The latest zip of fm's LiquidCrystal library is LiquidCrystal_V2.1.1.zip

If you installed the LiquidCrystal_I2C library
in order to use fm's LiquidCrystal library you will have to fully uninstall LiquidCrystal_I2C

The issue is that fm's LiquidCrystal library is replacement for the standard LiquidCrystal
library and there can be header file collisions with other libraries.
Essentially, fm's LiquidCrystal library can be thought of as multiple libraries bundled together in one library.
In reality it is one library but can support many different interfaces by using different constructors.
Because of this it can be a bit confusing because the constructor names don't always match
up with the library name.
For example in this case, the library name is LiquidCrystal but the constructor
name is LiquidCrystal_I2C

The zip image that fm created really isn't quite correct for using the IDE to install it.
I'd recommend installing manually.
You can install it in your home sketchbook/libraries directory instead of replacing
the LiquidCrystal library that came with the IDE
but you have to make sure it is named "LiquidCrystal" and that there is no other
LiquidCrystal IC2 library installed.

BulldogLowell's advice on the constructor is wrong for fm's LiquidCrystal library.
The constructor he provided was for the LiquidCrystal_I2C library which works differently.

So while both fm's LiquidCrystal library and the LiquidCrystal_I2C library both have a constructor
called LiquidCrystal_I2C, that is used to initialize the library for a PCF8574 based LCD backpack,
they are different libraries and use very different parameters in the constructors.

fm's LiquidCrystal library works with any backpack so it requires that you tell it how the PCF8547 is wired to the LCD.
LiquidCrystal_I2C library only supports a particular wiring so it does not need to now how it is wired up
but it may not work with your backpack.

The examples on Terry's yourduino.com site, referenced above are for fm's LiquidCrystal library not
the LiquidCrystal_I2C library.

You can only have one of these libraries installed at a time other wise, strange things can happen
since they collide with each other and the IDE can pick the wrong one or potentially even pick and choose different ones
at different points of time during the build process.
Which is why you see the POSITIVE error message.

--- bill

Allright.
So, how would i go about uninstalling librarys? Simply just moving them, and/or renaming them - then start/re-start the arduino ide?
And should i remove every library containing the words liquid*?
And now you really must be patient with me. I've searched my computer for a folder called sketchbook without any luck. Can i get some clarification?

Also, i am not able to google search the v2.1.1 library - is it called any different perhaps?

If you go to File -> Preferences in your Arduino IDE, right at the top, it will show you the location of your sketchbook folder.

As for uninstalling libraries, for this case at least, I would move any folder with the word "Liquid", "crystal" or "LCD" in it's name completely out of your libraries folder. From both library locations.

Then follow the directions I posted above.

Snowman815901:
If you go to File -> Preferences in your Arduino IDE, right at the top, it will show you the location of your sketchbook folder.

As for uninstalling libraries, for this case at least, I would move any folder with the word "Liquid", "crystal" or "LCD" in it's name completely out of your libraries folder. From both library locations.

Then follow the directions I posted above.

This made a lot of sense.
Nothing left with LCD, liquid or crystal remaining in either folder :slight_smile:

Ran a i2c scanner in the meantime;
"Scanning...
I2C device found at address 0x27 !
done"

So it's there allright

I'm up and running with the library from Snowman815901 - i'm quite pleased :slight_smile:

You all been a great help! And this isnt the last you heard from me, because now i'll venture in to serial communications with an engine management, and how to get it to display on the arduino LCD :smiley:

Thank you very much everybody

/* YourDuino.com Example Software Sketch
 20 character 4 line I2C Display
 Backpack Interface labelled "LCM1602 IIC  A0 A1 A2"
 terry@yourduino.com */

/*-----( Import needed libraries )-----*/
#include <Wire.h>  // Comes with Arduino IDE
// Get the LCD I2C Library here: 
// https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
// Move any other LCD libraries to another folder or delete them
// See Library "Docs" folder for possible commands etc.
#include <LiquidCrystal_I2C.h>

/*-----( Declare Constants )-----*/
//none
/*-----( Declare objects )-----*/
// set the LCD address to 0x20 for a 20 chars 4 line display
// Set the pins on the I2C chip used for LCD connections:
//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address


/*-----( Declare Variables )-----*/
//none

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  Serial.begin(9600);  // Used to type in characters

  lcd.begin(20,4);         // initialize the lcd for 20 chars 4 lines and turn on backlight

// ------- Quick 3 blinks of backlight  -------------
  for(int i = 0; i< 3; i++)
  {
    lcd.backlight();
    delay(250);
    lcd.noBacklight();
    delay(250);
  }
  lcd.backlight(); // finish with backlight on  
  
//-------- Write characters on the display ----------------
// NOTE: Cursor Position: CHAR, LINE) start at 0  
  lcd.setCursor(0,0); //Start at character 4 on line 0
  lcd.print("     RSMTUNING      ");
  delay(1000);
  lcd.setCursor(0,1);
  lcd.print("   Megasquirt 1   ");
  delay(500);  
  lcd.setCursor(0,2);
  lcd.print("   Race-display     ");
  lcd.setCursor(0,3);
  delay(500);   
  lcd.print("  Under udvikling  ");
  delay(1000);
  lcd.clear();
  lcd.setCursor(0,0); //Start at character 4 on line 0
  lcd.print("   RPM: 1000");
  delay(250);
  lcd.setCursor(0,1);
  lcd.print("   MAP: 127 kpa");
  delay(250);  
  lcd.setCursor(0,2);
  lcd.print("   AFR: 12.5");
  lcd.setCursor(0,3);
  delay(250);   
  lcd.print("  Temp: 88");
  delay(8000);



// Wait and then tell user they can start the Serial Monitor and type in characters to
// Display. (Set Serial Monitor option to "No Line Ending")
//  lcd.setCursor(0,0); //Start at character 0 on line 0
//  lcd.print("Start Serial Monitor");
//  lcd.setCursor(0,1);
//  lcd.print("Type chars 2 display");   


}/*--(end setup )---*/


void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
  {
    // when characters arrive over the serial port...
    if (Serial.available()) {
      // wait a bit for the entire message to arrive
      delay(100);
      // clear the screen
      lcd.clear();
      // read all the available characters
      while (Serial.available() > 0) {
        // display each character to the LCD
        lcd.write(Serial.read());
      }
    }
  }

}/* --(end main loop )-- */


/* ( THE END ) */