Loading...
Pages: [1] 2 3   Go Down
Author Topic: [SOLVED] SainSmart / YwRobot I2C LCD works well  (Read 17209 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 2
Posts: 55
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The sainsmart I2C LCD2004 LCD module works well with Arduino 1.0 with the proper library.

The example and library provided  by sainsmart.com is obsolete and will NOT work with Ardueno 1.0. However, this board works perfectly with F Malpartida's NewLiquidCrystal library.
I posted a working example code below and at: http://pastebin.com/LbjTkvPe

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)
*/
#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);
}

Also, I have attached a reverse engineered schematic to this post. Since I cannot see the board'e reverse side, I suspect that there is, at least, one resistor back there - one to current limit the back-light and two pull-ups for the I2C inputs.

You can also pull the code from the BitBucket repository.
« Last Edit: May 22, 2012, 10:20:14 am by celem » Logged

Málaga, Spain
Offline Offline
Edison Member
*
Karma: 33
Posts: 2017
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Cheers!
Logged

   

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank You for posting this!  This got me rolling.

 smiley-mr-green
Logged

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 17
Posts: 3460
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Also, I have attached a reverse engineered schematic to this post. Since I cannot see the board'e reverse side, I suspect that there is, at least, one resistor back there - one to current limit the back-light and two pull-ups for the I2C inputs.

I believe that some of the Sainsmart devices are ripoffs of the DFRobot boards so you could check your work against the corresponding DFRobot schematic.

By the way at least one of the DFRobot designs has a serious wiring error in terms of the backlight.  You could research this aspect as well.


Don
Logged

Offline Offline
Jr. Member
**
Karma: 2
Posts: 55
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I looked at the I2C 20X4 board at DFRobot and DFRobot, in the spirit of open source, provides a schematic (floresta, thanks for the tip). Based on DFRobot, the back side of the SainSmart board must not only contain a resistor, but also a transistor. The SDA/SCL lines do not have pull-up resistors, as anticipated - but it works, nonetheless.  DFRobot provides their own LiquidCrystal library which contains the LiquidCrystal_I2C routines. I did not test their code against their library (I'll just assume that it works). I did modify their example code to work with F Malpartida's NewLiquidCrystal library and it functions well. Their modified example is:
Code:
//DFRobot.com
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>  // F Malpartida's NewLiquidCrystal library

#define I2C_ADDR    0x27  // Define PCF8574A's I2C Address

#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

#define  LED_OFF  0
#define  LED_ON  1

#define printByte(args)  write(args);

uint8_t bell[8]  = {0x4,0xe,0xe,0xe,0x1f,0x0,0x4};
uint8_t note[8]  = {0x2,0x3,0x2,0xe,0x1e,0xc,0x0};
uint8_t clock[8] = {0x0,0xe,0x15,0x17,0x11,0xe,0x0};
uint8_t heart[8] = {0x0,0xa,0x1f,0x1f,0xe,0x4,0x0};
uint8_t duck[8]  = {0x0,0xc,0x1d,0xf,0xf,0x6,0x0};
uint8_t check[8] = {0x0,0x1,0x3,0x16,0x1c,0x8,0x0};
uint8_t cross[8] = {0x0,0x1b,0xe,0x4,0xe,0x1b,0x0};
uint8_t retarrow[8] = { 0x1,0x1,0x5,0x9,0x1f,0x8,0x4};
  
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);  // initialize the lcd
  // Switch on the backlight
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(LED_ON);
  
  lcd.createChar(0, bell);
  lcd.createChar(1, note);
  lcd.createChar(2, clock);
  lcd.createChar(3, heart);
  lcd.createChar(4, duck);
  lcd.createChar(5, check);
  lcd.createChar(6, cross);
  lcd.createChar(7, retarrow);
  lcd.home();
  
  lcd.setCursor(0, 0);
  for(int i = 0;i < 20; i++)  lcd.printByte(6);
  lcd.setCursor(0, 1);
  lcd.printByte(6);
  lcd.print("   Hello world    ");
  lcd.printByte(6);
  lcd.setCursor(0, 2);
  lcd.printByte(6);
  lcd.print("  i ");
  lcd.printByte(3);
  lcd.print(" arduinos!   ");
  lcd.printByte(6);
  lcd.setCursor(0, 3);
  for(int i = 0;i < 20; i++)  lcd.printByte(6);
//  lcd.clear();

}

void loop()
{

}

I have attached DFRobot's I2C adapter board schematic to this post.

DFRobot may have been the original board designer given their more professional approach of decent documentation, but given China's disregard for intellectual property rights, who knows for sure? Also, DFRobot has and active forum with timely responses by their engineers, and a wiki, which is another plus for their professionalism. DFRobot's board and SainSmart's significantly differ, physically, so if SainSmart copied DFRobot, it was only from their schematic and not the board design.
« Last Edit: May 31, 2012, 08:45:00 am by celem » Logged

UpState NY
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

HI,
Noobie here. I have a Sainsmart LCD2004, The stetch compiles and uploads but nothing happens. The LCD is lite, with two lines a space between them.
I am running a Mega 2560 copy and a V5 senor shield.
 PLEASE HELP
 :~Thanks in advance
 Daka
Logged

Offline Offline
Jr. Member
**
Karma: 2
Posts: 55
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Daka101 - double check your wiring. The circuit only uses four wires so there is very little to go wrong. Are you positive that you properly installed F Malpartida's NewLiquidCrystal library? Note - you have to remove the NewLiquidCrystal library that came with the API - move it elsewhere and retest.
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 230
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
Daka, how did you solve the problem?

I have "exactly" the same problem: 2 black lines, nothing happens on uploading the code.

I put in the folder LiquidCrystal_I2C, with the files of FM

On the sensor shield and on the lcd there descriptions like gnd vcc etc for the 4 cables pins, so im sure i plugged it right :-/

Can someone help me?

This is my 2nd step after using the "blink" example.

What i did:
I redownloaded and unzipped arduino software, i downloaded FM LCD zip, unpacked it and renamed it: LiquidCrystal_I2C then put it in libraries folder.
Started the software, Com3, put in the code given at top, compiled it and uploaded it: 2 black bars in the 4 line display and nothing happens.

Were my steps right?
« Last Edit: June 09, 2012, 07:19:34 am by lax123 » Logged

Málaga, Spain
Offline Offline
Edison Member
*
Karma: 33
Posts: 2017
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@lax123 - the library was designed to replace the current LIquidCrystal library. Therefore, you will have to backup the current LiquidCrystal library somewhere that is not the library directory of the IDE and extract the contents of the library in the LiquidCrystal library folder.

You will then need to configurethe correct I2C address and IO pin mapping to match that of the backpack LCD module.

Which backpack are you using? If it is the one from DFRobot, you should be able to use the same example as above. Also make sure you adjust the trim pot for the LCD contrast.
Logged

   

Offline Offline
Full Member
***
Karma: 1
Posts: 230
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

its still not working,

im using the sainsmart 2004LCD with the shield described by Daka/ the device that is linked first in this topic in first post.

now i tried 2 things: i removed the LiquidCrystal folder, and renamed your fmalpartida-new-liquidcrystal-fc7ac429cfc8 to  LiquidCrystal and put it at its spot.

2nd thing was: i copied over the LiquidCrystal folder content with the files included in your folder.

adjusting the poti turns the bars from invisible over black to white
:-(

uploading the blink example again the bars stay that way, this seems to be like the default for the display
« Last Edit: June 09, 2012, 07:42:47 am by lax123 » Logged

Málaga, Spain
Offline Offline
Edison Member
*
Karma: 33
Posts: 2017
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If you have the schematic or a like, it would be great. I have seen that you are going to need 2 10K pullups on the sca and scl I2C lines to drive it.

With the two schematics posted and the code snippets from the posts, you should be able to get the LCD up and running. The code looks good for the LCD cconfiguration and schematics.
« Last Edit: June 09, 2012, 12:16:46 pm by fm » Logged

   

Offline Offline
Full Member
***
Karma: 1
Posts: 230
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thank you for ur effort.

Can you take a look at this?

http://www.ebay.de/itm/SainSmart-IIC-I2C-TWI-Serial-2004-LCD-Sensor-Shield-V4-For-Arduino-UNO-MEGA-R3-/320922503691?pt=Wissenschaftliche_Ger%C3%A4te&hash=item4ab878ca0b

I wired it as in the picture, there is nothing about extra components that r needed.

U still think i need pullup resistors?

In the pictures of my link i see 2 blue jumpers that r put on the sensorboard, do u know if that could have a purpose or is just an eyecatcher?

I wonder if daka could solve it, because he is exactly facing the same issue.
Or if the author of this topic needed something extra, since he links exactly my LCD2004.



« Last Edit: June 09, 2012, 08:41:28 am by lax123 » Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 230
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

LoL
those jumpers r not for show, they were the problem.
Once i read whats written at those pins it also makes sense ;-) switching from analog to i2c

Maybe they should describe stuff like that somewhere when they sell the product, not to mention the not working code...
« Last Edit: June 09, 2012, 08:49:29 am by lax123 » Logged

UpState NY
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well I have fixed the problem. I am using the V5 sensor brd. It has a header for I2C. Four pins, SCL, SCA,-,and +. That is where I hooked up the connections from the LD2004. Did not work. After emailing SAINSMART. they sent a package of pictures and spec sheets. The pins SCL and SCA ,at the header go to A4 and A5. You have to use the SCA and SCL on the ARDUINO
Here is the picture they sent

Hope this helps
Daka smiley
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 230
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thx for the message daka, but as u can see i solved it too.

Just in case i post a pic of my problem too/ what i didnt see.

Logged

Pages: [1] 2 3   Go Up
Print
 
Jump to: