will be read-only starting December 31st, 2018. For more info please look at this Forum Post

Arduino's LiquidCrystal Library with SPI
Author:  Juan Hernandez (juanh0238)



This is the same library that comes with Arduino I just added SPI functionality to use a Shift Register (I was using a 74HC595). it can be used with SPI or the same way it was intended with six or eight wires or whatever. all I did was to add a way for it to communicate with the LCD using SPI and a shift register other then that it is the exact same. I figured why write another library when there was one already written and free and fully functional and made public for the same purpose. will Linux had become what it is if people would have writen a diferent operating system for every project they had, or functionality they needed I think not. (that is a message for everyone) so here it is I hope it is of use. I also hope no one else has written it already and I just wasted my time, since I am new and learning it takes me longer than it would a seasoned programer, also as I mentioned above I don't like to reinvent the wheel unless the code is not readily available. it was good learning though.

Download, install and import

 This version only works in arduino versions before 1.0

Download here:

 this version works on arduino 1.0 and the newer versions

Download here:

Breadboard Sketch: LCD_using_74HC595_and_SPI.png

and replace the LiquidCrystal folder in the libraries folder of your Arduino installation directory with this one.

You can see an example sketch from "File -> Examples -> LiquidCrystal -> HelloWorld_SPI".

To create a new sketch, select from the menubar "Sketch->Import Library->LiquidCrystal". Once the library is imported, an '#include <LiquidCrystal.h>' line will appear at the top of your Sketch. you will also need to include the SPI library. (in other words just as you would use the regular Library since its the same) the only diference is it takes only one parameter the sspin for SPI (or the latchPin of the register) if you want to use SPI otherwise it is used the same.

SPI only Library

I forked original code from Juan Hernandez and created simple, modernized, SPI only Library. ShiftedLCD Library is ready to use for those who want to use their other SPI devices like SD, Ethernet, RFID, etc together with Shifted LCDs.

Original code was modified both parallel and SPI (serial) communication, which leads a bug that other digitalPins on Arduino UNO state is not known (for example if you have a INPUT pin with PULLUP resistor is enabled, you couldn’t determine its state (HIGH or LOW) when it’s floating - because of Initializing parallel communication)

I modified the Library to reduce complications, like collision with native Library, removed Parallel communication support.


I'll just use the example that is in the Examples folder:

  1. #include <SPI.h>
  3. //some comments missing here but they will be in the original sketch
  5. // include the library code:
  6. #include <LiquidCrystal.h>
  8. // initialize the library with the number of the sspin
  9. //(or the latch pin of the 74HC595)
  10. LiquidCrystal lcd(10);
  12. void setup() {
  13.   // set up the LCD's number of columns and rows:
  14.   lcd.begin(20, 4);
  15.   // Print a message to the LCD.
  16.   lcd.print("hello, world!");
  17. }
  19. void loop() {
  20.   // set the cursor to column 0, line 1
  21.   // (note: line 1 is the second row, since counting begins with 0):
  22.   lcd.setCursor(0, 1);
  23.   // print the number of seconds since reset:
  24.   lcd.print(millis()/1000);
  25. }


The 74HC595 or the CD4094 shift register can be used. They operate in the same way, but they have different layouts and different names for the pins.

A clock signal is used for a serial input of 8 data-bits into a shift-register. The contents of the shift-register are copied into a latch with a strobe pulse. The outputs of the latch register is on the output pins.

Data = The data bits (74HC595 pin 14 "DS").
Clock = The shift clock for the data bits (74HC595 pin 11 "SHCP").
Latch = The strobe that copies the databits into the latch (74HC595 pin 12 "STCP").

Connect to SPI:
Data = MOSI = Arduino pin 11
Clock = SCK = Arduino pin 13
Latch = SS = Arduino pin 10, but also other pins can be used.

BreadBoard Ilustration

Note:I had to connect pin 5 on the LCD to gnd (not on diagram) to make it work.

Using those 2 leftover pins Q0, Q2

I've found a workaround with the library.

Modify the LiquidCrystal.h by making the _bitString variable and spiSendOut() functions public.


  1. public:
  2.   uint8_t _bitString;
  3.   void spiSendOut();

Then by setting the value of bitString and sending it you can set the register values; 1 = q0, 4=q2, 5=q0+q2


  1. lcd._bitString=VALUE;
  2. lcd.spiSendOut();

This is really useful of you don't want to waste those pins on your 74HC595!

Information about this page

Last Modified: November 17, 2016, at 04:36 AM
By: omersiar