Connect to i2c

The first option we'll show is how to use the i2c interface on the backpack. We'll be showing how to connect with an Arduino, for other microcontrollers please see our MCP23008 library code for the commands to send to the i2c i/o expander. I2c is nice because it only uses two pins, and you can put multiple i2c devices on the same two pins. So for example, you could have up to 8 LCD backpacks+LCDs all on two pins! The bad news is that you have to use the 'hardware' i2c pin. You can't change those pins and you can't use them for reading analog data. If you absolutely need those two pins, use SPI (see next section)

For this we'll need to connnect four wires: GND, 5V, CLK (clock) and DAT (data).

Connect:

  • 5V to your 5V power pin - don't use 3.3V power, the LCD needs 5V for contrast! The I2C pullups are fairly weak so you can use use 3.3V logic for SDA/SCL even if the board is powered with 5V
  • GND to Ground
  • DAT (SDA) to I2C Data (on the Uno, this is A4 on the Mega it is 20 and on the Leonardo digital 2)
  • CLK (SCL) to I2C Clock (on the Uno, this is A5 on the Mega it is 21 and on the Leonardo digital 3)

Install Adafruit_LiquidCrystal

To begin reading sensor data, you will need to download Adafruit_LiquidCrystal from our github repository. You can do that by visiting the github repo and manually downloading or, easier, just click this button to download the zip

Rename the uncompressed folder Adafruit_LiquidCrystal and check that the Adafruit_LiquidCrystal folder contains Adafruit_LiquidCrystal.cpp and Adafruit_LiquidCrystal.h

Place the Adafruit_LiquidCrystal library folder your arduinosketchfolder/libraries/ folder.
You may need to create the libraries subfolder if its your first library. Restart the IDE.

We also have a great tutorial on Arduino library installation at:
http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use

Load Demo

Restart the IDE and load up the Adafruit_LiquidCrystal->HelloWorld_i2c demo

Upload the sketch. You should see the backlight turn on when the Arduino resets. If you don't see any characters, adjust the Contrast trim potentiometer with a mini-screwdriver until you see the text clearly

The default HelloWorld sketch blinks the backlight as well as updating the text.

If you see the backlight blinking that means your connection to the i2c port is OK but the contrast is too low or too high, or the LCD data pins are not solidly connected.

Check the contrast first by gently twisting the mini trim potentiometer, if that doesn't help, recheck your soldering and resolder all 16 of the LCD pins!

Once you're done, you can remove the blinking LED backlight code:

lcd.setBacklight(HIGH);
delay(500);
lcd.setBacklight(LOW);
delay(500);

Changing the I2C Address


If you want to have more than one MCP23008 device (like more than one backpack+LCD) each one needs to have a unique 'address'. You can set the address by jumpering the A0 A1 and A2 solder jumpers. By default, no jumpers are soldered, giving an address of 0. If you want to have an address of 3 you would solder A0 (bit 0) and A1 (bit 1) for an address of "011" = 3 in binary. Then in the code change:
// Connect via i2c, default address #0 (A0-A2 not jumpered)
LiquidCrystal lcd(0);
to
// Connect via i2c, address #3 (A0&A1 jumpered)
LiquidCrystal lcd(3);
Last updated on 2016-09-12 at 01.33.35 PM Published on 2012-08-27 at 03.43.17 PM