Tutorial-2 LCD Interfacing with Arduino
Introduction:
The LiquidCrystal library allows to control LCD displays that are compatible with the Hitachi HD44780 driver. A Liquid Crystal Display commonly abbreviated as LCD is basically a display unit built using Liquid Crystal technology. When building real world electronics based projects, need a medium/device to display output values and messages.
The most
basic form of electronic display available is 7 Segment display – which
has its own limitations. The next best available option is Liquid Crystal Displays which
comes in different size specifications. Out of all available LCD modules in
market, the most commonly used one is 16×2 LCD Module which
can display 32 ASCII characters in 2 lines (16 characters in 1 line). Other
commonly used LCD displays are 20×4 Character LCD, Nokia 5110 LCD module,
128×64 Graphical LCD Display and 2.4 inch TFT Touch screen LCD display.
Working of the project:
Firstly Need to enable the header file (‘#include <LiquidCrystal.h>’), this header file has instructions written in it, which enables the user to interface an LCD to UNO. With this header file need not have to send data to LCD bit by bit, this will all be taken care of and don’t have to write a program for sending data or a command to LCD bit by bit and In this LCD each character is displayed in a 5×7 pixel matrix.
After that need to tell the board which type of LCD we are using here. Since have so many different types of LCD (like 20x4, 16x2, 16x1 etc.). Here are going to interface a 16x2 and 20x4 LCD to the UNO so get ‘lcd.begin(16, 2); and ‘lcd.begin(20,4 );. For 16x1 get ‘lcd.begin(16, 1);’.In this instruction, going to tell the board where connected the pins. The pins which are connected need to be represented in order as “RS, En, D4, D5, D6, D7”. These pins are to be represented correctly. Since have connected RS to PIN0 and so on as show in the circuit diagram, we represent the pin number to board as “LiquidCrystal lcd(0, 1, 8, 9, 10, 11);”. The data which needs to be displayed in LCD should be written as “ cd.print("hello, world!");”. With this command the LCD displays ‘hello, world!’.
Table of
Content:
1. List of Inventories
1.1 Hardware Requirements
1.2 Software Requirements
1.3 Brief Introduction of component and calculate resistance
2. System Modelling
2.1 Circuit Diagram, Schematic Diagram and PCB Layout
2.2 Source Code
Programming
2.2.1 16x2 LCD
Interfacing with Arduino
2.2.2 20x4
LCD interfacing with Arduino
2.2.3
Scrolling text display on LCD
2.2.4 Special
Character Display on LCD
2.2.5 Demultiplexing of LCD
2.2.6 Design and play the game with Arduino
2.2.5 Demultiplexing of LCD
2.2.6 Design and play the game with Arduino
2.3 How to get .hex file
2.4 Detail explanation of code
1. List of
Inventories:
1.1 Hardware:
2. Jumper wires - 12 (Male to male)
3. Resistor: 65 ohm
4. Potentiometer: 1k ohm
5. Power Supply: 1)
9 to 12 Vdc & <= 1A (For Arduino)
+2) 5 to 9 Vdc (For LCD)
Development
Board:
1. Arduino or Genuino UNO
1.2 Software and Library:
1. Arduino Software
1.2 Arduino for Linux OS
3. Library
1.3 Brief
introduction of the components:
1) Arduino UNO
Arduino is a simple to use microcontroller board used in most engineering
projects where automation is needed. IO devices like Sensor, modules and many
others things can be interfaced with the Arduino board to accomplish a task.
Arduino is an open source board which means that all the design specifications,
schematics, and software library are available openly for all users. The
Arduino board has gained popularity today among many hobbyists because it is
friendly and easy to use and can be used to design complex projects. It can be
easily programmed using its own software; the Arduino IDE. The nature of the
Arduino language is friendly and makes it easy for everyone to develop
prototypes and hardware to suit their intended purpose.
2) LCD
The liquid crystal display uses
the property of light monitoring of liquid crystal and they do not emit the
light directly. The Liquid crystal display is a flat panel display or the
electronic visual display. With low information, content the LCD’ s are
obtained in the fixed image or the arbitrary image which are displayed or
hidden like present words, digits, or 7 segment display. The arbitrary images are made up of large no of small
pixels and the element has larger elements.
I. What is a LCD (Liquid
Crystal Display)?
A liquid crystal display or LCD draws its
definition from its name itself. It is combination of two states of matter, the
solid and the liquid. LCD uses a liquid crystal to produce a visible image.
Liquid crystal displays are super-thin technology display screen that are
generally used in laptop computer screen, TVs, cell phones and portable video
games. LCD’s technologies allow displays to be much thinner when compared to
cathode ray tube (CRT) technology.Liquid crystal display is composed of several layers which include two
polarized panel filters and electrodes. LCD technology is used for displaying
the image in some other electronic devices. Light is projected from a lens on a
layer of liquid crystal. This combination of colored light with the gray scale
image of the crystal (formed as electric current flows through the crystal)
forms the colored image. This image is then displayed on the screen.
II. How LCD constructed?
LCD Layered
Diagram
1. The basic structure of LCD should be controlled by
changing the applied current.
2. Must use a polarized light.
3. Liquid crystal should able be to control both of
the operation to transmit or can also able to change the polarized light.
As mentioned above that need to take two polarized glass pieces filter in the making of the liquid crystal. The glass which does not have a polarized film on the surface of it must be rubbed with a special polymer which will create microscopic grooves on the surface of the polarized glass filter. The grooves must be in the same direction of the polarized film. Now we have to add a coating of pneumatic liquid phase crystal on one of the polarized filter of the polarized glass. The microscopic channel cause the first layer molecule to align with filter orientation. When the right angle appears at the first layer piece, we should add a second piece of glass with the polarized film. The first filter will be naturally polarized as the light strikes it at the starting stage.
Thus the light travels through each layer and guided on the next with
the help of molecule. The molecule tends to change its plane of vibration of
the light in order to match their angle. When the light reaches to the
far end of the liquid crystal substance, it vibrates at the same angle as that
of the final layer of the molecule vibrates. The light is allowed to enter into
the device only if the second layer of the polarized glass matches with the
final layer of the molecule.
III. How LCDs Work?
The principle behind the LCD’s is that when an electrical current is
applied to the liquid crystal molecule, the molecule tends to untwist. This
causes the angle of light which is passing through the molecule of the
polarized glass and also cause a change in the angle of the top polarizing
filter. As a result a little light is allowed to pass the polarized glass
through a particular area of the LCD. Thus that particular area will become
dark compared to other. The LCD works on the principle of blocking light. While
constructing the LCD’s, a reflected mirror is arranged at the back. An
electrode plane is made of indium-tin oxide which is kept on top and a
polarized glass with a polarizing film is also added on the bottom of the
device. The complete region of the LCD has to be enclosed by a common electrode
and above it should be the liquid crystal matter.
Next comes to the second piece of glass with an electrode in the form of
the rectangle on the bottom and, on top, another polarizing film. It must be
considered that both the pieces are kept at right angles. When there is no
current, the light passes through the front of the LCD it will be reflected by
the mirror and bounced back. As the electrode is connected to a battery the
current from it will cause the liquid crystals between the common-plane
electrode and the electrode shaped like a rectangle to untwist. Thus the light
is blocked from passing through. That particular rectangular area appears
blank.
IV. Liquid Crystal Display of 16×2
The 16×2 liquid crystal display contains two horizontal lines and they
are used for compressing the space of 16 display characters. In inbuilt, the
LCD has two registers which are described below. The LCDs have
a parallel interface, meaning that the microcontroller has to manipulate
several interface pins at once to control the display. The interface consists
of the following pins:
· A register select (RS) pin that
controls where in the LCD's memory you're writing data to. You can select
either the data register, which holds what goes on the screen, or an
instruction register, which is where the LCD's controller looks for
instructions on what to do next.
· A Read/Write (R/W) pin that
selects reading mode or writing mode
· An Enable pin that enables
writing to the registers
· 8 data pins (D0 -D7). The states of
these pins (high or low) are the bits that you're writing to a register when
you write, or the values you're reading when you read.
· There's
also a display constrast pin
(Vo), power
supply pins (+5V and Gnd) and LED Backlight (Bklt+ and BKlt-) pins
that you can use to power the LCD, control the display contrast, and turn on
and off the LED backlight, respectively.
· The
process of controlling the display involves putting the data that form the
image of what you want to display into the data registers, then putting
instructions in the instruction register. The LiquidCrystal Library simplifies this for you so
you don't need to know the low-level instructions.The Hitachi-compatible LCDs can be controlled in two modes: 4-bit or 8-bit.
The 4-bit mode requires seven I/O pins from the Arduino, while the 8-bit mode
requires 11 pins. For displaying text on the screen, you can do most everything
in 4-bit mode, so example shows how to control a 16x2 LCD in 4-bit mode.
· Pin1 (Vss):Ground
pin of the LCD module.
· Pin2 (Vcc):
Power to LCD module (+5V supply is given to this pin)
· Pin3 (VEE):Contrast
adjustment pin. This is done by connecting the ends of a 10K potentimeter to
+5V and ground and then connecting the slider pin to the VEE pin. The voltage
at the VEE pin defines the contrast. The normal setting is between 0.4 and
0.9V.
· Pin4 (RS): Register
select pin.The JHD162A has two registers namely command register and data register.
Logic HIGH at RS pin selects data register and logic LOW at RS pin selects
command register. If we make the RS pin HIGH and feed an input to the data
lines (DB0 to DB7), this input will be treated as data to display on LCD
screen. If we make the RS pin LOW and feed an input to the data lines, then
this will be treated as a command ( a command to be written to LCD controller –
like positioning cursor or clear screen or scroll).
· Pin5 (R/W):
Read/Write modes. This pin is used for selecting between read and write modes.
Logic HIGH at this pin activates read mode and logic LOW at this pin activates
write mode.
· Pin6 (E): This
pin is meant for enabling the LCD module. A HIGH to LOW signal at this pin will
enable the module.
· Pin7 (DB0) to Pin14(DB7):
 These are data pins. The commands and data are fed to the LCD module
though these pins.
· Pin15 (LED+):
Anode of the back light LED. When operated on 5V, a 560 ohm resistor should be
connected in series to this pin. In arduino based projects the back light LED
can be powered from the 3.3V source on the arduino board.
· Pin16 (LED-):
Cathode of the back light LED.
· Resistance to adjust LCD Contrast:
On an LCD the
potentiometer is used to adjust the bias
level of the LCD - that is the contrast. You need to use
it to set a voltage between Vcc and Vee, which you feed into Vo. That is, a
voltage somewhere between +5V and -5V. Contrast adjustment; the best way is to use a
variable resistor such as a potentiometer. The output of the potentiometer is
connected to this pin. Rotate the potentiometer knob forward and backwards to adjust the LCD contrast. The contrast pin on
the LCD requires a fairly small voltage for ideal display conditions.The lower the voltage the higher the contrast and vice versa.By using this formula we find the resistance value used across the
led.Led resistor value can be calculated by Ohm’s law:
Vs = R x I
where:
where:
- Vs is
the source voltage, measured in volts (V),
- I is
the current, measured in Amperes (Amps/A), and
- R is
the resistance, measured in Ohms (Ω).
Example:
- Vs = 5V
- I =
5 mA (Minimum) & 50 mA (Maximum)
- R = 1
K ohm & 100 ohm
From the
calculation, we get 100 ohms to 1K ohm resistance for 5mA and 50 mA current.
but roughly use around 1 K ohm potentiometer. Only LCD’s Contrast will vary.
but roughly use around 1 K ohm potentiometer. Only LCD’s Contrast will vary.
· Resistance to adjust LCD back light Intensity:
To improve visibility, particularly in dark locations,
many LCDs (liquid crystal displays) include LEDs (light emitting diodes) behind
the screen to provide a light source. This is called a back light.Some
industry standard LCDs have 14-pin connectors and some have 16-pin connectors.
The displays with 16-pin connectors usually use the top two pins for the
back light. In this case, the Nanox LCD has a 14-pin connector with a separate
LED back light.
Note: Do NOT hook power directly to
the back light, or else it will instantly overheat and burn out. Instead, use a
resistor to limit the current flow.
By using this formula we find the resistance value used across the
led.Led resistor value can be calculated by Ohm’s law:
R=(V s-V led)/I led
where:
- V s is the source voltage, measured in
volts (V),
- V led is the voltage drop across the
LED, measured in volts (V),
- I led is the current through the LED,
measured in Amperes (Amps/A), and
- R is the resistance, measured in
Ohms (Ω).
· Example:
- Vs = 5V
- Vled = 3.7V
- Iled = 20 mA
- R = 65 ohm
From the calculation, get 65 ohms. but roughly we
use around 70 ohm resistor. Only LED’s intensity will vary.
2. System
modelling:
Before wiring the LCD screen to your Arduino or Genuino board we suggest to solder a pin header strip to the 14 (or 16) pin count connector of the LCD screen, as you can see in the image above.
To wire your LCD screen to your board, connect the following pins
· LCD RS pin to digital pin 13
· LCD Enable pin to digital pin 12
· LCD D4 pin to digital pin 5
· LCD D5 pin to digital pin 4
· LCD D6 pin to digital pin 3
· LCD D7 pin to digital pin 2
Schematic Diagram
PCB Layout
To wire your LCD screen to your board, connect the following pins
· LCD RS pin to digital pin 13
· LCD Enable pin to digital pin 12
· LCD D4 pin to digital pin 5
· LCD D5 pin to digital pin 4
· LCD D6 pin to digital pin 3
· LCD D7 pin to digital pin 2
Schematic Diagram
PCB Layout
2.2 Source Code programming:
2.1.1 LCD Interfacing with Arduino
Open the Arduino IDE and
write the following program to blink an LED. I have written the Blink
(File àExample à Basic à Liquid crystal à Display) example provided in
the book Getting Started with Arduino. You may see the screenshot below.
After writing the program you may save it with a file name of your choice (find
File–>Save on menu bar of IDE)
To Download the code click here
Read About
Read About
III. How to get .hex file ?
Result:
1) Simulate design online click here to simulate
Download the code from here
2.2.3 Scrolling text display on LCD
Here is a simple example of how to create letter ‘b’ in CG-RAM.
Result:
1) Simulate design online click here to simulate
2) Published by, Electronics with shreyash
2.2.2 20x4 LCD Interfacing with Arduino
The 20×4 LCD module pin out diagram is very much
same as the 16×2 LCD module pin out diagram. It is same with the number of
pins, order of pins and the purpose of pins. So the interfacing circuit diagram
is also very same as the 16×2 LCD module with Arduino
2.2.3 Scrolling text display on LCD
A simple program for scrolling
a text message on the LCD screen using Arduino is shown here. This is done
using the “scroll()” method defined inside
LiquidCrystal.h library. For example the method “lcd.scrollDisplayRight()”
will scroll the display to right and the method”lcd.scrollDisplayLeft()”
will scroll the display to left. A “for” loop is used for selecting the number
of positions to scroll at a time. In the program shown below, it is chosen to
be 2 because the text to be displayed is comparatively long. For shorter texts
more number of positions must be scrolled at a time to get a smooth display.
Result:
Result:
1) Simulate design online, click here to simulate
2) Published by, Electronics with shreyash:
Download the code from here
2.2.4 Special character Display on LCD
Here is a simple example of how to create letter ‘b’ in CG-RAM.
The Array for generating ‘b’ is char
b[7]={0x10,0x10,0x16,0x19,0x11,0x11,0x1E}; That is,
·
Send
address where you want to create character.
·
Now
create your character at this address. Send the ‘b’ character array values
defined above one by one to the data register of LCD.
·
To
print the generated character at 0x40. Send command 0 to command register of
LCD. The table below would explain this more clearly.
2) Published by, Electronics with shreyash:
Download the code from here
2. 2.4 Demultiplexing of LCD
Download the code from here
2.4 Design and play the game with Arduino
Download the code from here
2. 2.4 Demultiplexing of LCD
We have seen
parallel interface technique using Arduino library and we know that it requires
6 IO Lines, Now let’s see how we can reduce required IO’s using 74HC595. We
know that we can reduce number IO required by using I2C based LCD interface
circuit; It costs ten times more than 74HC595 Circuit
Result:
1) Published by, Electronics with shreyash:
2.4 Design and play the game with Arduino
Design and play the game is simple with Arduino microcontroller which is another example of interfacing of LCD with Arduino.
Result:
2) Published by, Electronics with shreyash: Result:
1) Simulate design online, click here to simulate
- See Also
Join our Community
Comments
Post a Comment