LiquidCrystal_I2C for Mega 2560

I am having trouble getting a 20x4 LCD display with a I2C backpack to work on my Fundino Mega 2560. I've done a lot of troubleshooting and at this point I'm convinced the problem is in the library. I've found a newer library, but the parameters were changed around and I can't get it to compile.

More details:

  • I have 3 LCD displays with I2C backpacks.
  • I have 2 Arduino Unos, a Funduino Mega 2560, and a TI Launchpad.
  • I can get all 3 displays working on both Unos and the Launchpad, but not the Mega.
  • I can run I2C scanner on all boards and find the display at address 0x27. Including on the Mega.
  • I can run I2Cmaster and I2Cslave on the Uno, the Mega, and the Launchpad, and whichever way I load 'em and run 'em, they all talk to each other as expected. The Mega is thus verified to send and receive via I2C.
  • I'm using pins 20 SCL and 21 SDA on the Mega. I also tried Analog 5 and 4.
  • The LiquidCrystal_I2C library that works on the Unos was created by Francisco Malpartida on 8/20/11 according to the comments in the file. My file date is 4/5/12 but I think that may be the date I unzipped it.
  • I know my pin numbers for the backpack, they are 2,1,4,5,6,7,3. That works with the older library by Malpartida on the Uno.
  • I found LiquidCrystal_I2C_V3 on GitHub. The GitHub user is Dino0815. It was last updated 8 months ago on 8/14/13 by Sebastian Löser.
  • The constructor and begin() parameters have changed. The constructor now takes the address, cols and rows, and one more parameter, a constant, that indicates which backpack you are using and it's pinout.
  • The default is 'POLLIN' but I think the correct one for my pinout is 'SYDZ'
  • The begin() function now has a 3rd parameter, which is the dot size of the display. (It also takes the # of cols and rows again -- redundant!)
  • Whether I use 3 parameters, or just 2, I get error: no 'void LiquidCrystal_I2C::begin3(uint8_t, uint8_t, uint8_t)' member function declared in class 'LiquidCrystal_I2C' when I compile. Yes, I'm passing it 3 (or 2) unsigned 8-bit integers.
  • I admit my C++ skills are not the greatest, but the error sounds like I am not sending the correct parameters to the begin() function, yet I'm pretty sure I am calling it correctly. My skills are not good enough to trace it out further within his code.
  • Version 3 by Löser does not include updated examples to show how to call it. Or any other real documentation.

I just want a LCD library that works with I2C backpacks (the cheap no-name chinese ones) and that works on a Mega 2560.
Suggestions anyone?

I2C is I2C, the programming is the same for Uno and Mega. Use the standard library LiquidCrystal_I2C2004V1. If you get a result on the Uno, there can't be anything wrong with the library. All you need do is use the Mega pins 20,21, which you already know about, and not A4,A5, which are exclusive to Uno. Since there is nothing to get wrong with the software, it more or less leaves the problem to be found in the hardware. God knows what. I suppose it is possible that you have the I2C connected to A4,A5 as well as 20,21 but I don't know what the result of that would be.

Nick_Pyner:
If you get a result on the Uno, there can't be anything wrong with the library. All you need do is use the Mega pins 20,21

Yeah, you would think so! But if you check my troubleshooting steps above, you will see that I verified that the Mega can both send and receive I2C on pins 20 and 21. And the I2Cscanner sketch found the LCD backpack at address 0x27 just as expected. My Hello World sketch works fine on the Uno (It shows Hello World on the LCD display) but the EXACT SAME CODE does not work on the Mega. It compiles, it runs, but nothing shows up on the LCD display.

I spent much of the day troubleshooting it and running all sorts of tests. I only tried Analog 4 and 5 on the Mega out of desperation after nothing else worked.

I have at least 3 versions of the LiquidCrystal_I2C library, updated by different authors. I get the same results with all three. I will try to track down the "LiquidCrystal_I2C2004V1" specific version and try it.

I will check my Uno and Mega but I'm sure programmes I have had are the same for both and labelled accvordingly. The library I mentioned is the only one I know of. I'm certainly not inclined to try any others..........

OK, the following works without changing anything on both Uno and Mega. As I said, I2C is I2C, and this is exactly what you would expect. After all, what is there to change? It is just a matter of connecting the SDA,SCL as appropriate. The library is produced by YWRobot and was probably obtained from a link on the eBay page when I got the display. I submit your problem is too much concern about buzzstuff like parameters and functions, not to mention your limited C++ skills, where in truth you don’t need any C++ skills at all, and you are not using the library in the manner intended i.e. no fiddling. In short, your libraries are probably innocent, and your problem lies somewhere else. I imagine the first step is to re-install the libraries virgo intacto, it could even be the only step…

I guess it is just possible that Malpartida, Dinoxxx, and Loser, have also been fiddling when they shouldn’t, so, as a last resort, I guess you could get this library from Yourduino.com, as I don’t believe it should matter which library you use.

/* YourDuino.com Example Software Sketch
 20 character 4 line I2C Display
 terry@yourduino.com */

/*-----( Import needed libraries )-----*/
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

/*-----( Declare Constants )-----*/
/*-----( Declare objects )-----*/
// set the LCD address to 0x27 for a 20 chars 4 line display
LiquidCrystal_I2C lcd(0x27,20,4);  

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


void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  Serial.begin(9600);
  lcd.init();                      // initialize the lcd 

  // Print our characters on the LCD
  lcd.backlight();  //Backlight ON if under program control
  lcd.setCursor(3,0); //Start at character 3 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");
    delay(1000); 
  lcd.setCursor(0,3);
  delay(1000);   
  lcd.print("http://YourDuino.com");

}/*--(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 )-- */

It may be you need to try a level shifter as the Mega has 10K pullups to 5 volts on the I2C pins.

http://playground.arduino.cc/Main/I2CBi-directionalLevelShifter#.U0FYgvldWSo

Which library does matter. As can be seen, they are not all the same.
Some work better than others, and sometimes vendors go in and monkey with stuff
for their hardware and sometimes break things.

In the MANY threads like this, the outcome is almost always the same: user error.
What I can say is that I recommend using fm's library, as I know that one works.
https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
Follow the instructions and install it properly:
https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home
(see the Downloading and Installation section)

Something to check:

  • make sure that one and only one of the libraries is installed a time.
    Because of the way the IDE works and the naming used by the libraries,
    they cannot coexist and can step on each other to
    create an environment where nothing works or things behave strangely
    because you can end getting parts of one library and parts of another.
    So when you install another library you must make sure to remove any previous library.
    i.e. you can't have more than library that has a LiquidCrystal_I2C.h header file installed

I know my pin numbers for the backpack, they are 2,1,4,5,6,7,3. That works with the older library by Malpartida on the Uno

If you have it working on UNO, then it should work on Mega with no changes.
I would go back to this condition and start from there.

Get it working on UNO, then take the exact same i2c backpack & LCD, move it the mega board,
change the board type, and upload it to mega.
Make sure that nothing else is changed.
i.e. build sketch on the same machine, and use the exact same i2c backpack & LCD that worked on the UNO.

--- bill

I got it working on both the Uno and the Mega...
... using fm's library at https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads as recommended Bill (bperrybap) THANK YOU!

and BTW:

Get it working on UNO, then take the exact same i2c backpack & LCD, move it the mega board,
change the board type, and upload it to mega.
Make sure that nothing else is changed.
i.e. build sketch on the same machine, and use the exact same i2c backpack & LCD that worked on the UNO.

is precisely what I did right from the very start if you read my troubleshooting steps. But as Bill noted:

Which library does matter. As can be seen, they are not all the same.
Some work better than others, and sometimes vendors go in and monkey with stuff
for their hardware and sometimes break things.

And after all my troubleshooting, I figured the problem MUST be in the version of the library I was using, which is why my original question was:

I just want a LCD library that works with I2C backpacks (the cheap no-name chinese ones) and that works on a Mega 2560.
Suggestions anyone?

so thanks to everyone but extra kudos to Bill for pointing me to one that works! :smiley:
Part of my problem was that I didn't realize that fm's library also supported I2C, since the overall library name is simply named "LiquidCrystal" I thought it only supported ones that were wired to a bunch of pins (without I2C). Hence, I went out seeking other people's libraries to get I2C support that unknowingly I had along. Maybe I should have clicked my heels together 3 times :wink: