SainSmart 20 x 4 LCD wanting to use I2C from Arduino Uno

Hello all,

I have been using arduino for awhile, but this is my first post in the forums. I have built a project that is working fine using the 6 data pins that I declare in my code:

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

but my senior partners and I in my class would like to imply more use of the Digital Pin outs especially the SPI pin outs, so I have decided to try the I2C route. Now I have connected Pin analog 4 (SDA ) and analog 5 (SDL) to the resepective Two wire interface for the board on the back of the 20 x 4 LCD as well as VCC and GND.

All the test code provided online doesn't work, I have arduino 1.0 and arduino 1.0.1 and it is kicking my @$$ on trying to get some readout on the LCD at all...I can get it to load using this code:

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

LiquidCrystal_I2C lcd(0x27 20,4); //set the LCD address to 0x27 

void setup()
{
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("b2cqshop");
lcd.setCursor(0, 1);
lcd.print("Voltage: ");
lcd.setCursor(13, 1);
lcd.print("V");
}
void loop()
{
int val;
float temp;
val=analogRead(0);
temp=val/4.092;
val=(int)temp;//
lcd.setCursor(9, 1);
lcd.print(0x30+val/100);
lcd.print(0x30+(val%100)/10);
lcd.print('.');
lcd.print(0x30+val%10);
delay(100);
}

but the LCD just doesn't do anything......I know all about the ACK bit for the 7 / 8 bit transfer using I2C and the wire library needs to be included which it is.....

IS THERE ANYONE OUT THERE THAT HAS DONE a simple Arduino Uno to I2C LCD that could step me through some simple basics to get any readout on the 20 x 4 LCD...direct me to a proper library ...something....

the 4 wire harness I have is fine as well (Ohmed it out..) ...Pot for contrast is good too....

Please Please help

Aaron

Moderator edit: Code tags added.

Now I have connected Pin analog 4 (SDA ) and analog 5 (SDL) to the resepective Two wire interface for the board on the back of the 20 x 4 LCD as well as VCC and GND.

Have you got pullups for the I2C lines?
What value?
Do you have a scope?

Scope yes.....I did try the pullups with 5K's and it still didn't work....I just want the LCD to display something.....I don't want my code written for me....am I not using the correct Libraries? I don't know....

simply..SDA and SDL are hooked up from arduino Uno to the I2C interface board behind the LCD...power and gnd are good...

is there any libraries I need beside LiquidCrystal_I2C and wire...

???????

How do I know which address to use as well? I have seen a lot of 0x27 stuff

I was using the LiquidCrystal_I2C lcd( 0x27, 20, 4);

to initiate the LCD...i read how someone wrote you have to also code wire.begin but that just shows an error.

Damn it man

How do I know which address to use as well? I have seen a lot of 0x27 stuff

Which LCD do you have?
What does the datasheet say?

5k is a good value for the pullups.

.i read how someone wrote you have to also code wire.begin but that just shows an error.

What does that mean, please?

sainsmart LCD HD44780 with the I2C board on back......

wire library is needed for I2C but I was wondering myself what wire.begin would do.....

I was wondering myself what wire.begin

I simply cannot imagine.

can anybody help me please? has anyone ever built an arduino I2C lcd project

Aaron_dyer:
?

How do I know which address to use as well? I have seen a lot of 0x27 stuff

I was using the LiquidCrystal_I2C lcd( 0x27, 20, 4); to initiate the LCD...

I noticed you also posted in this thread:http://arduino.cc/forum/index.php/topic,119502.15.html
So by now you have already found and used the I2C-scanner found here:Arduino Playground - I2cScanner
This is the adress you need to put in the declaration.

Give the New liquidCrystal library a shot:
https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home

It is reported to work with the Sainsmart LCD. I think at base address 0x27.

Wiring info on corresponding section.

This is a dumb question, I know...but how do I "open the serial monitor" I uploaded the code for the I2C scanner and it compiled fine...but now what?

I did try the new liquid crystal library but which version are you referring to? There are like 10 downloads on that bitbucket page.....

so confusing....and is this for 1.0 or 1.0.1?

I saw some posts of some sainsmarts getting to work, but dammit I want mine to

how do I "open the serial monitor"

On the Arduino's IDE, the right-most button just above the code pane.

Ok I found the serial monitor thing....I have an I2C device at 0x3F which is cool now I'm getting somewhere...

But I upload my simple code here: and the LCD backlight just blinks...no characters still....what am I missing??

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

LiquidCrystal_I2C lcd(0x3F,20,4);

void setup()
{

lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Hello");
lcd.setCursor(0, 1);
lcd.print("World ");

}

void loop()
{

}

Aaron_dyer:
This is a dumb question, I know...but how do I "open the serial monitor" I uploaded the code for the I2C scanner and it compiled fine...but now what?

I did try the new liquid crystal library but which version are you referring to? There are like 10 downloads on that bitbucket page.....

so confusing....and is this for 1.0 or 1.0.1?

I saw some posts of some sainsmarts getting to work, but dammit I want mine to

Get the latest version.

As it says in the wiki:

To install the library:

  • Download the most recent version of the library.
    ...

version and compatibility:

== Version ==
Current New LiquidCrystal is the latest zip file in the download section.

The New LiquidCrystal library has been tested and is compatible with Arduino SDK 1.0.1, 1.0 and Arduino SDK 0022.

Downloaded......installed in place of old library......still doesn't work.....The address my I2C is communicating on is 0x3F.

I upload the code and the LCD just turns off its backlight and flashes from time to time.

Does anyone know some GOOD -verified working test code for the LCD just to say ANYTHING using an I2C connection?

I am so close I feel it...I just need some new tips....

here is my code:

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

LiquidCrystal_I2C lcd(0x3F, 20, 4);

void setup()
{

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

void loop()
{

}

pins 4 and 5 from arduino Uno plugged into I2C board on 20 x 4 LCD...along with ground and power.....just white pixels on LCD still and the LED backlight flashes from time to time.....

Try address 0x2F or 0x1F.

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

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

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

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:

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