Arduino 1.0.1 setting the I2C address for 20 x 4 LCD

Discussion in 'Programmer's Corner' started by dyeraaron, Aug 30, 2012.

  1. dyeraaron

    Thread Starter Active Member

    Oct 27, 2008
    Hello all,

    My name is Aaron. I've been hitting my head up against the wall all day. So I have an Arduino Project thats hooked up to a 20 x 4 LCD that works just fine by connecting the 6 data lines and then programming it etc.....However, I have purchased an I2C serial interface board that uses the Two wire interface of TWI as well as VCC and Ground to operate the code from the arduino onto the LCD....

    After I received the New LCD with the I2C I hooked up pins analog 4 from arduino Uno to the SDA on the I2C and analog 5 from arduino to SDL on I2C and loaded this code for testing from the website I bought it from:

    /* Example Software Sketch
    20 character 4 line I2C Display */
    /*-----( 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 )----*/
    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!");
    lcd.print("From YourDuino");
    lcd.print("20 by 4 Line Display");
    }/*--(end setup )---*/

    void loop() /*----( LOOP: RUNS CONSTANTLY )----*/
    // Do nothing
    }/* --(end main loop )-- */

    /* ( THE END ) */

    Loads just fine...I even hooked up the SDA and SDL to pull up resistors as I once saw on this website:

    But this is an older site.....I have a newer Arduino Uno and using 1.0.1 and theres nothing on my LCD (contrast Pot is good too)

    I don't get I need to set my I2C address to something else?

    I am using this as a reference:

  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    I2C can be tough to get working... same goes for LCD displays.

    First thing to check for I2C is the ACK bit: after sending the 7 bit address plus the 1 bit read/write bit, the master releases the data line so the slave can send back the ACKnowedge bit by pulling data low. If you get your Arduino to pause when this bit is coming back you can use even a voltmeter or a LED to see if the LCD controller is being properly addressed.

    If that works...

    First thing I would check when a library of LCD functions is not working is the delays: set them absurdly long and see if that helps. Once the display says HELLO WORLD you can cut them back to what they should be.

    I don't have any specific Arduino things you could heck, I don't use them so have no insight.
  3. BSomer


    Dec 28, 2011
    I have not worked with the I2C library or any LCD library for that matter. However, I did look at the reference site you linked to and read through some of the code examples listed there. You seem to be missing some lines that may be needed.

    "Serial.begin(9600);" -- This line starts the serial communications. Your code doesn't seem to have this.

    Then there is the line in the "void loop()" where you are doing nothing but the example has the following:

    // when characters arrive over the serial port...
    if (Serial.available()) {
    // wait a bit for the entire message to arrive
    // clear the screen
    // read all the available characters
    while (Serial.available() > 0){
    // display each character to the LCD

    I am uncertain if the loop stuff is necessary to just display your message once and stop. I think it wouldn't hurt to put it in though.