Go Down

Topic: SainSmart 20 x 4 LCD wanting to use I2C from Arduino Uno (Read 19711 times) previous topic - next topic

Aaron_dyer

Andrew!!!!!!  You are the Man!   I just hooked it up , downloaded library and uploaded and it worked like a champ!   Thank you so much bro!

arjscott


Andrew!!!!!!  You are the Man!   I just hooked it up , downloaded library and uploaded and it worked like a champ!   Thank you so much bro!


Hey that's great!!! I'm really glad you got it working! I'm loving playing with this LCD too.

Cheers,

Andrew

fm

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!
   

fm

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".

Code: [Select]
/*
** 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!
   

Aaron_dyer

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......

Aaron_dyer

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

fm

@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.
   

Aaron_dyer

FM,

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

fm


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
   


fm

   


Aaron_dyer

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....


vatosupreme



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.?

Go Up