Loading...
Pages: 1 [2] 3   Go Down
Author Topic: [SOLVED] SainSmart / YwRobot I2C LCD works well  (Read 17328 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 41
When you wake up in the morning, set a goal that today you must be better than yesterday. Do it everyday, grow better!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset



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.
[/quote]

I think we think alike.
Logged

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

I know this thread was long buried, but its the first one that came up (and came up repeatedly while searching for an issue I had), so I thought I'd post a reply incase others got stuck the way I did.

I got an LCD2004 board, I2C connection etc, that is a YwRobot job (bought from rcmodelpart369 on ebay - with GY-LCD-V1 labelled on the back).  Except it seems to be a different revision to the ones I've seen elsewhere.  Ends up mine doesnt even respond on I2C address 0x27 as it should, but on address 0x20.  (So one of the first steps of trouble shooting, would be to search for an arduino "I2C Scanner" sketch, which tries to communicate on every address, and lets you know exactly what devices/addresses respond).

I changed the code in the first post of this thread to 0x20, which at least got the screen to respond (back light came on, even managed to get one weird character up eventually), but it didnt really work.  Just before giving up hope, I tried tracing the output of the PCF8574T (on the I2C daughterboard) to the 16pin header on the LCD board.  Although I did it with the help of this simple sketch -:

Code:
#include <Wire.h>

void setup()
{
  Wire.begin(); // join i2c bus
  Serial.begin(9600);  // start serial for output
}

void loop()
{
  Wire.beginTransmission(0x20); // transmit to I2C device 0x20
  Wire.write(0x80);             // sends value byte (In this case setting PCF8574T pin P7 HIGH)
  Wire.endTransmission();     // stop transmitting
  Serial.println("Sent 0x80"); // Let the serial monitor know whats happened
  delay(1000);
  
  Wire.beginTransmission(0x20); // transmit to device 0x20
  Wire.write(0x00);             // writes a 0 (setting all PCF8574T Px pins LOW)  
  Wire.endTransmission();     // stop transmitting
  Serial.println("Sent 0x00");
  delay(1000);

 }

Basically changing the value each time so that a single pin was being flashed high (i.e. 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01), while using a multimeter down each pin of the LCD header until I found which it corresponds too. After that its just a simple matter of modifying the definitions at the start of the example code to correspond to the LCD header pins.  (Just for reference, on the LCD header, pin 11 -> DB4, 12 -> DB5, 13 -> DB6, 14 -> DB7, 16 -> Backlight, 4 -> Rs, 5 -> Rw, 6 -> En).  The above sketch also spits out the value sent to the serial monitor, so you can ascertain if the backlight pin is active high or low (to set the lcd.setBacklightPin() function correctly - mine had to be set NEGATIVE).  The modifications I needed for this unusual YwRobot LCD2004 revision I received are as follows -:

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    0x20  // Define I2C Address where the PCF8574A is

#define BACKLIGHT_PIN     7
#define En_pin  4
#define Rw_pin  5
#define Rs_pin  6
#define D4_pin  0
#define D5_pin  1
#define D6_pin  2
#define D7_pin  3

#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,NEGATIVE);
  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()
{

}

Hope this saves someone hours of hassles, or wondering if they received a dud display!  
« Last Edit: November 01, 2012, 07:32:59 am by avian » Logged

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

Hi, thanks for this post. I have just struck the same problem. Months ago I got a 20x4 i2c lcd with a YwRobot LCM1602 daughter board wth PCF8574T expander chip working without any problems using the liquidcrystal library files from the 'yourduino' site. I just purchased another board from the same place but the daughter board is marked GY-LCD-V1 also with PCF8574T. I too traced the pinouts and realised the differences. I'm a little unclear on what the posted fix is though. Is it a modification to the library files (.h and .cpp) or is it just new code in any main sketch trying to use the lcd ? any advice appreciated. David.
Logged

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

Hi, thanks for this post. I have just struck the same problem. Months ago I got a 20x4 i2c lcd with a YwRobot LCM1602 daughter board wth PCF8574T expander chip working without any problems using the liquidcrystal library files from the 'yourduino' site. I just purchased another board from the same place but the daughter board is marked GY-LCD-V1 also with PCF8574T. I too traced the pinouts and realised the differences. I'm a little unclear on what the posted fix is though. Is it a modification to the library files (.h and .cpp) or is it just new code in any main sketch trying to use the lcd ? any advice appreciated. David.

Hi David,
  
I didnt change anything in the header files or libraries (although I did switch over to F Malpartida's NewLiquidCrystal library, which is backward compatible, but brings with it major speed improvements).  You could make these changes directly in the libraries, but it's not needed.  All thats needed is to define the correct pin out at the start of a sketch.  Thats what these lines do -:


Code:
#define I2C_ADDR    0x20  // Define I2C Address where the PCF8574A is. 0x20 works with the GY-LCD-V1

//  The following defines the pin out of the PCF8574A to the LCD screen.  
// The following values work for the GY-LCD-V1

#define BACKLIGHT_PIN     7  
#define En_pin  4  
#define Rw_pin  5
#define Rs_pin  6
#define D4_pin  0
#define D5_pin  1
#define D6_pin  2
#define D7_pin  3


After that, it should work like any other typical LCD screen.  The only other caveat is that when controlling the backlight, that the pin is active low ( lcd.setBacklightPin(BACKLIGHT_PIN,NEGATIVE); ), so using negative instead of positive was needed there.  

« Last Edit: November 05, 2012, 12:41:03 am by avian » Logged

Indian Ocean
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hope this saves someone hours of hassles, or wondering if they received a dud display!  


Definitely You saved me many more hours than I spend already. Thank You!
What a great analysis of the problem and giving a simple solution!

I just want to point out that the LCD Adapter board I2C lcd1602 - www-mjkdz-com) sold very cheap on ebay ( US$ 3,59 including postage from 1984yht888 ) has exactly the same problem/solution. And the board works (now) without problem also for LCD 20/4 and others!

You MUST use the F Malpartida's NewLiquidCrystal library though!  (and through the other LiquidCristal_I2C out ! of your libraries folder). That had cost me another hour.

Small correction the chip on the board is a PCF8574 not a PCF8574A otherwise the address would be 0x30.

avian thank You again!
« Last Edit: November 10, 2012, 03:07:27 pm by Ogoh_Ogoh » Logged

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

If anyone was still lost with this, two key things which worked for me were setting the address correctly as in my ebay purchase, for me which was
I2C Address: 0x3F

also I was confused with adding the liquid crystal library because in the code
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
are both referenced but they reside in the liquid crystal folder which confused me, but it still works with the libraries not having their own folders. awesome.
Logged

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

Cool, thanks!
Logged

   

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

Hey guys,

its been hours today.................................

Following:
I have a DFRobot 2004, got ist about 5 days ago.
After searching half an hour for a working lib and reading to try address 0x20, i got it working, until today.
When i first used the wrong lib, i just saw two lines fully illuminated.
With the right library and code, i got it working.

i used exactly this code:

Code:
//Please download the Arduino library!
//The link:http://www.dfrobot.com/image/data/DFR0154/LiquidCrystal_I2Cv1-1.rar
//DFRobot.com
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
 
#if defined(ARDUINO) && ARDUINO >= 100
#define printByte(args)  write(args);
#else
#define printByte(args)  print(args,BYTE);
#endif
 
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(0x27,20,4);  // set the LCD address to 0x27 for a 20 chars and 4 line display
 
void setup()
{
//  Serial.begin(57600);
  lcd.init();                      // initialize the lcd
  lcd.backlight();
   
  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()
{
 
}

from http://www.dfrobot.com/wiki/index.php/I2C_TWI_LCD2004_%28SKU:DFR0154%29.

but actually i own that one:

http://www.komputer.de/zen/index.php?main_page=product_info&cPath=30&products_id=49

but it worked very well.

So today i tried a little bit with DCF77 (didnt work), so i switched back to my Temperature-logging and displaying version, BUT DISPLAY didnt work again!

After hours and hours of searching i loaded the first example (that one above), and wonder: it worked again!

I uploaded my datalogger, diplay gave me tempertures. For about 30 minutes then again, dead. nothing is working.

That somehow looks to me as if im having a I2C-bus problem..... ??

I tried teh Lib posted here (moved LiquidCrystal_I2C and LiquidCrystal out of libraries folder), nothing. two lines on (no text), two lines off......

Any ideas?

BTW: I have a Mega R3, Display connecet to pins 20 an 21 (sda and scl) on mega....
Logged

Greenville, IL
Offline Offline
Edison Member
*
Karma: 11
Posts: 1289
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


 I believe I have all the latest libraries from FM. I copied the code from the OP and from Avain  but, I have problems with the code compiling. Can anyone spot the issue and tell me where to make changes?


 Here is the code from the post above.
Code:
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>  // F Malpartida's NewLiquidCrystal library

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

#define BACKLIGHT_PIN     7
#define En_pin  4
#define Rw_pin  5
#define Rs_pin  6
#define D4_pin  0
#define D5_pin  1
#define D6_pin  2
#define D7_pin  3

#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,NEGATIVE);
  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()
{

}


 Here are my errors.
Code:
LiquidCrystal_I2C\LiquidCrystal_I2C.cpp.o: In function `LiquidCrystal_I2C::pulseEnable(unsigned char)':
C:\Users\name\Documents\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.cpp:306: multiple definition of `LiquidCrystal_I2C::pulseEnable(unsigned char)'
LiquidCrystal\LiquidCrystal_I2C.cpp.o:C:\Users\name\Documents\Arduino\libraries\LiquidCrystal/LiquidCrystal_I2C.cpp:287: first defined here
LiquidCrystal_I2C\LiquidCrystal_I2C.cpp.o: In function `LiquidCrystal_I2C::send(unsigned char, unsigned char)':
C:\Users\name\Documents\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.cpp:288: multiple definition of `LiquidCrystal_I2C::send(unsigned char, unsigned char)'
LiquidCrystal\LiquidCrystal_I2C.cpp.o:C:\Users\name\Documents\Arduino\libraries\LiquidCrystal/LiquidCrystal_I2C.cpp:240: first defined here
LiquidCrystal_I2C\LiquidCrystal_I2C.cpp.o: In function `LiquidCrystal_I2C::setBacklight(unsigned char)':
C:\Users\name\Documents\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.cpp:337: multiple definition of `LiquidCrystal_I2C::setBacklight(unsigned char)'
LiquidCrystal\LiquidCrystal_I2C.cpp.o:C:\Users\name\Documents\Arduino\libraries\LiquidCrystal/LiquidCrystal_I2C.cpp:167: first defined here
LiquidCrystal_I2C\LiquidCrystal_I2C.cpp.o: In function `LiquidCrystal_I2C::begin(unsigned char, unsigned char, unsigned char)':
C:\Users\name\Documents\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.cpp:106: multiple definition of `LiquidCrystal_I2C::begin(unsigned char, unsigned char, unsigned char)'
LiquidCrystal\LiquidCrystal_I2C.cpp.o:C:\Users\name\Documents\Arduino\libraries\LiquidCrystal/LiquidCrystal_I2C.cpp:144: first defined here
LiquidCrystal_I2C\LiquidCrystal_I2C.cpp.o: In function `LiquidCrystal_I2C::init()':
C:\Users\name\Documents\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.cpp:92: multiple definition of `LiquidCrystal_I2C::init()'
LiquidCrystal\LiquidCrystal_I2C.cpp.o:C:\Users\name\Documents\Arduino\libraries\LiquidCrystal/LiquidCrystal_I2C.cpp:194: first defined here
Logged


Denver, CO, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I received a reply suggesting that I review the material below.  I had done that earlier.  But, I carefully read through it twice more.  Some of it appears incomplete and contradictory. 

I loaded each of the three libraries posted by F Malpartida.  These are all for the 2x16 displays, as the examples have the line "lcd.begin(16,2)" and also the address for the LCD device was wrong for all of them.  My device is 4x20.  I ran I2C Scanner, which found one I2C device at 0x3F.  I modified the example Sketch code, making the I2C device address and size correct, but none of them do anything other than make the back light flicker and cause some of the individual character LCDs to dimly flicker very quickly.

I appreciate your willingness to try and untangle this mess, but doing the same thing over and over, getting the same result is one working definition of insanity.   smiley-confuse

Again, my device is a Sainsmart LCD2004 J204A, found here:
http://www.amazon.com/gp/product/B003B22UR0/ref=oh_details_o00_s00_i00
I have an Arduino Uno, no shield, connecting I2C.
Logged

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

@ytrewq
I think you have replied to the wrong thread.  You probably should report back to the thread that recommended you to look here.

This thread was started in May of 2012 and marked as [SOLVED] in June. 

It was (in my estimation improperly) resurrected in October and died in November.

It was re-resurected in January and should again be left to die or perhaps it should be locked.


Don
Logged

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

@cyclegadge - it all point towards not having installed the library correctly. Are you using Arduiono's IDE 1.5?

If you are not using IDE 1.5 you are good, simply remove the stock LCD library "LiquidCrystal" and instal this one. Also if you have downloaded any other library i.e. some "LiquidCrystal_I2C" from another place it should be removed as the compiler is not able to find a good range of methods that are implemented.

@ytrewq - it all looks like your pin mapping is not correctly initialised. The flickering backlight is a sign that the LCD commands are getting to the LCD's backpack, but to the incorrect LCD pins. I suggest you look at the LiquidCrystal_I2C.h file which contains a description of what the contructors do (variable creation) and how the different methods are used. The library has been writen to try and be as generic as possible, therefore it should be customized for each particular LCD and backpack.

I think Don has a good point, to avoid re-opening several times this thread (again and again) this will be my last post here on how to configure the LCD library for any particular LCD vendor.
Logged

   

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

Quote
I think Don has a good point, to avoid re-opening several times this thread (again and again) this will be my last post here on how to configure the LCD library for any particular LCD vendor.

That doesn't mean he won't answer your questions -- just start a new thread!

Don
Logged

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

Quote
I think Don has a good point, to avoid re-opening several times this thread (again and again) this will be my last post here on how to configure the LCD library for any particular LCD vendor.

That doesn't mean he won't answer your questions -- just start a new thread!

Don
+1
Logged

   

Greenville, IL
Offline Offline
Edison Member
*
Karma: 11
Posts: 1289
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
if you have downloaded any other library i.e. some "LiquidCrystal_I2C" from another place it should be removed

 Thank you FM! That was the problem! I have tried to get this display to work for about 4 nights! Finally, I have the sketch that was from the OP working very nicely!

 Thank you very much!
Logged


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