16×2 LCD Module Pin Out Diagram
16×2 LCD Module Pin Out Diagram
The JHD162A lcd module has 16 pins and can be operated in 4-bit mode or 8-bit mode. Here
we are using the LCD module in 4-bit mode. Before going in to the details of the project, let’s
have a look at the JHD162A LCD module.The schematic of a JHD162A LCD pin diagram is
given below.
The name and functions of each pin of the 16×2 LCD module is given below.
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 anddata 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.
Most of the 16×2 modules available are compatible with the Hitachi HD44780 LCD controller. This
allows you to buy almost any device and be sure it is going to work in much the same way as any
other. There are loads to choose from on eBay with different coloured backlights. The one I
purchased had a blue backlight.
LCD
Function Pi Function Pi Pin
Pin
04 RS GPIO7 P1-26
05 RW GND P1-06
06 E GPIO8 P1-24
07 Data 0
08 Data 1
09 Data 2
10 Data 3
16 GND P1-06
NOTE : The RW pin allows the device to be be put into read or write mode. I wanted to send data to
the device but did not want it to send data to the Pi so I tied this pin to ground. The Pi can not tolerate
5V inputs on its GPIO header. Tying RW to ground makes sure the device does not attempt to pull the
data lines to 5V which would damage the Pi.
Wiring Checks
Here are some sanity checks before you power up your circuit for the first time :
You can control a HD44780 style display using any programming environment you like but my
weapon of choice is Python. I use the RPi.GPIO library to provide access to the GPIO.
Here is my code :
1 #!/usr/bin/python
2 #--------------------------------------
10 #
# Date : 06/04/2015
12
#
13
# http://www.raspberrypi-spy.co.uk/
14 #
15 #--------------------------------------
16
32
33 #import
35 import time
36
LCD_RS = 7
38
LCD_E = 8
39
LCD_D4 = 25
40
41 LCD_D5 = 24
42 LCD_D6 = 23
LCD_D7 = 18
43
44
# Define some device constants
45
LCD_WIDTH = 16 # Maximum characters per line
46
LCD_CHR = True
47
LCD_CMD = False
48
49
LCD_LINE_1 = 0x80 # LCD RAM address for the 1st line
50
LCD_LINE_2 = 0xC0 # LCD RAM address for the 2nd line
51
52
# Timing constants
53 E_PULSE = 0.0005
54 E_DELAY = 0.0005
55
56 def main():
58 GPIO.setwarnings(False)
65
66 # Initialise display
67 lcd_init()
68
69 while True:
70
lcd_string("Rasbperry Pi",LCD_LINE_1)
72
lcd_string("16x2 LCD Test",LCD_LINE_2)
73
74
time.sleep(3) # 3 second delay
75
76
# Send some text
77
lcd_string("1234567890123456",LCD_LINE_1)
78
lcd_string("abcdefghijklmnop",LCD_LINE_2)
79
80 time.sleep(3) # 3 second delay
81
82 # Send some text
83 lcd_string("RaspberryPi-spy",LCD_LINE_1)
84 lcd_string(".co.uk",LCD_LINE_2)
85
time.sleep(3)
86
87
101 time.sleep(E_DELAY)
102
if bits&0x10==0x10:
115
GPIO.output(LCD_D4, True)
116
if bits&0x20==0x20:
117
GPIO.output(LCD_D5, True)
118
if bits&0x40==0x40:
119
GPIO.output(LCD_D6, True)
120 if bits&0x80==0x80:
124 lcd_toggle_enable()
125
if bits&0x08==0x08:
136
GPIO.output(LCD_D7, True)
137
138
# Toggle 'Enable' pin
139
lcd_toggle_enable()
140
141
def lcd_toggle_enable():
142
# Toggle enable
143 time.sleep(E_DELAY)
145 time.sleep(E_PULSE)
147 time.sleep(E_DELAY)
148
149 def lcd_string(message,line):
151
163 pass
164 finally:
lcd_string("Goodbye!",LCD_LINE_1)
s166
GPIO.cleanup()
167
168
169
170
171
172
173
174
175
176
177
178
179
180