Go Down

Topic: Driving a 20x4 LCD with I2C - what am I missing? (Read 1 time) previous topic - next topic


Not sure if you've tried this or not, but you should adjust your potentiometer on the back of the LCD screen. Your screen may be showing the correct text from the code but it looks like blocks because the contrast is off.

Umm, in short, No!

Sorry, no cigar. :smiley-lol:


I have exactly the same display and backpack, and I got it to work with the following sketch:

/* YourDuino.com Example Software Sketch
16 character 2 line I2C Display
Backpack Interface labelled "A0 A1 A2" at lower right.
Backpack Interface labelled "YwRobot Arduino LCM1602 IIC V1"
MOST use address 0x27, a FEW use 0x3F
terry@yourduino.com */

/*-----( Import needed libraries )-----*/
#include <Wire.h>  // Comes with Arduino IDE
// Get the LCD I2C Library here:
// https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
// Move any other LCD libraries to another folder or delete them
// See Library "Docs" folder for possible commands etc.
#include <LiquidCrystal_I2C.h>

/*-----( Declare Constants )-----*/
/*-----( Declare objects )-----*/
// set the LCD address to 0x27 for a 16 chars 2 line display
// A FEW use address 0x3F
// Set the pins on the I2C chip used for LCD connections:
//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
//LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);    // Set the LCD I2C address

/*-----( Declare Variables )-----*/

void setup()   /*----( SETUP: RUNS ONCE )----*/
 Serial.begin(9600);  // Used to type in characters

 lcd.begin(20,4);   // initialize the lcd for 20 chars 4 lines, turn on backlight

// ------- Quick 3 blinks of backlight  -------------
 for(int i = 0; i< 3; i++)
 lcd.backlight(); // finish with backlight on  

//-------- Write characters on the display ------------------
// NOTE: Cursor Position: (CHAR, LINE) start at 0  
 lcd.setCursor(0,0); //Start at character 4 on line 0
 lcd.print("Hello, world!");

// Wait and then tell user they can start the Serial Monitor and type in characters to
// Display. (Set Serial Monitor option to "No Line Ending")
 lcd.setCursor(0,0); //Start at character 0 on line 0
 lcd.print("Use Serial Mon");
 lcd.print("Type to display");  

}/*--(end setup )---*/

void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
   // when characters arrive over the serial port...
   if (Serial.available()) {
     // wait a bit for the entire message to arrive
     // clear the screen
     // read all the available characters
     while (Serial.available() > 0) {
       // display each character to the LCD

}/* --(end main loop )-- */

/* ( THE END ) */

I found that the contrast setting is crucial.  Try adjusting contrast after running sketch.


Hi. I got a similar display off fleabay and it had three problems

a) some of the pins between the back pack and the display were shorted with excess solder.
b) the contrast pot was dodgy.
c) depending on the source of supply for the board even the replacement board needed different settings (the 5v output on USB on my computer is slightly low 4.8v, and the Leonardo's native 5v rail is actually 5.05)

a&b Are fixable if your a dab hand with a soldering iron.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131