[SOLVED] I2C LCD - Setup instructions for 16x2

I find an amazing LCD project here: an UART TFT LCD with Nextion software editor
http://forum.arduino.cc/index.php?topic=316321.0

Many thanks from Quebec Canada , your work is ancestral. I am sure this has spawned many a success , has for me . Thank you may you be well happy and prosper.

I have a problem with my LCD 1602 and I2C. I I bought them online (on DX). Every time when I try to verify any program which have to use LiquidCrystal library I receive this message:

"Arduino: 1.6.4 (Windows 7), Board: "Arduino Uno"
sketch_apr24a.ino:12:31: fatal error: LiquidCrystal_I2C.h: No such file or directory
compilation terminated.
Error compiling.

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

I don't know which test code to use. I have tried with this code from this site: arduino-info - LCD-Blue-I2C

/* 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 0x27 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 ) */

I have downloaded LiquidCrystal_V1.2.1.zip from this site: https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
I am probably doing something wrong.

Can some one help me? Where am I wrong? :o
I would be very grateful for any help!!!

Thanks! :slight_smile:

You have to install the library from fmalpartida and remove the original LiquidCrystal library.

Ok thank you, it works now! :smiley:

hi thanks for this explanation i followed the same steps the first time my lcd worked but when i tried it again it didnt work i had an error said expected primary-expression before ' , ' token for the line ( lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE); )

I'm new here and this thread has been INVALUABLE to me getting down the Arduino Starter Kit learning curve.
I know it's simple (when it works, as here) but there is SOOOOO much misinformation & disinformation at the end of Google searches for this sort of stuff. My hair is now GROWING AGAIN. Thanks....
WELL DONE!

G'Day all.
This is my first on this Forum and I would like to say thanks for solving that problem however I don't understand why it was necessary in the first place. I have been using I2C LCD for some years with no problems until I updated to 1.6 and that is where the wheels fell off. None of my programs using I2C LCD worked. So now I have to go back and add a lot more code.

Thank you so much, awsome. Following your post has fixed my different issues in a few minutes,
Ok at first try, very good :slight_smile:

I have to say that I have spent so much time trying different(lack of doc !) I2C libraries causing different type of issues and searching for documentation that i was really reconsidering the Arduino IDE (and its Lib pool) as a solution for my projects.

When you begin with such a simple application (displaying a char string on a display) using a single simple library and everything goes wrong.... The question which come directly, "And what about the whole project when displaying the result, which should be kind of "PnP" or "Fire and forget" take so much time...?

I believe that the root cause is due to the fact that each developer/manufacturer want to name its lib (its baby) using the same standard name even if it is only compatible with its particular hardware... great :frowning:

In my opinion naming libraries that way this is a very very poor solution. Ok, i'm a newbie here, but now i'm afraid, what about my projects ? How much time ? A clear naming convention / rules should be defined and applied, everyone will spare time and enjoy using such wonderful and cheap (accessible) piece of technology :slight_smile:

As I have said elsewhere, what is clearly needed is for the fmalpartida library to replace the one presently supplied with the Arduino IDE.

It is not a matter of a pissing contest. The original library is simply unusable (at least in terms of I2C modules as it catered for only one particular module configuration which does not even seem to be available at present - someone correct me if I am wrong :grinning: ) and needs to be replaced.

Hi all, i have followed the steps and tried to get the LCD to work;however it keeps giving me this error when i run the code:
sketch_jun16a.ino:2:17: fatal error: LCD.h: No such file or directory
compilation terminated.
Error compiling.
Any way to fix this problem?

Thanks.

Hi All. Good instructions, I was following them and i2c LCD works fine, but I am also using IR LED and library IRremote.h is hard coded to use PIN3 as well. I tried to change back light PIN3 in order to release it for IR LED, but after this LCD remains black. Is there a way to use different PIN for back light?

ayretix:
Any way to fix this problem?

b0br0ff:
I tried to change back light PIN3 in order to release it for IR LED, but after this LCD remains black. Is there a way to use different PIN for back light?

Yes, first read the instructions for submitting queries, then post your code and a perfectly focused photograph of your set-up with all wires clearly visible as they terminate on the modules as a link in the text, not an attachment.

Yes, first read the instructions for submitting queries,...

Pay particular attention to #5. You are more likely to get a response by starting a new Topic than by tacking your question onto an old one that has been marked as [SOLVED].

Don

I would like to thank all involved. I have spent hours trying an retrying every i2c sketch I could find. Many wouldn't compile, several would flash the dreaded complete2... error. I found the one posted on this forum and within 1 minute I had my lcd working. I don't who posted it first, but thank you. I would like to keep what hair I have left. Thanks again

Thank you ...

Helped in getting an InSainSmartLCD2004 working. Wow, they would really have a good selling product-line if they provide FUNCTIONAL INSTRUCTIONS (documentation that actually gets their products up and running).

With this TOPIC/FORUM site, I was able to get this thing actually working!

just another metoo -- clear and concise. i'm not a newbie, but i greatly appreciate the concise assemblage of trivia all in one place. i've got a chinese-made serial LCD adapter i stuck on the back of a 4 x 20 display of unknown history... the I2C scanner was incredibly handy. address of mine was 0x27 also.

I had the same problems that some of y'all had. I also had a problem where the LCD just displayed garbage.

I used the excellent scanner sketch (thanks!), but that only solved part of my problem.

I ended up going to the manufacturers website where I found a LiquidCrystal_I2C library that worked (for that board).

The board that I got (from eBay) was the LH GY-IICLCD that has a PCF8574T chip on board. This board comes from http://artofcircuits.com/product/i2c-io-expander-interface-board-16x2-20x2-character-lcd-modules and it seems to work pretty well.

I plan to pull their library apart to see why I was getting what I was getting.

Thanks fm and everyone for being such a helpful community!

Cheers
Baelzabubba

baelzabubba:
I plan to pull their library apart to see why I was getting what I was getting.

Why bother? It is a bit of a waste of time.
The reason a library doesn't work with a backpack is that the library's assumption on how the backpack is wired to the LCD does not match how it is really wired. It really is that simple.
You are very lucky in that your board comes with something that is quite rare on these low cost backpacks.
The link you provided provides a schematic which means you can look at it to fill in the constructor with the proper pin mapping for fm's library. It literally takes only a few seconds.
Here it is:
Here is the pin mapping parameters for the constructor (i2caddr, en, rw, d4, d5, d7, d7, bl, polarity)
And here is yours:
LiquidCrystal_I2C lcd(i2caddr, 4, 5, 6, 0, 1, 2, 3, 7, NEGATIVE);

All the information is in the schematic. You can easily see the pin mappings and then if you look at the P7 i/o pin to the transistor, you can see that it uses a PNP transistor with Emitter going to VCC so a "NEGATIVE" or LOW i/o signal from P7 to the transistor base will turn on power to the backlight.

But if you really still want to dig into their code here is the pin mapping in their library which is hard coded:
In LiquidCrystal_I2C.h (backlight signal and polarity)

// flags for backlight control
#define LCD_BACKLIGHT 0x00
#define LCD_NOBACKLIGHT 0x80

In LiquidCrystal_I2C.h (control signals)

#define En B00010000  // Enable bit
#define Rw B00100000  // Read/Write bit
#define Rs B01000000  // Register select bit

In LiquidCrystal_I2C.cpp (data signals)

void LiquidCrystal_I2C::send(uint8_t value, uint8_t mode) {
	uint8_t highnib=value>>4;
	uint8_t lownib=value & 0x0F;
	write4bits((highnib)|mode);
	write4bits((lownib)|mode);
}

That is the same information that can be seen in the schematic and can be used to fill in the constructor in fm's library with the proper mapping information.
IMO it is a bit quicker and easier to simply look at the schematic.

--- bill

bperrybap:
Here is the pin mapping parameters for the constructor (i2caddr, en, rw, d4, d5, d7, d7, bl, polarity)
And here is yours:
LiquidCrystal_I2C lcd(i2caddr, 4, 5, 6, 0, 1, 2, 3, 7, NEGATIVE);

So, is this in the "guesser", which means he simply did not try the guesser, or does it need to be added to the guesser?