Go Down

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

fm

   

Aaron_dyer

Nah its definitely 0x3F...

Here is taken from my serial monitor just now:

I2C Scanner
Scanning...
I2C device found at address 0x3F !
done

Scanning...
I2C device found at address 0x3F !
done



I switched code around a bit:



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




LiquidCrystal_I2C lcd(0x3F, 20, 4);


void setup()
{

  lcd.init();                      // initialize the lcd
  lcd.backlight();
 
}

void loop()
{

 
  Wire.begin();
  lcd.setCursor(0,0);
  lcd.print("Hello"); 
  lcd.setCursor (0, 1);       
  lcd.print (" World!");


     
}


my backlight will stay on now.....the pixels are fluxuating...adjusted the contrast still no characters....

fm

Can you shift right the value and give it a shot.
   

dgreen

Try moving the Wire.begin(); to the setup section. That is initializing the communications. With that in the loop segment, it keeps initializing.

fm

OK, found the problem on your code.

The I2C address should be 0x27 as it says on their web.

The code would need to be something like this:
Code: [Select]

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



#define BACKLIGHT_PIN     13

LiquidCrystal_I2C lcd(0x27);  // Set the LCD I2C address

//LiquidCrystal_I2C lcd(0x38, BACKLIGHT_PIN, POSITIVE);  // Set the LCD I2C address


// Creat a set of new characters
const uint8_t charBitmap[][8] = {
   { 0xc, 0x12, 0x12, 0xc, 0, 0, 0, 0 },
   { 0x6, 0x9, 0x9, 0x6, 0, 0, 0, 0 },
   { 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0, 0x0 },
   { 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0, 0x0 },
   { 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0x0 },
   { 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0x0 },
   { 0x0, 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0x0 },
   { 0x0, 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0x0 }
   
};

void setup()
{
   int charBitmapSize = (sizeof(charBitmap ) / sizeof (charBitmap[0]));

  // Switch on the backlight
  pinMode ( BACKLIGHT_PIN, OUTPUT );
  digitalWrite ( BACKLIGHT_PIN, HIGH );
 
  lcd.begin(20,4);               // initialize the lcd

   for ( int i = 0; i < charBitmapSize; i++ )
   {
      lcd.createChar ( i, (uint8_t *)charBitmap[i] );
   }

  lcd.home ();                   // go home
  lcd.print("Hello, ARDUINO "); 
  lcd.setCursor ( 0, 1 );        // go to the next line
  lcd.print (" FORUM - fm   ");
  delay ( 1000 );
}

void loop()
{
   lcd.home ();
   // Do a little animation by writing to the same location
   for ( int i = 0; i < 2; i++ )
   {
      for ( int j = 0; j < 16; j++ )
      {
         lcd.print (char(random(7)));
      }
      lcd.setCursor ( 0, 1 );
   }
   delay (200);
}

You need to initialize the LCD to the geometry that you have, i.e. 20x4 -> lcd.begin( 20, 4 );

If you are using the New LiquidCrystal library, there is no need to call Wire.begin();

There are also a good range of examples that come from the library. I have just used the HelloWorld_i2c and changed the I2C address.

If it doesn't work with 0x27 then try 0x3F (but this value looks very odd for an IO expansion module).
   

Aaron_dyer

I appreciate the help guys.....I found a similar thread on a different library a guy used so I'm going to check into that....everything here is close but no cigar......its definitely 0x3F as well....no matter their website......labor day amend.....gonna break for now

fm

Did you try the code posted changing the address.
   

arjscott

#22
Sep 02, 2012, 05:40 pm Last Edit: Sep 03, 2012, 06:02 am by arjscott Reason: 1
Hey buddy,

Try the code below. I was having the exact same problem, but its working nicely with this example.

As mentioned below by Don, static display should go in setup(), and variables should go in loop().

This info is also helping me with my own project :-) Appreciate the feedback. Will be going from Arduino n00b to competent coder in no time.

Let me know if you have any questions.

Cheers,

Andrew.


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
**
** Edward Comer
** LICENSE: GNU General Public License, version 3 (GPL-3.0)
**
** sain_lcd_2.ino
** Simplified and modified by Andrew Scott for Arudino 1.0.1, Arudino Uno R3.
** NOTE: I2C pins are A4 SDA, A5 SCL
** Don't forget to use the new LiquidCrystal Library.
*/



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

#define I2C_ADDR    0x3F  // Define I2C Address where the SainSmart LCD 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

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);

 // Position cursor and write some text
 lcd.home ();                   // go to the first line, first character
 lcd.print("SainSmart I2C tester");  
 lcd.setCursor ( 0, 1 );        // go to the 2nd line
 lcd.print("It's Working!");
 lcd.setCursor ( 0, 2 );        // go to the third line
 lcd.print("Sainsmarts docs suck");
 lcd.setCursor ( 0, 3 );        // go to the fourth line
 lcd.print("Nice LCD Though. ");
}

void loop()
{

}


Moderator edit: colour tag swapped for code tags

floresta

Code: [Select]
  lcd.home ();                   // go home

  lcd.setCursor ( 0, 0 );

This second step appears redundant.  Shouldn't you explain why it may be necessary.

Don

arjscott

#24
Sep 03, 2012, 02:44 am Last Edit: Sep 03, 2012, 02:50 am by arjscott Reason: 1
Thanks for your feedback.

You're right, now I see its redundant.

Fixed  :)

Andrew.

floresta

Quote
By the way, the LCD display code should probably be in the loop() if you want to add any useful output.

I missed this one.  This statement is not correct since the information that you are displaying does not change.

You should only put LCD display code in loop() if the information that you are displaying changes.  

For example to display "The temperature is xxx" you should display "The temperature is " in setup() and "xxx" in loop().  Then as the temperature changes you just update the "xxx" part.


Don

arjscott


Quote
By the way, the LCD display code should probably be in the loop() if you want to add any useful output.

I missed this one.  This statement is not correct since the information that you are displaying does not change.

You should only put LCD display code in loop() if the information that you are displaying changes. 

For example to display "The temperature is xxx" you should display "The temperature is " in setup() and "xxx" in loop().  Then as the temperature changes you just update the "xxx" part.


Don


Ahh, this makes good sense. Thanks again for the advice. Will update accordingly.

Aaron_dyer

For arjscott.....in your comments you say don't forget to use the new liquidcrystal library...you're referring to the one sainsmart provides compatible with arduino right?

arjscott


For arjscott.....in your comments you say don't forget to use the new liquidcrystal library...you're referring to the one sainsmart provides compatible with arduino right?


The new liquidcrystal library can be found here:

https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home

One important thing to note from the installation instructions (at the above link) is this:

"The library has been developed to replace the current Arduino library, therefore you will need to remove/backup the LiquidCrystal folder from the Arduino library folder the original LiquidCrystal library and replace it for this one."

So, be sure to move the current LiquidCrystal folder somewhere, and replace it with the new library.

Best regards,

Andrew

arjscott

Oh, I think the library on the sainsmart website is the same one that I have linked to.

But, personally I don't have much faith in any docs or code on their site.

Go Up