SainSmart 20 x 4 LCD wanting to use I2C from Arduino Uno

You did use my New LiquidCrystal library right?

The whole thing is that these folks sell their stuff and rely on someone else to sort it out for them. The link in the LCD product page is not for my library (didn't check). But if it was, they could at least mention how they've mapped the I2c extender pins to the LCD to simplify the initialisation and use of what they sell!

It is a zipped image of my library the one they have on their site! http://www.sainsmart.com/home-page-view/sainsmart-iic-i2c-twi-serial-2004-20x4-lcd-module-shield-for-arduino-uno-mega-r3.html

They have even writen a sample sketch to go with it that is not correctly initialised as it uses 0x27 as its base address as opposed to 0x3F used by you LCD module. The sample sketch is called "sainlcdtest".

/*
** 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(HIGH);
  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 By Edward Comer");
  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);
}

How intersting!

FM,

Yes...your Library you were trying to Direct me to was the same Andrew was......and the one sainsmart has you download is the same as well.

Here is what i was doign wrong all along! So In the beginning I had my I2C scanner running so I knew it was address 0x3F i was communicating with right?

Well when I had first downloaded that new LiquidCrystal Library...I discarded the other liquidCrystal library that is in 1.0.1 but what I was doing wrong: I didn't discard the LiquidCrystal_I2C library I had downloaded before...it kept wanting to use that one......because the LiquidCrystal_i2c.h and LCD.h is already in the new LiquidCrystal library.....Now I just have to tinker with the code to make it say what I want in the loop etc...

But you guys have been so great and patient...I REALLY APPRECIATE it.....

Thanks to FM and Andrew......

I was going to mention...about the sainsmart stuff....forget their 0x27 garbage! you need to verify the I2C address for the device you're communicating with via this I2C scanner code:

// i2c_scanner
//
// This program (or code that looks like it)
// can be found in many places.
// For example on the Arduino.cc forum.
// The original author is not know.
//
// This sketch tests the standard 7-bit addresses
// from 0 to 127. Devices with higher bit address
// might not be seen properly.
//
// Adapted to be as simple as possible by Arduino.cc user Krodal
//
// June 2012
// Using Arduino 1.0.1
//

#include <Wire.h>

void setup()
{
Wire.begin();

Serial.begin(9600);
Serial.println("\nI2C Scanner");
}

void loop()
{
byte error, address;
int nDevices;

Serial.println("Scanning...");

nDevices = 0;
for(address = 0; address <= 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();

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

nDevices++;
}
else if (error==4)
{
Serial.print("Unknow error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");

delay(8000); // wait 8 seconds for next scan
}

Then open the serial monitor after uploading and check the address.....mine was 0x3F

@Aaron_dyer - thanks for your comments, much appreciated.
This whole thing of not publishing correct information about device addresses is a bit of a bother.

What I am pleased about is that they've linked the library in and respected the Open Source Creative Commons license! Cool.

FM,

Is that you in your picture for your profile? It looks like a girl I went to High school with

Aaron_dyer:
FM,

Is that you in your picture for your profile? It looks like a girl I went to High school with

Lets just say that the picture was taken 22 odd years ago.
Lets also say that fm = fmalpartida

Pretty!

Aaron_dyer:
Pretty!

Thanks. :*

:wink: you know it too

Ya, that was the idea, to use the SPI printouts for a GPS to interface the I2c LCD as well as our other circuitry......ill post my YouTube video of it all later today or tomorrow....

Pinouts*

fm:
This whole thing of not publishing correct information about device addresses is a bit of a bother.

What I am pleased about is that they've linked the library in and respected the Open Source Creative Commons license! Cool.

Hey, Thanks for all your work and support on the library and being willing to support different devices. I have the SainSmart LCD 2004 also and was able to get mine working by following this thread. My device uses 0x27 as the address.

/---When I asked the people at Sainsmart why their code didn't work, they sent me some other documentation etc that didn't work. I don't understand how they can sell products marketed specifically at the Arduino market and not have legitimate support. ---/

Is there a way to have a 16x2 display with address 0x20 and a 20x4 with address 0x27 on the same I2C bus and be able to differentiate them in the code??? sending each different information etc.?

Yes, there is no problem what so ever. Just create two objects (variables) initialising them correctly and they will work. I have use a chain of 4 devices: 2 lcds and keyboards.

I had same problem reported by others using the SainSmart examples and libraries. Finally found this and followed Andrew's advice and now it works! Must agree with displayed message.

Thanks guys!

After blundering about the internet for a while trying to get this Sainsmart 2004 display working with help for their 'excellent documentation' :~, I stumbled on this thread.

A few minutes and I was up & running.

Registered on the forum just to say thanks Andrew!

Hello Guys,

marry christmas and sorry for my bad english but i got yesterday the SainSmart Mega 2560 with LCD2004 and Sensorshield V5.0. After assembling the boards, i started the I2C-Scanner but I didn't found a device! I'm 100% sure that my wire-connection is correct and the sensor-shield-board can't also be wrong mounted without destroying. After trying some libraries I decided to demount the sensor-shield and connecting the LCD2004 directly to the SainSmart (GND, 5V, SDA and SCL) and started the I2C-Scan again and got the address 0x3F (happy!!!).

My question is.... what could by my mistake by assembling the boards? Or is it neccessary to write more code to connect the sensor-shield-board?

Hey everybody! Happy New Year! My new sainsmart 20x4 LCD showed up today and all I got was the LCD? No documentation and no cable for connecting it to the arduino. Could someone tell me what type of connector I need so I can make a cable? Thanks!

worsethenu:
Hey everybody! Happy New Year! My new sainsmart 20x4 LCD showed up today and all I got was the LCD? No documentation and no cable for connecting it to the arduino. Could someone tell me what type of connector I need so I can make a cable? Thanks!

You will get a more reliable answer if you post a better description or a link to the actual device.

Don

Haha, sorry. good call.