Monday, February 24, 2014

SainSmart I2C LCD

It seems a lot of folks are having problems getting the SainSmart I2C LCD working. This is a shame, as the I2C LCD only uses 2 data lines, A4 (SDA) & A5 (SCL), on the UNO, or 20 (SDA) & 21 (SCL) on the MEGA, in addition to +5v and Gnd.

Well, there is a good reason for the difficulty!

The published I2C address is wrong.

A friend of mine sent me a unit he thought was defective, but doing some research, I found that the correct address is 0x3F. Thank you ianbren for a sample sketch I modified for this tutorial:

16x2 Display
20x4 Display

I2C LCD Library -

You can verify the I2C address of any connected I2C device with the following sketch:
I2C Scanner code -

Sample Code:

** NOTE: Tested on Arduino Uno whose I2C pins are A4==SDA, A5==SCL

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

#define I2C_ADDR 0x3F // <<----- Add your address here. Find it from I2C Scanner
#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

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); // or (20,4)

// Switch on the backlight
lcd.setCursor (0,0); // (column, row)
lcd.setCursor (0,1);
lcd.print("I2C 16x2");

void loop()


Related Posts Plugin for WordPress, Blogger...