Library Problems? Hooking-up the DFRobot I2C LCD to Arduino (Uno)

I was going to inquire here for help with the DFRobot I2C LCD Arduino library, but I solved my problem. So If you are having issues with the DFRobot I2C LCD read on …

The library linked to on the Robotshop shopping page for the DFRobot I2C / TWI LCD1602 Module part #RB-Dfr-69 did not work well with the Arduino Uno. The Uno did not properly initialize the LCD with the provided library. It may be intermitant or not work at all. Mine would work every so other Arduino “reset”, weird.

Update: RobotShop fixed the DFRobot I2C LCD onsite download libraries. The updated I2C LCD Library can also be found at:

dfrobot.com/image/data/DFR0063/Arduino_library.zip

You can check your current Arduino libraries to see if you have the corrected LiquidCrystal_I2C library. Open the LiquidCrystal_I2C.cpp file, check the the Void …::begin section of code …

*void LiquidCrystal_I2C::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
if (lines > 1) {
_displayfunction |= LCD_2LINE;
}
_numlines = lines;

// for some 1 line displays you can select a 10 pixel high font
if ((dotsize != 0) && (lines == 1)) {
	_displayfunction |= LCD_5x10DOTS;
}

// SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
// according to datasheet, we need at least 40ms after power rises above 2.7V
// before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50
delayMicroseconds(50000); 

// Now we pull both RS and R/W low to begin commands
expanderWrite(_backlightval);	// reset expanderand turn backlight off (Bit 8 =1)
delay(1000);

//put the LCD into 4 bit mode
// this is according to the hitachi HD44780 datasheet
// figure 24, pg 46

// we start in 8bit mode, try to set 4 bit mode
**write4bits(0x03);**
delayMicroseconds(4500); // wait min 4.1ms

// second try
**write4bits(0x03);**
delayMicroseconds(4500); // wait min 4.1ms

// third go!
**write4bits(0x03); **
delayMicroseconds(150);

// finally, set to 4-bit interface
**write4bits(0x02); **

The library above will cause the LCD to work intermitantly, sometimes not at all, the correct Library (found at the DFRobot site, see below) shifts the bytes to the left …

write4bits(0x03 << 4); and write4bits(0x02 << 4);

You will also know if you have the corrected library by examining the //quote header of the library

You should see …

//www.DFRobot.com
//last updated on 26/11/2010

//Tim Starling Fixed the reset bug (Thanks Tim)
//wiki doc dfrobot.com/wiki/index.php?title=I2C/TWI_LCD1602_Module_(SKU:_DFR0063
//Support Forum: dfrobot.com/forum/

(If you don’t, checK for the “left shift” code (write4bits(0x0X << 4)) in the ::begin code.)

My LCD projects are now working fine with the new libraries, so if you are having problems with getting the DFRobot I2C LCD to work check your libraries and update your library at the DFRobot LiquidCrystal_I2C library site.

Also the old Robotshop LCD_I2C libaray downloads were double compressed (both ZIPped and RARed) which makes them hard to open, especially on Macs.

Update: RobotShop fixed the DFRobot I2C LCD onsite download libraries. The updated I2C LCD Library can also be found at:

dfrobot.com/image/data/DFR0063/Arduino_library.zip

See my next post here about hooking up your DFRobot I2C LCD and getting it going.

void loop {Arduino(0); cappuccino(0); Arduino(1); cappuccino(1); Arduino(2); cappuccino(2); sleep(8) //hours}

RoboFrog*

A few more “discovered” facts about hooking up your DFRobot I2C / TWI LCD1602 Module (part #RB-Dfr-69) to an Uno Arduino (this will most likely also work for most other Arduinos). Two days of web based searches and many hours of hacking yielded:

  1. make sure you have the correct libraries for your arduino and IC2 LCD (see first post “Having DFRobot IC2 LCD Arduino library problems ?”)

  2. You will need to connect the Uno Ardunio to the I2C LDC via a four wire harness (part #RB-See-56). The cheapest method is to cut the cable in the center and solder connector wires of the same colour to the cut and stripped ends. The yellow wire pin connects to Analog 4 socket (SCL), the white wire pin connects to Analog 4 socket (SDA) and of course red to 5 volts (5v) and black to ground (gnd) all on the Arduino board.

  3. There are two places to connect the cable plug on the I2C LCD, Use the black (clipped) socket for the cable. Be warned the naked connector pins on the I2C/LCD board has the SCL and SDA lines reversed, you can use this socket only if you swap the Yellow and White pin wires at the Arduino.

  4. if all this cutting and soldering scares you then purchase the SeeedStudio Electronic Brick Shield V4.0 Pro (RobotShop #RB-See-69) and hook the arduino/shield directly (via 4 wire harness) to the DFRobot I2C LCD. Make sure you set the tiny shield switch (on the shield board connect side) to “IIC” before you start everything up. Update: The shield I am using is new and has a switch for the I2C/COM setup; on some older shields this setting is done with pins and jumpers.

  5. regardless of what you may see posted elsewhere you do not need pull-up resistors on the SCL and SDA lines. The Arduino I2C library will set the internal pull-up on the Analog 4 (SDA) and Analog 5 (SCL) so that everthing will work just fine without them.

  6. although the I2C bus devices are hot swappable (connect/disconnect with the power on) you will have to reinitialize (reset the Arduino) to get the LCD working again if you remove and reattach the LCD to the Arduino.

  7. do try the “Hello World” example and other examples in the library to check out the I2C LCD and see how the I2C library is used. You must declare TWO (2) libraries for the I2C LCD to work in your sketch; they are:

#include <Wire.h> // LiquidCrystal_IC2 requires that Wire.h be loaded
#include <LiquidCrystal_I2C.h> // abstraction for LCD IC2 interface

  1. If your LCD does not light up and display “Hello World” power down and recheck all of your connections. You can also try adjusting the “contrast” pot on the back of the LCD module. If does not help, try another I2C LCD module, the first one may be DOA.

[ATTACH]284[/ATTACH]

  1. remember: if your I2C LCD does not initialize properly on Arduino reset, Make sure you update your LiquidCrystal_IC2.cpp file in your Arduino library folder (see previous post “Having DFRobot IC2 LCD Arduino library problems ?”)

  2. Update: It seems that the backlighting LED on the LCD draws a fair amount of current, this is especially evident if you are turning the backlight on and off (with software) where the resulting voltage fluctuations may cause errors with the Uno Arduino’s internal workings (Analog inputs and timing). Try inserting a 470 micro Farads Capacitor (16 volt) across the 5 volt and ground rails on the Solderless Breadboard, like the RobotShop # RB-Cix-11.

And finally: if all else fails DON"T PANIC! Post something here for help.

void loop {Arduino(0); cappuccino(0); Arduino(1); cappuccino(1); Arduino(2); cappuccino(2); sleep(8) //hours}

RoboFrog
Last edited by robofrog; 10-23-2011 at 05:11 PM. Reason: Updates …