Alphanumeric LCD with Shift Register on Arduino

alphanumeric lcd arduino
One of the limitations of the small 8 bit microcontrollers like the Atmel ATMega family adopted by the Arduino board, is the reduced number of I/O ports. Among the main advantages of these microcontrollers: they are cheap, robust and simple to program. Therefore, also Arduino or one of its clones are cheap as well.


Microcontrollers in industrial applications are frequently used to manage almost simple circuits dedicated to a single task. We might think that an AVR microcontroller – e.g. the ATMega328p adopted by the Arduino UNO boards – has the sufficient number of pins to manage an alphanumeric LCD. In a complex industrial machine architecture that is more than sufficient.


The magic of the shift register
74HC595 datasheet
  • shift-in means that all the 8 bits (corresponding to 8 pins) can be set together and serially read from the input data pin.
  • shift-out is the opposite. We can send 8 bits serially to the output data pin shifted to the parallel 8-bits of the output pins.
Alphanumeric LCD, the controlled device
PCB
Schematic
ShiftLCD-Patched for last IDE
A last note about the circuit
LCD-Alpha 6


The complete circuit kit, including the alphanumeric LCD ready to use can be found on the Balearic Dynamics area. Use code ELEKTRO1008 to get the discount!

LCD-Alpha 5
we already know that the same ATMega328 microcontroller can do more than few basic functions. So why not many of them together?
In this first article we will propose to explore the power of the Arduino board with experiments, including circuitry and software, moving further to a high-level activity than a simple demonstration. Guys, with a little effort and few $$$ of components Arduino is the ideal tool to solve a lot of problems whereas other alternative solutions may be more expansive.

The Alphanumeric LCD for Arduino will be our first circuit: using only one component, and of course the LCD, we can povide our Arduino board with at least a 16×2 alphanumeric LCD display that we will use in all our future applications. This project consumes only three I/O pins, no matter what we decide to use, connected to a Shift Register. I have experienced that an alphanumeric LCD added to Arduino as a stable add-on devices is very useful during the debug phase of the sketches and gives much more options to our projects. Especially in case of unavailability of the Arduino USB port connected to the PC.
The shift register is an easy-to-manage component. We will dedicate a series of articles illustrating applications giving us the opportunity to develop circuits using one or more shift register saving a lot of I/O pins on our Arduino board.
Therefore you should expect that the software part (that is, the Arduino “Sketch”, more properly named firmware) covered extensively in the second part of this article, should be a bit complex. But the result is fascinating.
We should use a cheap parallel shift-out registers (it costs, depending on the country, a variable price around half dollar): the 74HC595
As a matter of fact there are two types of shift registers: shift-in (don’t worry, in future we will use this too) and shift-out parallel registers.
Regardless of the type of shift-register we are using, we need only three pins in our microcontroller. One pin is used for the serial data and the other two act like a clock to notify to the shift-register when a bit is ready to be shifted (shift-out) or the microcontroller is ready to acquire a new bit for reading (shift-in).
Another important aspect is the name of the component: register. In the assembler language a register is usually a place where a series of bits are stored for special purpose. In fact, the shift-registers not only are able to shift in one direction a certain number of bits but the bit status of every pin is persistent until another byte has not been completely sent (or received). This is perfect for us, as we need to write bytes to the LCD device managing a timing series of steps (e.g. writing a new character, moving the cursor, etc.)
At this point, the LCD Device will be connected with the 8-bits of the shift register (you can see the schematic and the circuit layout for the circuitry details).
So, what happens when we send a set of data to the LCD Device?
Our resulting sketch will be almost simple.
The most inspiring source to make this project comes from a blog post by Chris Parish proposing a similar circuit in 2010. Chris also provided a first modified version of the standard Arduino LCD Library supporting the shift register features. In 2010 Arduino libraries to manage shift registers were based on the 74LS164 component.
This arduinoshiftreglcd distributed on Google code was the only reference trying to solve the problem but included some bugs in the data timing and was not working properly.
The very valuable work by Chris consisted in modifying the 2010 version of theLiquidCrystal library distributed with the Arduino IDE (it was not supporting the shift register at all) and thanks to his work, in January 2010 the ShiftLCD Arduino library was born.
We suggest to download the ShiftLCD library from the link provided by this article. This version of the library implements the original Chris Parish ShiftLCD library with a couple of patches granting the compatibility with the most recent Arduino IDEs.
In the mentioned circuit implemented in 2010 by Chris Parish, you can find also the use of a high impedance MOSFET to control the LCD backlight. We have removed this component from our circuit because it proved useless with the cheap LCD devices working fine with or without backlight support. Note that the devices without the backlight support cost about the half compared to those with it, anyway offering a good visibility.
Next…
In this article we will consider the usage of this tool with some software developed to simplify and shorten the sketches with the LCD device as part of our Arduino architecture.


As promised in the above article, now it is time to see in detail how we can use the Alphanumeric LCD Display in our Arduino sketches.
The idea beside this project is to give a simple output empowering the Arduino board behavior without compromising the sketch space.

While the Alphanumeric LCD project for Arduino hardware aims to be simple, cheap and save as much as possible the available I/O ports (only three pins are used), in the same way the software to manage the display should fit leaving a reasonable free amount of memory for data and application firmware.
The AlphaLCD Library for Arduino
The sample application
The sample in depth
  • Display_Example.ino is the main source of the sketch
  • Strings.h is an example of a symbolic defined strings set can reduce the space for messages. Defining strings in a separate file is also useful as all the user strings are in a single file.
  • Version.h a simple example of few macro to show the sketch version without spending too much time to create one. If you want to save more space, remove this file from the project and remove the version method and include from the main source file.
  • LCD.h is the file including all the fixed constants and the local methods used to manage the display. Also useful to create a good documentation of the display features local methods. You should modify the three pin number assigned to the LCD Display depending on where you connect it to your Arduino board.
  1. #include <AlphaLCD.h>
  1. #include <Streaming.h>
  1.  
  1. // Include the LCD helper and the application string
  1. #include "LCD.h"
  1. #include "Strings.h"
  1. #include "Version.h"
  1.  
  1. //! AlphaLCD class instance for display hardware control
  1. AlphaLCD lcd(2,3,4);
  1. // Your setup initialization here
  1. void setup()
  1. {
  1. // Initializes the LCD library
  1. lcd.begin(LCDCHARS, LCDROWS);
  1. // Turn LCD On
  1. lcd.display();
  1. welcome();
  1. }
  1.  
  1. // Your Arduino application here
  1. void loop(void)
  1. {
  1.  
  1. // ...
  1.  
  1. }
The last method called in the setup function is welcome(), that is one of the methods defined in the third part of the sketch.

  1. void enable(bool s); ///< Set the display on or off
  1. void blink(bool set); ///< Set blink mode
  1. void error(String m); ///< shows an error message
  1. void error(String m, int x, int y); ///< shows an error message at specified coordinates
  1. void message(String m); ///< shows a string message
  1. void message(String m, int x, int y); ///< shows a string message at specified coordinates
  1. void clean(); ///< clean the LCD screen
  1. void dec(int n); ///< shows an integer in decimal format
  1. void hex(int n); ///< shows an integer in hexadeciaml format
  1. void bin(int n); ///< shows an integer in binary format
  1. void oct(int n); ///< shows an integer in octal format
  1. void welcome(); ///< shows the program welcome message


First you should download the AlphaLCD library for Arduino. Unzip the file and put the folder in in your Arduino library folder, so it can be used in the sketch, then restart the Arduino IDE.
The AlphaLCD library is derived by the original LCDShift library (you can find it in our previous article) with some small changes including a complete documentation also available separately in two formats: html interactive documentation AlphaLCD HtmlDoc and PDF AlphaLCD Manual. We suggest to take a look at the documentation to see the changes and how the library works.
Instead of the traditional – and in most case too obvious – “hello world” sketch we have added a sample application including a couple of source tips to simplify the usage of the LCD output everywhere in the sketch. It is a set of helper mathods to manage the LCD Alphanumeric display through the AlphaLCD library.
The sample application can be downloaded from here with the html interactivedocumentation and the PDF manual.
This sketch should be intended as a modificable skeleton, where you should add your program; the skeleton sketch, when compiled for Arduino UNO or Arduino Duemilanove, occupy less than 2,5 Kb of the 32Kb of available memory space.
If some of the functions included in the skeleton are not needed in your sketch for display purposes you can easly remove them without problems.
The sample application is organised in several files:
In addition to these files to simplify and get more flexibility in the LCD output functions we have included the use of the Streaming library for Arduino. The downloadable version available from here Streaming has already been optimized for the last versions of the Arduino IDE platforms (1.0 and more) Also for this library it is necessary, after downloading, to copy the unzipped folder in the Arduino library folder as usual. More details on the use and features of this library can be found on the Arduino playground site.
The first part of the sketch source don’t need great comments:
Note that the AlphaLCD library should be instantiated on top of the code in the same way of the traditional ShiftLCD library.
As you can see the only few calls are in the setup() method where the LCD library will be initalized.
In fact, at the end of the area that is supposed should contain the application code of the sketch there is a set of helper methods that can be used anywhere in the rest of the program, helpful to simplify most of the uses the Alphanumeric LCD is supposed for.
The following is a short list of the provided methods in the third section, based on previous experiences. Any author can remove or change those methods as well as adding other in a similar way.
For a more detailed explanation of the methods and their usage, and the parameters of every function please refer to the example documentation (available in htmlDisplay_Example HtmlDoc or PDF
Display_Example Manual format).


THANK YOU FOR VISITING..!!
PLEASE COMMENT

No comments:

Post a Comment