Recently I bought a cheap I2C controller and 16x2 display off of eBay, and since there seemed to be a lot of documentation online, I thought it would be an easy thing to hook up to my Uno. Instead, it took me weeks to figure it out. (Don't laugh, I'm new at this.) I noticed that there wasn't that much documentation about my specific I2C board, so I decided to help change that by posting the results of my work.
The display: a QC1602A 16x2 character display.
http://www.ebay.com/itm/170817946781?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649
This seems to be pretty popular, and is fairly well documented.
The I2C Adapter: MJKDZ brand I2C LCD1602
http://www.ebay.com/itm/140906400906?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649
Cheap, but not nearly as popular as it's similar cousins, so there isn't nearly as much information on this device. There is a website printed on the board. Don't bother, it's all in Chinese, and using Google Translate, I can confirm that what is there is totally useless. The name of the chip has been filed off for some unknown reason as well.
First of all, getting the I2C board properly connected wasn't hard. This 5v device connects to the Arduino just like any other I2C device. 4 pins: Ground, 5V power, A4/SDA and A5/SCL. Because things weren't working (for other reasons, but I had no idea the time), I tried to hook it up straight, and then I did it again using 4.7K Ohm pull-up resistors to improve signal quality. Both methods worked, so don't be so concerned with the pull-up resistors unless you are experiencing problems.
Next, testing to see if the I2C board itself works and responds to I2C commands is important. I recommend an I2C scanner, because this will tell you if the MJKDZ board is acknowledging I2C commands. I got mine at this website: Gammon Forum : Electronics : Microprocessors : I2C - Two-Wire Peripheral Interface - for Arduino about half way down the page. There's a lot of great I2C information there. When I ran my I2C scanner, it told me that the device has an I2C address of 0x20. This is interesting, because the eBay seller claimed the address was 0x27, which is totally not true. So it happens to be very important to run an I2C scanner on your device to confirm the address, because no sketch will work correctly if you don't have the right address.
Excited that my I2C board was working, I hooked up my 16x2 display, and loaded up an I2C "hello world" sketch and.... nothing. I tried all the sketches I could find on Google, and still, nothing. Sometimes, the back light would turn on and off, and sometimes, the screen would have strange flashing and gibberish. At first I thought it was a connection issue, so I tested the continuity of every wire, but everything was fine. I also tried turning the tiny screw on the blue potentiometer, as that adjusts the contrast on the display. Still, nothing. I spent many days searching the internet and trying everything I could get my hands on, but nothing seemed to work until yesterday. Here is what is needed for sketches to work:
Step 1: Remove all LCD libraries from your Arduino IDE. Check both the user specific ones, as well as in the Arduino install folder. Zip them up and save them somewhere else if you think you might need them again, otherwise, delete.
Step 2: Install the new and improved LCD library by F Malpartida from here: https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home This person has done some awesome work for the Arduino community.
Step 3: The sketch I got working I found at the bottom of this website: http://arduino-info.wikispaces.com/LCD-Blue-I2C Again, a very useful website!
I had to modify the sketch a little bit to make it work with a 16x2 display with an address of 0x20. Below is the modified code:
/* YourDuino.com Example Software Sketch
16 character 2 line I2C Display
NEW TYPE Marked "Arduino-IIC-LCD GY-LCD-V1"
terry@yourduino.com */
/*-----( Import needed libraries )-----*/
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h> // F Malpartida's NewLiquidCrystal library
/*-----( Declare Constants )-----*/
#define I2C_ADDR 0x20 // Define I2C Address for the PCF8574A
//---(Following are the PCF8574 pin assignments to LCD connections )----
// This are different than earlier/different I2C LCD displays
#define BACKLIGHT_PIN 7
#define En_pin 4
#define Rw_pin 5
#define Rs_pin 6
#define D4_pin 0
#define D5_pin 1
#define D6_pin 2
#define D7_pin 3
#define LED_OFF 0
#define LED_ON 1
/*-----( Declare objects )-----*/
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
void setup() /*----( SETUP: RUNS ONCE )----*/
{
lcd.begin (16,2); // initialize the lcd
// Switch on the backlight
lcd.setBacklightPin(BACKLIGHT_PIN,NEGATIVE);
lcd.setBacklight(LED_ON);
}// END Setup
void loop() /*----( LOOP: RUNS OVER AND OVER AGAIN )----*/
{
// Reset the display
lcd.clear();
delay(1000);
lcd.home();
// Print our characters on the LCD
lcd.backlight(); //Backlight ON if under program control
lcd.setCursor(0,0); //Start at character 0 on line 0
lcd.print("Hello, world!");
delay(1000);
lcd.setCursor(0,1); //Start at character 0 on line 1
lcd.print("16 by 2 Display");
delay(8000);
} // END Loop
I pressed upload and it worked the first time! After all that hard work, it now seemed so easy. I think the secret is that the pins on the I2C device aren't standard, so may need to be remapped, which is what I think happens in the code above. This would also explain why those pins on the MJKDZ board have no labels. For me as a new Arduino user, it was quite a hassle, but it all worked in the end, and I learned lots, so I can say that this was $5.23 well spent. I hope this post helps any other new owners of the MJKDZ I2C LCD1602 boards save some time figuring things out the hard way.