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

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

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

Did you try the code posted changing the address.

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

/*
** 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

  lcd.home ();                   // go home

  lcd.setCursor ( 0, 0 );

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

Don

Thanks for your feedback.

You're right, now I see its redundant.

Fixed :slight_smile:

Andrew.

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

floresta:

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.

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?

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?

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