Pages: 1 [2] 3 4   Go Down
Author Topic: SainSmart 20 x 4 LCD wanting to use I2C from Arduino Uno  (Read 15264 times)
0 Members and 1 Guest are viewing this topic.
Málaga, Spain
Offline Offline
Edison Member
*
Karma: 40
Posts: 2182
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Try address 0x2F or 0x1F.
Logged

   

Raleigh, NC.
Offline Offline
Full Member
***
Karma: 0
Posts: 129
Addicted to Arduino
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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

   

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

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

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

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:
#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).
Logged

   

Raleigh, NC.
Offline Offline
Full Member
***
Karma: 0
Posts: 129
Addicted to Arduino
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

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

Did you try the code posted changing the address.
Logged

   

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

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:
/*
** 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
« Last Edit: September 02, 2012, 11:02:56 pm by arjscott » Logged

Western New York, USA
Online Online
Faraday Member
**
Karma: 32
Posts: 4245
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  lcd.home ();                   // go home

  lcd.setCursor ( 0, 0 );
This second step appears redundant.  Shouldn't you explain why it may be necessary.

Don
Logged

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

Thanks for your feedback.

You're right, now I see its redundant.

Fixed  smiley

Andrew.
« Last Edit: September 02, 2012, 07:50:20 pm by arjscott » Logged

Western New York, USA
Online Online
Faraday Member
**
Karma: 32
Posts: 4245
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

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

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

Raleigh, NC.
Offline Offline
Full Member
***
Karma: 0
Posts: 129
Addicted to Arduino
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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
Logged

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

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

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