Go Down

Topic: Finding workable code for 20x4 LCD with backpack (Read 1 time) previous topic - next topic


I acknowledge  the many ways I am being contradictory.
So here is the code which has been uploaded satisfactorily and with the backlight lit, but with no text showing:

Code: [Select]
** 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
** Edward Comer
** LICENSE: GNU General Public License, version 3 (GPL-3.0)
** sain_lcd_2.ino
** Simplified and modified by Andrew Scott for Arudino 1.0.1, Arudino Uno R3.
** NOTE: I2C pins are A4 SDA, A5 SCL
** Don't forget to use the new LiquidCrystal Library.

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

#define I2C_ADDR    0x3F  // Define I2C Address where the SainSmart LCD 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

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

void setup()
 lcd.begin (20,4);
 // Switch on the backlight

 // Position cursor and write some text
 lcd.home ();                   // go to the first line, first character
 lcd.print("SainSmart I2C tester"); 
 lcd.setCursor ( 0, 1 );        // go to the 2nd line
 lcd.print("It's Working!");
 lcd.setCursor ( 0, 2 );        // go to the third line
 lcd.print("Sainsmarts docs suck");
 lcd.setCursor ( 0, 3 );        // go to the fourth line
 lcd.print("Nice LCD Though. ");

void loop()


Sorry I think you are a troll and doing this deliberately, surly no one can be as "intelligent "as you are coming across. I will not look at this thread any more.


I'm sorry you feel that way, but I don't blame you for dropping me   I'm a 91 year old, trying to learn something, but this world and its tech language are too much for me.  Thanks for being patient but I guess enough is enough. (I don't know what a "troll" is.) Thanks.............


I think you mixed sda and scl wires

sda goes to a4
scl goes to a5



These i2c displays can be tricky because there is no standard relationship of the pins on the chip to the pins of the lcd. Fortunately, there is a new "plug and play" library which will simplify the use of these devices.

Use the library manager to install a library called hd44780.h.  If you are not using a version of the ide which suports the library manager, I suggest you update to a current ide.

You can also get it from https://github.com/duinoWitchery/hd44780

After you have the library installed, try this sketch

Code: [Select]
#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h> // include i/o class header

hd44780_I2Cexp lcd; // declare lcd object: auto locate & config display for hd44780 chip

void setup()
  // initialize LCD with number of columns and rows:
  lcd.begin(20, 4);

  // Print a message to the LCD
  lcd.print("Hello, World!");

void loop()
  lcd.setCursor(0, 1);
  lcd.print(millis() / 1000);

If this does not get you going, run the diagnostic sketch in the library examples.


Post the results of this diagnostic test. I suggest that you start a new thread in the Display section of the forum with those results.


Cattledog, you must understand I am a very slow student here, as evidenced by the trouble I got in to by my ignorance shown with the patient gentleman above.                               

I have installed a library from the Library Manager,under the heading of "Liquid Crystal by Arduino, Adafruit version 1.07 INSTALLED".

What else do I do to make hd44780.h appear in my library?  Your sketch won't work without it, and I can't find it.

Thanks for your response.  I hope I don't try your patience.


I have installed a library from the Library Manager,under the heading of "Liquid Crystal by Arduino, Adafruit version 1.07 INSTALLED".
Use the library manager to find a library called hd44780.h. It is by Bill Perry.

If you type in hd44780 into the search box of the library manager is shows as the third library from the top.


Thanks, cattledog; you saved me,after so many weeks of being confused.  Here is the sketch I ended up with; I don't know what you mean by posting it elswhere, but this should let you know the conclusion to your very much appreciated advice:

Code: [Select]

//good sketch.....KEEP..............

#include <Wire.h>
#include<hd44780ioClass/hd44780_I2Cexp.h>  //include i/o class header

hd44780_I2Cexp lcd;  //declare lcd object:  auto locate & config display for

void setup() {
  // put your setup code here, to run once:
  lcd.begin(20, 4);          //initialize LCD with number of columns and rows:
  lcd.print("Hello, World!");

void loop() {
  lcd.setCursor (0, 1);                         
  lcd.print("WHAT HAPPENED?");
  lcd.setCursor(0, 2);
  lcd.print("Can we help you?");
  lcd.setCursor(0, 3);
  lcd.print("sorry, we're broke");


I  would think there are many others who can use your discovery.


Good job getting your display running.

It's unfortunate that you posted in the Audio section of the forum instead of Displays. Your problem would have been solved sooner in "Displays".  Bill Perry actively monitors that section, and the hd44780 library which was written by him is the "go to" solution for people having problems getting i2c lcd displays up and running.

With your next problem, You do need to give some consideration as to where in the forum you are going to post.

Go Up