Arduino I2C LCD example

This example was based on an Arduino UNO and a kit I purchased from Amazon UK which contained various LCD displays, sadly the instructions were not great and I couldn’t get the LCD working but a bit of digging and I struck gold and managed to get the LCD working. Thanks to the Arduino forums for this one

 

The LCD was this one SainSmart IIC LCD1602 Module Display For Arduino UNO MEGA R3 *New *

First of all I connected up the VCC and GND and then I connected up the SDA of the LCD to A4 and SCL to A5. This is for an Arduino UNO

Now you need to get the I2C address of your LCD

Each device has an I2C address that it uses to  accept commands or send messages.

Load the sketch over at http://arduino.cc/playground/Main/I2cScanner and follow the instructions to use it.  By opening up the serial monitor window after you upload the sketch, the Arduino will scan the address range looking for a reply.

Take a note of the address that you have found,  its used in the code example below , #define I2C_ADDR 0x3F

Libraries

https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads – rename the LiquidCrystal library in the Arduino installation libraries and replace with this one.

 

Code Example

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR 0x3F
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

int n = 1;

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

void setup()
{

lcd.begin (16,2);
// Switch on the backlight
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
lcd.home ();
lcd.print(“Hello World”);
}

void loop()
{

//goto start of 2nd line and display a number updating every second
lcd.setCursor (0,1);
lcd.print(n++,DEC);
delay(1000);
}

 

Here is the LCD in action connected to my Arduino, note I used a sensor shield for connecting wires from the Arduino to the LCD

arduino and i2c lcd
arduino and i2c lcd

 

 

 

Previous articleBasic Netduino example
Next articleArduino and LCD4884 shield