Example Arduino sketch for SainSmart I2C LCD2004 adapter for HD44780 LCD screens

/*
** Example Arduino sketch for SainSmart I2C LCD2004 adapter for HD44780 LCD screens
** Readily found on eBay or http://www.sainsmart.com/
** The LCD2004 module appears to be identical to one marketed by YwRobot
**
** Address pins 0,1 & 2 are all permenantly tied high so the address is fixed at 0x27
**
** Written for and tested with Arduino 1.0
** This example uses F Malpartida’s NewLiquidCrystal library. Obtain from:
**
** Edward Comer
** LICENSE: GNU General Public License, version 3 (GPL-3.0)
*/
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR    0x27  // Define I2C Address where the PCF8574A is
#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 (20,4);
// Switch on the backlight
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home ();                   // go home
  lcd.print(“SainSmart I2C test”);
  lcd.setCursor ( 0, 1 );        // go to the next line
  lcd.print(“F Malpartida library”);
  lcd.setCursor ( 0, 2 );        // go to the next line
  lcd.print(“Test By Edward Comer”);
  lcd.setCursor ( 0, 3 );        // go to the next line
  lcd.print(“Iteration No: “);
}
void loop()
{
  // Backlight on/off every 3 seconds
  lcd.setCursor (14,3);        // go col 14 of line 3
  lcd.print(n++,DEC);
  lcd.setBacklight(LOW);      // Backlight off
  delay(3000);
  lcd.setBacklight(HIGH);     // Backlight on
  delay(3000);
}
Advertisements

4 responses

  1. Trying to get the LCD2004 module working with Arduino Uno I would love to try this SainSmart sketch but it throws a lot of errors when verified some of which are obscure. I suspect the displayed code is at fault – why can’t I access the original code? I’m hoping there is a sketch out there somewhere which is compatible with this module but I’m not going to find it until I have posted this reply!

  2. Clive Fernando | Reply

    Why I get a error saying can not find LCD.h ?
    I have copied all the files in the libaray.

  3. Adrian the compilation errors come from encoding problems to fix this just delete all the quotations and replace with your own text strings then on TOOLS > Fix Encoding and Reload. This will fix the errors and compile correctly.

  4. Adrian the compilation errors come from encoding problems to fix this just delete all the quoted strings and replace with your own text then on TOOLS menu > Fix Encoding and Reload. This will fix the errors and compile correctly.

    example where it says lcd.print(“SainSmart I2C test”); >> remove all characters between ” ” and input your own text then go tools menu and Fix encoding and reload.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: