I2C for LCD

IMG_20141108_161103A cheap I2C expander aimed at LCD’s is available from a multitude of sources such as eBay or DealExtreme (http://www.dx.com/p/lcd1602-adapter-board-w-iic-i2c-interface-black-works-with-official-arduino-boards-216865). The pin-out from this interface matches the pin-out from most Hitachi based LCD’s and therefore can easily be connected, just make sure that the pin’s are not connected in reverse.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Gnd Vcc Vlcd RS RW E D0 D1 d2 D3 D4 D5 D6 D7 Anod Cathode

After downloading and installing the library from F. Malpartida, use the following program to test

/*
P4 R/S
P5 RW
P6 E
P0 D4
P1 D5
P2 D6
P3 D7

A4=SDA 
A5=SCL
*/
#include  <Wire.h>
#include  <LiquidCrystal_I2C.h>
#define BACKLIGHT_PIN     3
#define I2C_ADDR 0x27 
LiquidCrystal_I2C lcd(I2C_ADDR, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
// 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]));

    
  lcd.begin(16,2);               // initialize the lcd 
// Switch off the backlight
noBacklight()

   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);
}

The standard address on the I2C bus for this model is 27H. In case you need/want to change that, you need to connect the A1-A3 lines to ground: either 1, 2 or all 3 of them. The table below  shows what adresses correspond with what  connections. You will find solderpads  of these addresses on the board.
pcf8574end

Advertisement

2 thoughts on “I2C for LCD”

  1. Subject:  I2C for LCD Great idea, but …….. what is the  pinout of this board, of which I bought some, but I do not find the pinout anywhere.Of course it was not with the parcel received by me. 16 unknown pins and even the addresses are not quite clear how to set. Please give me some info. Thanks,Ben.

    Benjamin Vis via Manin 9A 33080 Prata (PN) Italia voice: +39-(0)434-610.004 e-mail: benjaminvis@yahoo.com

  2. Benjamin, the pinout is as I described in the first few lines of my article, in the table that says 1——16
    If you have the same board as I have, then pin 16 is at the side where you find the jumper for the backlight and pin 1 is at the side where you find the 4 pins header.
    With regard to the addresses: the standard address is 0x27H in the lower right corner, close to the 4 pins header, you will see 3 x2 solderpads that make the addresses A1-A3. connecting any of these with the opposite pad will change the address.
    If u are not sure about the address of an I2C device… google ‘Arduino I2C sniffer’ and that program will tell you what I2C addresses are connected.
    Check out the pics I added for more detail
    Good luck

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: