Subscribe to Arduino Academy and start learning today for FREE!

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:

16×2 Display
20×4 Display

I2C LCD Library – https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads

Become the Maker you were born to be. Try Arduino Academy for FREE!

You can verify the I2C address of any connected I2C device with the following sketch:
I2C Scanner code – http://playground.arduino.cc/Main/I2cScanner#.UwvAz_ldXD4

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 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

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.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
lcd.setCursor (0,0); // (column, row)
lcd.print(“SainSmart”);
lcd.setCursor (0,1);
lcd.print(“I2C 16×2”);
}

void loop()
{

}

Become the Maker you were born to be. Try Arduino Academy for FREE!

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Archives

0
Would love your thoughts, please comment.x
()
x