Shift Register Libraries for LCD Displays

I am working on a project where, ultimately, I will be driving a 16x2 1602 LCD with a ATtiny85. For now, however, I am testing Shift Register libraries, and there are several out there. I am testing several and will, eventually, pick one. So far I have tested ShiftLCD by Chris Parish and LiquidCrystal_SR by Francisco Malpartida. They both work well but require significantly different wiring. I have posted my test “Hello World” for both libraries below. The wiring differences are noted. I thank both Chris and Francisco for generously donating the libraries to the community.

First, with LiquidCrystal_SR:

#include <LiquidCrystal_SR.h>

/*
  ShiftLCD Library - Hello World
 
 Demonstrates the use a 16x2 LCD display.  The ShiftLCD library works with
 all LCD displays that are compatible with the Hitachi HD44780 driver.
 There are many of them out there, and you can usually tell them by the
 16-pin interface.
 
 This sketch prints "Hello World!" to the LCD
 and shows the number of seconds since reset.
 
  The circuit:
 
 ---Shift Register 74HC595---
 * SR SER - Pin 14 to Arduino pin PD2
 * SR RCK - Pin 12 to Arduino pin PD3 and (LCD E 1602 Pin 6)
 * SR SCK - Pin 11 to Arduino pin PD4
 * SR GND - Pin  8 to Ground
 * SR VCC - Pin 16 to +5v
 * SR OE - Pin 13 to Ground
 * SR SCLR - Pin 10 to +5v
 -----Shift Reg to LCD--------
 * SR QG - Pin 6 to D7 (LCD 1602 Pin 14)
 * SR QF - Pin 5  to D6 (LCD 1602 Pin 13)
 * SR QE - Pin 4  to D5 (LCD 1602 Pin 12)
 * SR QD - Pin 3  to D4 (LCD 1602 Pin 11)
 * SR QC - Pin 2  to LCD RS (LCD 1602 Pin 4)
 -----LCD HD44780-------------
 * Vss to Ground    (LCD 1602 Pin 1)
 * Vdd to +5V       (LCD 1602 Pin 2)
 * Vo  to 10k Wiper (LCD 1602 Pin 3)
 * R/W to Ground    (LCD 1602 Pin 5)
 * LEDA  to +5v     (LCD 1602 Pin 15)
 * Gnd to LEDK via 330 Ohm resistor  (LCD 1602 Pin 16)
 
 The schematic at this link is:
 http://code.google.com/p/arduinoshiftreglcd/ see 
 the last schematic labled "Latched shiftregister"

 */
 
#define  DATAPIN  2
#define  CLOCKPIN 4
#define  STROBEPIN 3
#define  MAXCOLUMNS  16
#define  MAXLINES  2


LiquidCrystal_SR lcd(DATAPIN, CLOCKPIN, STROBEPIN);

void setup() {
  // set up the LCD's number of rows and columns: 
  lcd.begin(MAXCOLUMNS, MAXLINES);
  // Print a message to the LCD.
  lcd.print("Hello, World!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);  //lcd.setCursor(column, row);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
}

Next with ShiftLCD:

#include <ShiftLCD.h>

/*
  ShiftLCD Library - Hello World
 
 Demonstrates the use a 16x2 LCD display.  The ShiftLCD library works with
 all LCD displays that are compatible with the Hitachi HD44780 driver.
 There are many of them out there, and you can usually tell them by the
 16-pin interface.
 
 This sketch prints "Hello World!" to the LCD
 and shows the number of seconds since reset.
 
  The circuit:
 
 ---Shift Register 74HC595---
 * SR SER - Pin 14 to Arduino pin PD2
 * SR RCK - Pin 12 to Arduino pin PD3
 * SR SCK - Pin 11 to Arduino pin PD4
 * SR GND - Pin  8 to Ground
 * SR VCC - Pin 16 to +5v
 * SR OE - Pin 13 to Ground
 * SR SCLR - Pin 10 to +5v
 -----Shift Reg to LCD--------
 * SR QA - Pin 15 to D7
 * SR QB - Pin 1  to D6
 * SR QC - Pin 2  to D5
 * SR QD - Pin 3  to D4
 * SR QG - Pin 6  to LCD Enable (LCD 1602 Pin 6)
 * SR QH - Pin 7  to LCD RS (LCD 1602 Pin 4)
 -----LCD HD44780-------------
 * Vss to Ground    (LCD 1602 Pin 1)
 * Vdd to +5V       (LCD 1602 Pin 2)
 * Vo  to 10k Wiper (LCD 1602 Pin 3)
 * R/W to Ground    (LCD 1602 Pin 5)
 * LEDA  to +5v     (LCD 1602 Pin 15)
 * Gnd to LEDK via 330 Ohm resistor  (LCD 1602 Pin 16)
 
 The schematic at this link is correct except that, in this implementation,
 The MOSFET circuit is replaced by a 330 ohm resistor (see above).
 http://cjparish.blogspot.com/2010/01/controlling-lcd-display-with-shift.html
 
 Library modified from the original LiquidCrystal Library
 This example originaly by Tom Igoe, Jul 2009
 Example modified for use with ShiftLCD
 Chris Parish, January 12th 2010
 */
 
#define  DATAPIN  2
#define  CLOCKPIN 4
#define  LATCHPIN 3
#define  MAXCOLUMNS  16
#define  MAXLINES  2
#define  FOURBIT  4


ShiftLCD lcd(DATAPIN, CLOCKPIN, LATCHPIN, FOURBIT);

void setup() {
  // set up the LCD's number of rows and columns: 
  lcd.begin(MAXCOLUMNS, MAXLINES);
  // Print a message to the LCD.
  lcd.print("Hello, World!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);  //lcd.setCursor(column, row);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
}

So far I have tested ShiftLCD by Chris Parish and LiquidCrystal_SR by Francisco Malpartida.

Your post would be a lot more helpful if you included actual links to these libraries.

don

added to original post

I always wonder what the author of a program named NewWhatever will call his next version. Perhaps 'NewerWhatever', or the worst possibility - 'NewestWhatever'.

What is really important and troubling is the fact that virtually every 'new' LCD library that comes out: (a) still contains the same irrelevant comments that have been with us since the early days of the original LiquidCrystal library, and (b) fails to follow the initialization code sequence that is recommended in the data sheets.

Don

floresta: I always wonder what the author of a program named NewWhatever will call his next version. Perhaps 'NewerWhatever', or the worst possibility - 'NewestWhatever'. [/quote]

And you live in which great state Don? ;)

My libraries and hardware have a common prefix and fortunately it is not the word "new" or my name.

And you live in which great state Don?

I didn't name it, but I guess it should have been York v01 or York1664

Don

Will this work with an arduino UNO R3? I tried the shift LCD but I got a couple of errors when I tried to compile it.

In file included from sketch_mar07a.cpp:1: C:\Program Files\arduino-1.0\libraries\ShiftLCD/ShiftLCD.h:116: error: conflicting return type specified for 'virtual void ShiftLCD::write(uint8_t)' C:\Program Files\arduino-1.0\hardware\arduino\cores\arduino/Print.h:48: error: overriding 'virtual size_t Print::write(uint8_t)'

Thanks a bunch for any advice on getting this to work.

LiquidCrystal_SR from New-LiquidCrystal is the best library choice. Get it directly from the author: https://bitbucket.org/fmalpartida/new-liquidcrystal/overview

Other good reading: http://code.google.com/p/arduinoshiftreglcd/ - contains important info regarding the circuit design.

and, yet more: http://www.3guys1laser.com/blog-cheap-arduino-2-wire-lcd-display-0

I got it working. The circuit was fine. Something was wrong with my IDE, so I re-installed it then was able to get the liquidCrystal_SR library to work. I still get the same errors for the shiftLCD library but the other works fine for my purpose. Thanks for sharing this code, and also pointing these libraries out to us. I have been trying to get this 595 to run my LCD for weeks. Here is my schematic I made with Fritzing for anyone who is interested.

How do I go about powering everything off another voltage supply? Would this setup work using either a wall adapter or battery, as long as I connect all the grounds?

How do I go about powering everything off another voltage supply? Would this setup work using either a wall adapter or battery, as long as I connect all the grounds?

It wouldn't work very long with that battery. You would have to power the Arduino somehow. I don't see the recommended capacitor on the input side of your voltage regulator. Not too many LCDs give a suitable display with that contrast pin circuit. How did you manage to get two wires into one breadboard hole?

Don

Consider getting a breadboard specific power supply, such as this: http://tinyurl.com/85avtt2

They are under $5 and perfect for Arduino breadboard work, specifically designed for the type of breadboard shown in your Fritzing image. You’ll also need a 6-to-9 volt wall wart transformer - maybe hiding in your closet or at the local thrift store.

!(http://i.ebayimg.com/t/3v-5v-Power-Supply-Module-adapter-MB102-Breadboard-/00/$(KGrHqYOKjYE43-6s9ftBOQCqnLf!g~~_1.JPG)

I really just wanted to know if this was the right way to do it. I heard that in some cases you can have multiple voltages in a system and you connect the grounds together. So basically the question is will the circuit short anything out. I will be using a seperate power supply for the arduino of course and the 9v can be replaced with a wall wort. I have been wanting to get a breadboard ps like that but for now i am using a voltage regulator and 2x 10uf caps with a .1 uf. Also, lets say I want to add a mosfet to power a high current device such as a solenoid. Would I also connect that ground to the circuit? Do you always connect all the grounds in these situations?

Thanks for the reply, Anthony

Yes, you can use multiple power supplies, connecting the common, within reason. The Vcc should be as close to the same as you can get it, given that there will be some feedback through circuit connections, such as the Atmel chip, i/o chips, etc.

I have downloaded the "latest" library from Francisco's GITHUB (dated 20Aug2011) and installed it. When I go to compile your example code, I get errors related to "I2CIO.cpp", where "Wire.h" does not exist. I am using the IDE V1.0. I went through his .ccp file and noticed that it says "#include...Wire.h". Are there changes I need to make to this file in order for this to work, or should I reinstall the IDE as was suggested above by roachburn?

Disregard previous question. I added the following line to the top of the code, and it compiled and uploaded fine:

#include <Wire.h>

Now I get random garbage being displayed on my LCD. I read a note in your page:

http://code.google.com/p/arduinoshiftreglcd/

that says that decoupling caps should be added to fix this problem. I’m going to try that next, but first have a question. Is the screen supposed to be continuously rewritten? The screen doesn’t just print one set of garbage lines and stop. It continues to write blah to line zero, mostly question marks and forward slashes. Shouldn’t it just print one line and stop? For reference, I am using:

Arduino UNO SMD
V1.0 IDE
This LCD: http://www.sparkfun.com/products/709
And a 74H595N latching shift register
All is wired according to the instructions in the sample code above.

As suggested, I placed coupling capacitors between VCC (pin 16 on the 595N) to GND, and GND to GND (the second one was just in case). It didn't change anything. In the LCD3Wires tutorial, a decoupling cap is recommended for pin 12 to GND, to cancel out ripple which could cause flicker. I had this cap placed between pin 12 and pin 13, since pin 13 is tied to GND, and electrically it is all the same. To ensure that this was not the issue, I removed the cap entirely. When I did this, I can definitely see the flicker when the SR changes state (clock), and the LCD now writes garbage faster, and generally to only the first 6 blocks. If I hit the reset button on the Arduino, or remove power from it entirely, the LCD does nothing (I am running it off of separate power from a USB port). It holds the state of the characters until the Arduino is powered back on, then starts to write garbage again.

I also use the IDE v1.0 although these days I mostly use make for my compilations. I use the same LCD display as you.

I am not sure if I can help much as I haven't used this circuit with an actual Arduino for quite a while. I have moved on to using bare-chip AVR ATtiny85 and ATtiny84 designs. There is a video of my ATtiny85 version at http://youtu.be/9r2GVga5cYs

I can say that without the bypass capacitors the circuit was unreliable, displaying random garbage, as you are experiencing. I could tell that the firmware was sane because I could send serial commands to the circuit to turn the LED on and off. Inserting bypass capacitors solved my reliability issues. If you insert bypass capacitors and still have reliability issues you may have power supply noise. Finally, substitute different physical ICs and display in case you have a chip problem.

Two pieces of advice that I have learned the hard way on this project. (1) If you use one of the ATtiny chips, pay attention to the core's pin assignments. There are several ATtiny cores out there and they differ. I use MIT's Arduino-Tiny core; (2) If you use a serial connection that uses a CP2102 I/O chip, isolate the Rx line (CP2102's Tx, your board's Rx) with a signal diode. Otherwise your circuit will lockup if connected during power-on - or appears to lockup as the LCD displays the same pattern as if no CPU were present. Oddly, if connected after power on it worked correctly. Anyway, diode isolation solved that issue.

Update: Partial success. After removing the decoupling cap between pins 12 and 13, and writing the last update, I reset the Arduino again, and it started working. I reinserted the cap between these two pins, and the garbage came back. Obviously there should not be a cap there. Anyone who has done the same thing should remove this cap if you are having this problem.

Now what I get is "Hello World" on the first line, and a counter on the second line, displaying the seconds since the Arduino has been reset. However, at random intervals the second line will display garbage, and continue counting. The first time it was near 60 seconds, then near 100, then near 400. If I reset the Arduino, the counting starts again, and the screen looks normal, but the problem comes back at some random point.

I am using .1uF decoupling caps: http://www.sparkfun.com/products/8375

I don’t know what you are referring to with a “decoupling cap between pins 12 and 13”. The only capacitors that I use are between the power and ground pins, as close to the chips as possible. I attached, to this post, a copy of the schematic of my ATtiny85 2w-LCD circuit. You can see the capacitor placement.