element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Arduino I2C display
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 22 replies
  • Answers 1 answer
  • Subscribers 409 subscribers
  • Views 4568 views
  • Users 0 members are here
  • lcd
  • i2c
  • help
  • 20x4
  • arduino
  • module
Related

Arduino I2C display

danyboy
danyboy over 12 years ago

Hello:

I'm a hobbist electronics student and I have been experimenting with arduino for a while. I have worked with character and graphic LCD without any serious problems. I wanted to save wires, so I bought an I2C LCD 20x4 module from ebay. However I have not been able to get it working. I have downloaded the most recent I2C library and I have followed all the instructions but my LCD simply won't work. Instead it lights up like this. The supplier told me that the address of my display is 0x27, but when I use this address nothing happens. After trying different addresses, I dicovered that if I use 0x20 as an address some characters blink randomly with the example code running. the chip on the board is the pcf8574 from Phillips.

Attachments:
image
image
  • Sign in to reply
  • Cancel

Top Replies

  • Workshopshed
    Workshopshed over 12 years ago in reply to billabott +2
    The problem seems to be that pcf8574 is just an I/O expander so it can be wired up differently. The device I chose luckily had a ST7032 LCD controller chip so I did not have that issue but I still had…
  • mcb1
    mcb1 over 12 years ago in reply to danyboy +1
    Daniel You might need to clarify some items here. 1. Your sketch allocates the backlight on D13, but your display is a I2C version and the backlight pins are LCD 16 and 15 (as shown on top left of your…
  • billabott
    billabott over 12 years ago +1 suggested
    #include <Wire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd2 = LiquidCrystal_I2C(0x27,20,4); // Set the LCD address, # columns and # rows // Create a set of new characters const uint8_t charBitmap…
  • billabott
    0 billabott over 12 years ago

    Are you using this sketch?


     

     

    #include <Wire.h>

    #include <LiquidCrystal_I2C.h>

     

    LiquidCrystal_I2C lcd(0x27,16,2); //set the LCD address to 0x27 for a 16 chars and 2 line display

    //LiquidCrystal_I2C lcd(0x27,20,4); //set the LCD addr to 0x27 for a 20 chars and 4 lines

    // this may not work, simple extrapolation on WATB's part


    void setup()

    {

    lcd.init();

    lcd.backlight();

    lcd.setCursor(0, 0);

    lcd.print("b2cqshop");

    lcd.setCursor(0, 1);

    lcd.print("Voltage: ");

    lcd.setCursor(13, 1);

    lcd.print("V");

    }

    void loop()

    {

    int val;

    float temp;

    val=analogRead(0);

    temp=val/4.092;

    val=(int)temp;//

    lcd.setCursor(9, 1);

    lcd.print(0x30+val/100,BYTE);

    lcd.print(0x30+(val%100)/10,BYTE);

    lcd.print('.');

    lcd.print(0x30+val%10,BYTE);

    delay(100);

    }

     

    Came for supplier's ad for similar device.  It may be that the library only supports 2x20 on that 4x20 device for now.  I don't know.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • danyboy
    0 danyboy over 12 years ago in reply to billabott

    Hi billabot:

    Thank you for responding so quickly. Im am using the sketch provided as an example that comes with the library:

     

    #include <Wire.h>

    #include <LiquidCrystal_I2C.h>

     

    #define BACKLIGHT_PIN     13

     

     

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

     

     

    //LiquidCrystal_I2C lcd(0x38, BACKLIGHT_PIN, POSITIVE);  // Set the LCD I2C address

     

      

    // Creat a set of new characters

    const uint8_t charBitmap[][8] = {

       { 0xc, 0x12, 0x12, 0xc, 0, 0, 0, 0 },

       { 0x6, 0x9, 0x9, 0x6, 0, 0, 0, 0 },

       { 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0, 0x0 },

       { 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0, 0x0 },

       { 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0x0 },

       { 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0x0 },

       { 0x0, 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0x0 },

       { 0x0, 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0x0 }

      

    };

     

     

    void setup()

    {

       int charBitmapSize = (sizeof(charBitmap ) / sizeof (charBitmap[0]));

     

     

      // Switch on the backlight

      pinMode ( BACKLIGHT_PIN, OUTPUT );

      digitalWrite ( BACKLIGHT_PIN, HIGH );

     

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

     

     

       for ( int i = 0; i < charBitmapSize; i++ )

       {

          lcd.createChar ( i, (uint8_t *)charBitmap[i] );

       }

     

     

      lcd.home ();                   // go home

      lcd.print("Hello, ARDUINO "); 

      lcd.setCursor ( 0, 1 );        // go to the next line

      lcd.print (" FORUM - fm   ");

      delay ( 1000 );

    }

     

     

    void loop()

    {

       lcd.home ();

       // Do a little animation by writing to the same location

       for ( int i = 0; i < 2; i++ )

       {

          for ( int j = 0; j < 16; j++ )

          {

             lcd.print (char(random(7)));

          }

          lcd.setCursor ( 0, 1 );

       }

       delay (200);

    }

     

    By the way, I tried the sketch that you said, and my library doesn´t support most of the command. Still thank you

     

    Daniel

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mcb1
    0 mcb1 over 12 years ago in reply to danyboy

    Daniel

    You might need to clarify some items here.

    1.     Your sketch allocates the backlight on D13, but your display is a I2C version and the backlight pins are LCD 16 and 15 (as shown on top left of your first image)

    2.     The address settings appear to have been soldered or unsoldered and the datasheet for the chip shows that the address should be 0x27.

    3.     Your example does not seem to be for this library, as it is incomplete.

    4.     The line lcd.begin(20,4) shows this is for a 20x4 LCD, and not an I2C version LCD

    5.     Please confirm what pin on the lcd goes to what pin at the Arduino, to verify the connections.

     

    Please try the code below, and advise if you get anything.

    *** You may need to wind down the contrast until the top line of blocks is just visible. ***

     

     

     

    #include <Wire.h>

    #include <LiquidCrystal_I2C.h>

     

    LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display


    LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 20 chars and 4 line display

     

    void setup()

    {

      lcd.init();                      // initialize the lcd

     

      // Print a message to the LCD.

      lcd.backlight();

      lcd.print("Hello, world!");

    }

     

    void loop()

    {

    }

     

     

    Thanks

    Mark

     

    edit

    oops, should have read all the original post

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • billabott
    0 billabott over 12 years ago in reply to danyboy

    Is the library from the vendor's web site?  Which is where exactly?  provide link.

    The source I found for the library is here: http://hmario.home.xs4all.nl/arduino/LiquidCrystal_I2C/LiquidCrystal_I2C.zip

     

    All players should be familiar with: http://playground.arduino.cc/Code/LCDAPI

     

    I have a feeling that the LC_I2C library demands the latest version of Arduino IDE.

     

    Latest? info seems to be here: http://wentztech.com/radio/arduino/files/LCDI2C.html    -Happy Trails

     

    -= End Of Line =-

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • billabott
    0 billabott over 12 years ago

    Given

    LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27,20,4);//  (address of the display, cols, rows)   *

     

    The underlined portion is a function call containing the parameters that define the LCD interface/capabilities.

     

    It compiles for me.  I don't understand how your versions are compiling.   (See Postscript.)

     

    It returns a value into lcd which might be seen by the sketch as a handle;  so that the other library functions can be accessed correctly with the proper parameters.  What if there were two or more LCDs listening on the same I2C wire with different addresses?   Hmmmm?  M'kay!

    for example:

    lcd.print("Hello W.A.T. Bottger");

     

    This is hard stuff, y'all.

     

    Postscript:  Now that the IDE has indexed the existance and location of the library, the original notation also works, but I don't like it as much as the syntactically understandable one on line two of this posting.  Yeah, I know it is a constructor instantiating an object. M'kay.  But who cares?

     

    -=SyntaxMatters=-

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • billabott
    0 billabott over 12 years ago

     

     

    #include <Wire.h>

     

    #include <LiquidCrystal_I2C.h>

     

    LiquidCrystal_I2C lcd2 = LiquidCrystal_I2C(0x27,20,4);  // Set the LCD address, # columns and # rows

     

    // Create a set of new characters

    const uint8_t charBitmap[][8] = {

       { 0xc, 0x12, 0x12, 0xc, 0, 0, 0, 0 },

       { 0x6, 0x9, 0x9, 0x6, 0, 0, 0, 0 },

       { 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0, 0x0 },

       { 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0, 0x0 },

       { 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0x0 },

       { 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0x0 },

       { 0x0, 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0x0 },

       { 0x0, 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0x0 }

     

    };

     

    void setup()

    {

       int charBitmapSize = (sizeof(charBitmap ) / sizeof (charBitmap[0]));

       lcd2.backlight();               // Switch on the backlight

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

       for ( int i = 0; i < charBitmapSize; i++ )

       {

         lcd2.createChar ( i, (uint8_t *)charBitmap[i] );

       }

     

      lcd2.home ();                   // go home

      lcd2.print("Hello, ARDUINO ");

      lcd2.setCursor ( 0, 1 );        // go to the next line

      lcd2.print (" FORUM - fm   ");

      delay ( 1000 );

    }

     

    void loop()

    {

       lcd2.home ();

       // Do a little animation by writing to the same location

       for ( int i = 0; i < 2; i++ )

       {

          for ( int j = 0; j < 16; j++ )

          {

             lcd2.print (char(random(7)));

          }

          lcd2.setCursor ( 0, 1 );

       }

       delay (200);

    }


    This compiles clean:

    Got a clean compile with this sketch.  image

     

    and this one:

    #include <Wire.h>

    #include <LiquidCrystal_I2C.h>

     

    LiquidCrystal_I2C lcd=LiquidCrystal_I2C(0x27,20,4); //set the LCD address to 0x27 for a 16 chars and 2 line display

     

     

    void setup()

    {

    lcd.init();

    lcd.backlight();

    lcd.setCursor(0, 0);

    lcd.print("b2cqshop");

    lcd.setCursor(0, 1);

    lcd.print("Voltage: ");

    lcd.setCursor(13, 1);

    lcd.print("V");

    }

    void loop()

    {

    int val;

    float temp;

    val=analogRead(0);

    temp=val/4.092;

    val=(int)temp;//

    lcd.setCursor(9, 1);

    lcd.print(0x30);

    lcd.print(0x30+(val%100)/10);

    lcd.print('.');

    lcd.print(0x30+val%10);

    delay(100);

    }

     

    So please report back if it actually works with the I2C LCD.  thanks.  And give me my points.  I earned them tonight.


    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • mcb1
    0 mcb1 over 12 years ago in reply to billabott

    I should have read all the original post.

    I've edited the initialisation line to reflect the 20x4 display.

     

    Cheers

    mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • danyboy
    0 danyboy over 12 years ago in reply to billabott

    Hi billabot:

    First of all thank you so much for all your help.

    I double checked all my connections, I'm using an arduino mega 1280, the vcc is connected to +5v, gnd is connected to ground, SCL is connected to pin 21 (it is marked SCL), and SDA is connected to pin 20(It is marked SDA).

    The address setting jumpers were already like that when I got may LCD, they are just tined, none is making contact.

    I just downloaded the most reacent arduino ide, and I also downloaded the library you sugested. But this time there is a new problem, the compiller sends the following error mesage:

     

    Users/dany/Documents/Arduino/libraries/LiquidCrystal_I2C/LiquidCrystal_I2C.cpp: In member function 'void LiquidCrystal_I2C::expanderWrite(uint8_t)':

    Users/dany/Documents/Arduino/libraries/LiquidCrystal_I2C/LiquidCrystal_I2C.cpp:243: error: 'class TwoWire' has no member named 'write'

     

    I supose that there is something incompatible with the wire library and the LCD I2C library, but I'm not sure.

    Thanks again for your patience and support.

     

    PS:

    This is the first time I use element 14, so I don't know you to give you points. As soon as I find out how to do it, I will immediately give you points

     

    Daniel

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • billabott
    0 billabott over 12 years ago in reply to danyboy

    As MarkB said : The backlight is not controlled by pin 13 in this situation. 

    Take out the 3 lines pertaining to pin 13 and backlight control.

     

    They are only optionally used with a plain old 2x16 LCD using the parallel interface.  The I2C interface is 4 wires, right?  Ground, Vcc, clk, and serial data.  The one I looked at on eBay.com had a tiny round dial potentiometer to adjust the backlight brightness.  After that you can only programmatically turn it ON or OFF.

     

    The LC_i2c library includes:

    // flags for backlight control

    #define LCD_BACKLIGHT 0x00

    #define LCD_NOBACKLIGHT 0x80

    and functions that would appear in sketch as:

    lcd.backlight();

    or

    lcd.noBacklight();

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • billabott
    0 billabott over 12 years ago in reply to danyboy

    You should see some boxes at the bottom of each posted response.  Choose ONE posted answer for the Best Answer and other posted answers for helpful answers if you wish to do so.

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube