SainSmart LCD Module For Arduino 20 X 4, PCB Board -- No Code Works :(

I just got this in the mail from amazon today, there’s no documentation (as many others who have purchased it commented on the product page). However, someone was kind enough to write some sample code and give advise:

However, this didn’t work for me, so I took a look at this:

// --------------------------------------
// i2c_scanner
//
// Version 1
// 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.
// Version 2, Juni 2012, Using Arduino 1.0.1
// Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26 2013
// V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
// by Arduino.cc user Krodal.
// Changes by louarnold removed.
// Scanning addresses changed from 0...127 to 1...119,
// according to the i2c scanner by Nick Gammon
// http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
// As version 4, but address scans now to 127.
// A sensor seems to use address 120.
// 
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#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 = 1; 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(5000); // wait 5 seconds for next scan
}

This is to find the address of an I2C device, and my address is 0x27

So then I found this code, and switched out my numbers in the places he said (with no avail):

I’m using an Uno like they were. If anyone had this (or a similar issue) and can hopefully get me pointed in the right direction that would be awesome! I’m planning to use this to display temperatures from a series of sensors that I already have set up.

I just got this in the mail from amazon today, there's no documentation (as many others who have purchased it commented on the product page).

You are more likely to get constructive help rather than guesses if you were a bit more specific about exactly what 'this' refers to.

You appear to be dealing with an I2C adapter and on virtually any page of this forum you will find someone that has had problems getting one of these to work. Unfortunately those threads aren't always obvious since the authors frequently don't mention I2C in the topic heading. Neither did you.

Here are some resources:

Currently the malpartidia LiquidCrystal_IC2 library is the library of choice. You can get it here: FM New LiquidCrystal

Use the sketch found here i2cLCDguesser to determine the parameters to use with that library.

Use the tutorials found here LCD Displays (Blue and YELLOW) with I2C/TWI Interface to get started using the library.

Don

Currently the malpartidia LiquidCrystal_IC2 library is the library of choice. You can get it here: FM New LiquidCrystal

Use the sketch found here i2cLCDguesser to determine the parameters to use with that library.

Use the tutorials found here LCD Displays (Blue and YELLOW) with I2C/TWI Interface to get started using the library.

Thanks! Unfortunately I already saw these, and they weren’t much help. I tried adjusting the contrast, but that didn’t work. I looked at a I2C ID Checker and determined that the 20x4 display has a ID of 0x27. I’ve updated the LiquidCrystal_I2C to 1.2.1, but that didn’t help either. The IDE does not seem to be liking lcd.//any command. Would you possibly happen to know why?

I still don't know what specific device you are trying to get working.

It's hard to tell what is wrong with a sketch when you only provide one line of code. Many errors are caused by stuff that is wrong in preceding lines. It would also help if you provided the error message as well.

In this case I suspect that the IDE is expecting something after 'lcd.' . There's a hint in the comment.

Don

I finally found code that kind of works, only issue being it displays 00 on the third line of the screen…

The product I bought is this http://www.amazon.com/gp/product/B003B22UR0/ref=cfb_at_prodpg

This is the code I am using, but when I try to modify it (to make it work for my own needs) it freaks out.

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

LiquidCrystal_I2C lcd(0x3F,20,4);  

void setup()   
{
  Serial.begin(9600);
  lcd.init();                      // initialize the lcd 

  // Print our characters on the LCD
  lcd.backlight();  //Backlight ON if under program control
  lcd.setCursor(2,0); //Start at character 3 on line 0
  lcd.print("1 sec delays??");
  delay(1000);
  lcd.setCursor(2,1);
  lcd.print("From YourDuino");
  delay(1000);  
  lcd.setCursor(0,2);
  lcd.print("20 by 4 Line Display");
    delay(1000); 
  lcd.setCursor(0,3);
  delay(1000);   
  lcd.print("http://YourDuino.com");
}

void loop()  
{
  {
    // when characters arrive over the serial port...
    if (Serial.available()) {
      // wait a bit for the entire message to arrive
      delay(100);
      // clear the screen
      lcd.clear();
      // read all the available characters
      while (Serial.available() > 0) {
        // display each character to the LCD
        lcd.write(Serial.read());
      }
    }
  }
}

My code (I’m trying this on a different computer, I was booted off of the previous one I was using)

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

LiquidCrystal_I2C lcd(0x3F,20,4);  

void setup()   
{
  Serial.begin(9600);
  lcd.init();                      // initialize the lcd 

  // Print our characters on the LCD
  lcd.backlight();  //Backlight ON if under program control
  lcd.setCursor(0,1); //Start at character 3 on line 0
  lcd.print("Aquaponics Computer");
  delay(250);
  lcd.setCursor(0,2);
  lcd.print("Starting Up...");
  delay(1000);
  lcd.clear();
  lcd.setCursor(0,1);
  lcd.print("Starting Up...");
  delay(1000); 
  lcd.setCursor(0,1);
  lcd.print("Hello!");
  lcd.setCursor(0,1);
  lcd.print("Requesting");
  lcd.setCursor(0,2);
  lcd.print("Temperatures");
  lcd.clear;
}

void loop()  
{
}

And my error for this is:
sketch_nov28a.ino: In function ‘void setup()’:
sketch_nov28a:29: error: statement cannot resolve address of overloaded function

This is the code I am using, but when I try to modify it (to make it work for my own needs) it freaks out.

Is that a technical term?

LiquidCrystal_I2C lcd(0x3F,20,4);

Is this what the i2cLCDguesser recommended?

Why don't you just try to display a simple message on one line get that working? Then add a second line, etc.

Also, if you end with lcd.clear you won't see much on the display.

Don

TobyTobyo:
My code (I’m trying this on a different computer, I was booted off of the previous one I was using)

#include <Wire.h> 

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F,20,4);

void setup() 
{
  Serial.begin(9600);
  lcd.init();                      // initialize the lcd

// Print our characters on the LCD
  lcd.backlight();  //Backlight ON if under program control
  lcd.setCursor(0,1); //Start at character 3 on line 0
  lcd.print(“Aquaponics Computer”);
  delay(250);
  lcd.setCursor(0,2);
  lcd.print(“Starting Up…”);
  delay(1000);
  lcd.clear();
  lcd.setCursor(0,1);
  lcd.print(“Starting Up…”);
  delay(1000);
  lcd.setCursor(0,1);
  lcd.print(“Hello!”);
  lcd.setCursor(0,1);
  lcd.print(“Requesting”);
  lcd.setCursor(0,2);
  lcd.print(“Temperatures”);
  lcd.clear;
}

void loop() 
{
}




And my error for this is:
sketch_nov28a.ino: In function 'void setup()':
sketch_nov28a:29: error: statement cannot resolve address of overloaded function

To start with, the error message tells you line 29 is FUBAR. Try change

lcd.clear;
change to
lcd.clear();

I think still pointless sketch if you actually look what it will do…

Does this work as expected?

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

LiquidCrystal_I2C lcd(0x27,20,4);  

void setup()   
{
  Serial.begin(9600);
  lcd.init();                      // initialize the lcd 

  // Print our characters on the LCD
  lcd.backlight();  //Backlight ON if under program control
  lcd.setCursor(0,1); //Start at character 0 on line 1
  lcd.print("Aquaponics Computer");
  delay(250);
  lcd.setCursor(0,2);
  lcd.print("Starting Up...");
  delay(1000);
  lcd.clear();
  lcd.setCursor(0,1);
  lcd.print("Starting Up...");
  delay(1000);
  lcd.clear();
  lcd.setCursor(7,1);
  lcd.print("Hello!");
  lcd.setCursor(5,3);
  lcd.print("Requesting");
  lcd.setCursor(4,4);
  lcd.print("Temperatures");
  //lcd.clear();
}

void loop()  
{
}

Slow down, study your sketch, especially check lines of code with compiler errors. Try this when drunk, it is much more entertaining if just starting out with Arduino :wink: :grin:

Regards,

Graham

Thanks guys! I know this is really pointless right now, I just want to see it work on a more basic level before I up. Unfortunately, this is still not working. My lcd screen goes dark after uploading. When I finally make it go bright again (by unplugging it and plugging it back in), it will flicker a few times before giving up...

I removed the last lcd.clear(); from the void setup, and changed all the delays to 5000 in order for me to see if maybe that was the issue (I'm new to screens) and that didn't help.

On the back of my module, I have GND, VCC, SDA and SCL, with VCC in the 5V on my Uno, the SCL in A5 and SDA in A4.

Graham, I appreciate your sample code, however I am getting the same issues as I stated above. Any ideas?

his is the code I am using, but when I try to modify it (to make it work for my own needs) it freaks out.

Is that a technical term?

It is now.

please forgive me if i add to the confusion. i have the same setup and am getting a different error when i compile the previous users code.

it is an error that i have gotten before and don't understand what causes it

here is the error dump

This report would have more information with "Show verbose output during compilation" enabled in File > Preferences. Arduino: 1.0.6 (Windows XP), Board: "Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328"

sketch_nov28d:4: error: invalid conversion from 'int' to 't_backlighPol' ----- the above line is the problem for me---------

and yes i do have the newLiquidCrystal lib installed

sketch_nov28d:4: error: initializing argument 3 of 'LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t, uint8_t, t_backlighPol)' C:\Program Files\Arduino\libraries\LiquidCrystal/LiquidCrystal_I2C.h: In function 'void setup()': C:\Program Files\Arduino\libraries\LiquidCrystal/LiquidCrystal_I2C.h:154: error: 'int LiquidCrystal_I2C::init()' is private sketch_nov28d:9: error: within this context

I hadn’t realised what I was getting into with this!! Sainsmart strikes again… :stuck_out_tongue: :roll_eyes:

After extensive searching, I came across a library and example made for the exact board you bought on amazon, I have reposted it here.

Good luck, let is know if it works, it might help others.

Regards,

Graham

amazon_sainsmart_i2c_lcd_4x20_demo.zip (26.1 KB)

Quote

Quote

his is the code I am using, but when I try to modify it (to make it work for my own needs) it freaks out.

Is that a technical term?

It is now.

If you really want to get this resolved you should consider answering the other questions as well as the rhetorical one.

Don

Hey Graham,

When I use that code and substitute the libraries on that with the libraries I’ve already downloaded, I get this error.

In file included from amazon_sainsmart_i2c_lcd_4x20_demo.ino:2:
C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:34:19: error: I2CIO.h: No such file or directory
C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:35:17: error: LCD.h: No such file or directory
In file included from amazon_sainsmart_i2c_lcd_4x20_demo.ino:2:
C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:39: error: expected class-name before ‘{’ token
C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:53: error: ‘t_backlighPol’ has not been declared
C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:70: error: ‘t_backlighPol’ has not been declared
C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:93: error: ‘t_backlighPol’ has not been declared
C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:134: error: ‘t_backlighPol’ has not been declared
C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:196: error: ‘I2CIO’ does not name a type
C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:110: error: ‘LCD_5x8DOTS’ was not declared in this scope
amazon_sainsmart_i2c_lcd_4x20_demo:8: error: ‘POSITIVE’ was not declared in this scope
amazon_sainsmart_i2c_lcd_4x20_demo.ino: In function ‘void slow_print(char*)’:
amazon_sainsmart_i2c_lcd_4x20_demo:19: error: ‘class LiquidCrystal_I2C’ has no member named ‘print’
amazon_sainsmart_i2c_lcd_4x20_demo.ino: In function ‘void loop()’:
amazon_sainsmart_i2c_lcd_4x20_demo:45: error: ‘class LiquidCrystal_I2C’ has no member named ‘home’
amazon_sainsmart_i2c_lcd_4x20_demo:46: error: ‘class LiquidCrystal_I2C’ has no member named ‘clear’
amazon_sainsmart_i2c_lcd_4x20_demo:51: error: ‘class LiquidCrystal_I2C’ has no member named ‘setCursor’
amazon_sainsmart_i2c_lcd_4x20_demo:55: error: ‘class LiquidCrystal_I2C’ has no member named ‘setCursor’
amazon_sainsmart_i2c_lcd_4x20_demo:58: error: ‘class LiquidCrystal_I2C’ has no member named ‘setCursor’

When I put my libraries that I’m using back in, I just get this error:
amazon_sainsmart_i2c_lcd_4x20_demo:8: error: ‘POSITIVE’ was not declared in this scope

It’s having an error with this line of code:

LiquidCrystal_I2C lcd(MY_I2C_ADDR, MY_BACKLIGHT_PIN, POSITIVE);  // create an instance of the lcd display (positive/transmissive led backlight)

However, when I change positive to anything else (in this instance, HIGH), it compiles, but my LCD Screen does not carry out what the code is saying:

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


#define MY_I2C_ADDR 0x27
#define MY_BACKLIGHT_PIN 3

LiquidCrystal_I2C lcd(MY_I2C_ADDR, MY_BACKLIGHT_PIN, HIGH);  // create an instance of the lcd display (positive/transmissive led backlight)



void slow_print(char *text)
{
  char out_buf[2];
  out_buf[1] = '\0';   // terminate the c string (this string will always be 1 char with a trailing 0-byte)
  
  for (int i=0; i<strlen(text); i++) {
    out_buf[0] = text[i];
    lcd.print(out_buf);
    delay(50);
  }

}   


void setup()
{

  Serial.begin(9600);
  Serial.println("hello bryan - arduino with lcd testing...");


  lcd.begin(20,4);               // initialize the lcd 

}





void loop()
{


  lcd.home ();                   // go home
  lcd.clear();
  lcd.setBacklight(1);

  slow_print("+------------------+");

  lcd.setCursor(0, 1);        // go to the next line
  slow_print("hello BRYAN!");


  lcd.setCursor(6, 2);        // go to the next line
  slow_print("hd44780");

  lcd.setCursor(4, 3);        // go to the next line
  slow_print("from amazon.com");


  for (int i=0; i<5; i++) {
    lcd.setBacklight(0);
    delay(100);
    lcd.setBacklight(1);
    delay(300);
  }    

  delay(1000);
  lcd.setBacklight(0);
  delay(500);
  
  
  
  // hang here and block
  while (1) {
  }
  
}

Don, my I2C ID guesser recommended 0x27, I just accidentally copy-pasted the wrong ID, since I originally assumed that the ID of the sample code was the same as mine. I’m retrying it again with 0x27, but when I use this:

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

LiquidCrystal_I2C lcd(0x27,20,4);  

void setup()   
{
  Serial.begin(9600);
  lcd.init();                      // initialize the lcd 

  // Print our characters on the LCD
  lcd.backlight();  //Backlight ON if under program control
  lcd.setCursor(0,1); //Start at character 0 on line 1
  lcd.print("Aquaponics Computer");
  delay(250);
  lcd.setCursor(0,2);
  lcd.print("Starting Up...");
  delay(1000);
  lcd.clear();
  lcd.setCursor(0,1);
  lcd.print("Starting Up...");
  delay(1000);
  lcd.clear();
  lcd.setCursor(7,1);
  lcd.print("Hello!");
  lcd.setCursor(5,2);
  lcd.print("Requesting");
  lcd.setCursor(4,3);
  lcd.print("Temperatures");
  //lcd.clear();
}

void loop()  
{
}

It compiles but my LCD screen will turn on for 2 seconds, then turn off until I re-upload the code again, and then is will turn on for another 2 seconds then turn off.

Place the entire folder in your sketch folder…NOT LIBRARIES!!!.. It compiles without error for UNO. I have no LCD/liquid crystal libraries in my libraries folder, just that whole folder in my sketch folder. Try that?

Regards,

Graham

I did what you said. With the amazon code you posted

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


#define MY_I2C_ADDR 0x27
#define MY_BACKLIGHT_PIN 3

LiquidCrystal_I2C lcd(MY_I2C_ADDR, MY_BACKLIGHT_PIN, POSITIVE);  // create an instance of the lcd display (positive/transmissive led backlight)



void slow_print(char *text)
{
  char out_buf[2];
  out_buf[1] = '\0';   // terminate the c string (this string will always be 1 char with a trailing 0-byte)
  
  for (int i=0; i<strlen(text); i++) {
    out_buf[0] = text[i];
    lcd.print(out_buf);
    delay(50);
  }

}   


void setup()
{

  Serial.begin(9600);
  Serial.println("hello bryan - arduino with lcd testing...");


  lcd.begin(20,4);               // initialize the lcd 

}





void loop()
{


  lcd.home ();                   // go home
  lcd.clear();
  lcd.setBacklight(1);

  slow_print("+------------------+");

  lcd.setCursor(0, 1);        // go to the next line
  slow_print("hello BRYAN!");


  lcd.setCursor(6, 2);        // go to the next line
  slow_print("hd44780");

  lcd.setCursor(4, 3);        // go to the next line
  slow_print("from amazon.com");


  for (int i=0; i<5; i++) {
    lcd.setBacklight(0);
    delay(100);
    lcd.setBacklight(1);
    delay(300);
  }    

  delay(1000);
  lcd.setBacklight(0);
  delay(500);
  
  
  
  // hang here and block
  while (1) {
  }
  
}

I get the same blinking as before.

However, with my code I get:

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

LiquidCrystal_I2C lcd(0x27,20,4);  

void setup()   
{
  Serial.begin(9600);
  lcd.init();                      // initialize the lcd 

  // Print our characters on the LCD
  lcd.backlight();  //Backlight ON if under program control
  lcd.setCursor(0,1); //Start at character 0 on line 1
  lcd.print("Aquaponics Computer");
  delay(250);
  lcd.setCursor(0,2);
  lcd.print("Starting Up...");
  delay(1000);
  lcd.clear();
  lcd.setCursor(0,1);
  lcd.print("Starting Up...");
  delay(1000);
  lcd.clear();
  lcd.setCursor(7,1);
  lcd.print("Hello!");
  lcd.setCursor(5,2);
  lcd.print("Requesting");
  lcd.setCursor(4,3);
  lcd.print("Temperatures");
  //lcd.clear();
}

void loop()  
{
}

LEDS_2014_11_29:4: error: ‘LiquidCrystal_I2C’ does not name a type
LEDS_2014_11_29.ino: In function ‘void setup()’:
LEDS_2014_11_29:9: error: ‘lcd’ was not declared in this scope

Any ideas?

Does not name a type, and not declared in this scope errors are because of missing libraries.

Are you aware of the difference between #include “??” and #include <??> ?

Sorry, I cannot help any further, I have seen so many people having so many problems with that display, I don’t have any further suggestions.

Best of luck!

Regards,

Graham

Graham, what is the major difference between “??” and <??>? I’d like to thank you for your help, I’m thinking about contacting SainSmart and doing a return/exchange. If I return it, I think I’m going to get this module: http://www.amazon.com/RioRand-trade-Module-Arduino-White/dp/B00GZ6GK7A/ref=sr_1_1?ie=UTF8&qid=1417288411&sr=8-1&keywords=riorand+lcd

Do either one of you know if anyone has had issues with this one? Or could you recommend me another LCD (preferably 20 x 4 and under $15USD)?

Thanks so much for your help,
Luke

There's no reason to return the module. Just stop dealing with ancient libraries.

Don, my I2C ID guesser recommended 0x27 . . .

The i2cLCDguesser sketch that I recommended will give you the pin connections that you need to get the up-to-date version of FMs library to work with your adapter.

Place the entire folder in your sketch folder..............NOT LIBRARIES!!!..........

It would be a better idea to put the library where the current version of the IDE expects to find it. http://arduino.cc/en/Guide/Libraries

Don

It looks like the LCD module you linked to in reply #15 is a regular 20x4 without an I2C adapter. It should work properly using the LiquidCrystal library supplied with every Arduino IDE since v0017.

You could just de-solder your current display from its I2C adapter and achieve the same result without the postage.

Don

"Try this, try that, etc.." is nothing but guessing and I would ignore that type of advice. That is not a good way to get something up and working. It wastes time and can create frustration.

What I'm seeing is a mixing up of different libraries and sketches. You must stick with a single library and then use sketches that are written for that library. i.e. you can't use a sketch written for one LiquidCrystal_IC2 library on a another LiquidCrystal_I2C library.

I'm also seeing the use of libraries other than fm's library.

You cannot install multiple of these libraries at the same time either. If you install one, you must un-install and completely remove it when using another/drifferent library. (also you must exit and restart the IDE when installing/removing libraries) This is because of the way the IDE works and collisions/duplicates of header files within the libraries.

While the different libraries may use the same header file name, the libraries work differently and have different APIs.

That is why you are seeing strange types of errors.

My recommendation is to use fm's library as that one can be made to work with any of the PCF8574 based backpacks. Make sure to remove any/all of the other i2c lcd libraries. Install fm's library in your sketchbook/libraries directory and name the directory for fm's library "LiquidCrystal" as this will ensure that it overrides the IDEs built in "LiquidCrystal" library. Fill in the constructor in your sketch with the pin/bit numbers depending on the wiring of your backpack. If you are unable to see the PCB traces to determine the wiring of your backpack to come up with the proper numbers, you can run the guesser sketch referenced earlier and it will try various combinations to come up with the wiring for your backpack.

If the guesser sketch doesn't compile, then there is an installation issue of fm's library.

This entire process should take less than 10 minutes.

--- bill

I hope you can convince him. He certainly wouldn’t listen to me.

Don