Sainsmart LCD2004 newbie question - can't get it working

I have a Sainsmart LCD2004 with 20x4 display.

I've removed the LiquidCrystal library that came with my arduino software, and installed instead fmalpartida's new-liquidcrystal library.

I have an Arduino Uno R3, and I connected the LCD2004's VCC to Uno 5V, LCD GND to Uno GND, LCD SDA to Uno A4, LCD SCL to Uno A5.

I tried running this code:

/*
** 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:
** https://bitbucket.org/fmalpartida/new-liquidcrystal 
**
** Edward Comer
** LICENSE: GNU General Public License, version 3 (GPL-3.0)
**
** NOTE: TEsted on Arduino NANO whose I2C pins are A4==SDA, A5==SCL
*/
#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(LOW);
  lcd.home ();                   // go home

  lcd.print("SainSmart I2C tester");  
  lcd.setCursor ( 0, 1 );        // go to the 2nd line
  lcd.print("F Malpartida library");
  lcd.setCursor ( 0, 2 );        // go to the third line
  lcd.print("Test & demonstration");
  lcd.setCursor ( 0, 3 );        // go to the fourth 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);
}

And nothing happens at all. (The backlight is on once I connect VCC and GND, but the display never changes - it just looks like this:

I'm clearly missing something simple... what do I do?

Thanks!

I2C address?
Perhaps 0x20?

Changing I2C_ADDR to 0x20 has no effect.

It looks based on some Amazon reviews like this may have come with a defective I2C board. I'm going to return it. fm, can you recommend a source to buy a LCD display with I2C that will work?

Changing I2C_ADDR to 0x20 has no effect.

Don't just change it: read the datasheet and see what it is.

There are two notations for i2c addresses: somepeople use the 7-bit convention and others the 8-bit convention. so an address of 0b010 0111 (0x27 in 7-bit convention) can be represented at 0b0100 1110 (=0x2e in 8-bit land, and that's actually how it is sent to the device).

So when you see an i2c address of 0x27, you need really to see the bit pattern to be sure.

There are two notations for i2c addresses: somepeople use the 7-bit convention and others the 8-bit convention. so an address of 0b010 0111 (0x27 in 7-bit convention) can be represented at 0b0100 1110 (=0x2e in 8-bit land, and that's actually how it is sent to the device).

I believe you have a typo in there which makes it difficult to follow your explanation. The 0x2e should be 0x4e.

0 1 0 0 1 1 1 (0x27) basic I2C address
0 1 0 0 1 1 1 0 (0x4E) I2C address shifted one bit to the left to allow least significant bit to be used for direction

Don

Edit: And my original correction had a different error (I wrote it as 0x6E) which is all the more reason to just stick with the bit pattern.

Ok, still trying this, on the off chance that it's not actually defective.

I've looked around but can't find a datasheet online for this, and it's soldered on so I can't look and see. How can I figure out what the I2C address is?

I GOT IT! It was 0x3F.

I ran I2C Bus Scanner | Omar Francisco (which didn't work in Arduino v1, but I ran it under 23 and it discovered the I2C device at 0x3F).

@dmd - I was going to suggest to run an I2C scanner to figure out the I2C address before you returned it but you have done that already and you've got it up and running.

LCDs that work, well, I have some in my web but I shouldn't be saying it.

#define I2C_ADDR    0x27  // Define I2C Address where the PCF8574A is

Where did this information come from?

According to the datasheet that I found the possible addresses are as follows:
PCF8574 0 1 0 0 A2 A1 A0 or addresses 0x20 through 0x27
PCF8574A 0 1 1 1 A2 A1 A0 or addresses 0x38 through 0x3F

With the three address lines tied high this would give:
PCF8574 0 1 0 0 1 1 1 or address 0x27
PCF8574A 0 1 1 1 1 1 1 or address 0x3F

So when the documentation was written they used a PCF8574 and when the board was stuffed they used a PCF8574A.

Don

I GOT IT! It was 0x3F.

It pays to read the datasheet, as people would say.

A common mistake for beginners is their unwillingness or inability to read datasheet and they keep trying to get this thing to work, only in vain. A datasheet is like a map to a maze. The chance of a blind person working out of a maze without a map is practically zero.

BTW, 0x00 is the general call address for i2c devices.

Thanks for this thread! Recently received this Sainsmart LCD with no documentation (certainly no datasheet). They did point me to a URL but it didn't help. Anyway after many hours of fiddling changing the address to 03F was the trick. Given this is a Christmas gift for my Grandson the timing was great!

There are a number of things that can go wrong.
I suggest you run this code:
/*
** Example Arduino sketch for SainSmart I2C LCD Screen 16x2
** based on Bitbucket
** by Edward Comer
** LICENSE: GNU General Public License, version 3 (GPL-3.0)
**
** This example uses F Malpartida's NewLiquidCrystal library. Obtain from:
** https://bitbucket.org/fmalpartida/new-liquidcrystal

** Modified - Ian Brennan ianbren at hotmail.com 23-10-2012 to support Tutorial posted to Arduino.cc
** Modified 24/11/15 by Alan Howlett of www.DataTechnologies.co.uk to aid in finding LCD devices on the I2C bus.
** It assumes an LCD might exist on any of the 127 valid addresses and send them a message like "I am on 0x3F".
** If you run this and can't see anything:
** 1. Have a look on Tools, Serial Monitor- do you see a message saying it was found? If not, check your wiring.
** 2. You might need to adjust the contrast screw on the back of the I2C module on your display to see anything!
** Some of this code copied from the I2C_Scanner utility that some kind anonymous person wrote. Thank you, whoever!
*/
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#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

void setup()
{
pinMode(13,OUTPUT);
Serial.begin(9600);
}

void loop()
{
// Send a message to every possible LCD display on the I2C bus
for (int address=0; address<127; address++) {
LiquidCrystal_I2C lcd(address,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
lcd.begin (20,4); //(How many columns, how many rows) in your display
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
lcd.home (); // go to top left position
lcd.print("LCD on 0x");
lcd.print(address, HEX);
lcd.setCursor(0,1);
lcd.print("0x");
lcd.print(address, HEX);
lcd.print(" LCD address");

Wire.beginTransmission(address); //Now check the I2C bus communications
// Wire.write("fred");
int error = Wire.endTransmission(); //Get the error code, if any.

if (error == 0) {
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
Serial.println("--------------------------------------------------------");
Serial.println("");

digitalWrite(13,LOW);
delay(500);
digitalWrite(13,HIGH);
delay(500);
}

  1. You should be able to see on the serial port whether it has found an I2C device, and
  2. If you adjust the contrast on the LCD display (essential!) you should see the address of the display on the display. Always check the contrast- you usually can't see anything useful until it's adjusted.
  3. Write the I2C address on the back of the display with a permanent marker so you won't forget it!

dhenry:
It pays to read the datasheet, as people would say.

It pays not to buy Sainsmart as more people would say!! :wink: :stuck_out_tongue:

The amount of time and effort expended on the forums fixing Saincrap related issues is disproportionate to ANY other supplier of Arduino hardware!! FACT.

Regards,

Graham

Right, first things first, Mr(?s) Howlett.

Before posting code with all good intentions (even three years after the event), go and read the instructions.

Now go back and modify your post (use the "More --> Modify" option to the bottom right of the post) to mark up the code as such so that it can be conveniently and accurately used (not to mention, checked by others).