0% found this document useful (0 votes)
2K views

16×2 LCD Module Pin Out Diagram

The document describes the pinout of a 16x2 LCD module. It has 16 pins including ground, power, contrast adjustment, register select, read/write, enable, and 8 data pins. The summary provides the function of the key pins including ground, power, register select for selecting command or data registers, enable for sending data to the LCD, and 8 data pins for sending commands and characters to the LCD.

Uploaded by

vijay b
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

16×2 LCD Module Pin Out Diagram

The document describes the pinout of a 16x2 LCD module. It has 16 pins including ground, power, contrast adjustment, register select, read/write, enable, and 8 data pins. The summary provides the function of the key pins including ground, power, register select for selecting command or data registers, enable for sending data to the LCD, and 8 data pins for sending commands and characters to the LCD.

Uploaded by

vijay b
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

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.

16×2 LCD Module Control Using Python


 88

BY MATT ON JULY 27, 2012HARDWARE, PYTHON, TUTORIALS & HELP


Once you’ve played with LEDs, switches and stepper motors the next natural step is 16×2
alphanumeric LCD modules. These modules are cheap (less than $10) and easy to interface
to the Raspberry Pi. They have 16 connections but you only need to use 6 GPIO pins on
your Pi.

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 Module Hardware

The pinout of the module is :


1. Ground
2. VCC (Usually +5V)
3. Contrast adjustment (VO)
4. Register Select (RS).
RS=0: Command, RS=1: Data
5. Read/Write (R/W).
R/W=0: Write, R/W=1: Read
6. Enable
7. Bit 0 (Not required in 4-bit operation)
8. Bit 1 (Not required in 4-bit operation)
9. Bit 2 (Not required in 4-bit operation)
10. Bit 3 (Not required in 4-bit operation)
11. Bit 4
12. Bit 5
13. Bit 6
14. Bit 7
15. LED Backlight Anode (+)
16. LED Backlight Cathode (-)
Usually the device requires 8 data lines to provide data to Bits 0-7. However the device can be set to
a “4 bit” mode which allows you to send data in two chunks (or nibbles) of 4 bits. This is great as it
reduces the number of GPIO connections you require when interfacing with your Pi.

Here is how I wired up my LCD :

LCD
Function Pi Function Pi Pin
Pin

01 GND GND P1-06

02 +5V +5V P1-02

03 Contrast GND P1-06

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

11 Data 4 GPIO25 P1-22

12 Data 5 GPIO24 P1-18

13 Data 6 GPIO23 P1-16


14 Data 7 GPIO18 P1-12

15 +5V via 560ohm

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 :

 Pin 1 (GND), 3 (Contrast), 5 (RW) and 16 (LED -) ( should be tied to ground.


 Pin 2 should be tied to 5V. Pin 15 should have a resistor inline to 5V to protect the backlight.
 Pin 7-10 are unconnected
 Pin 11-14 are connected to GPIO pins on the Pi
Python

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 #--------------------------------------

#    ___  ___  _ ____


3
#   / _ \/ _ \(_) __/__  __ __
4
#  / , _/ ___/ /\ \/ _ \/ // /
5
# /_/|_/_/  /_/___/ .__/\_, /
6
#                /_/   /___/
7
#
8 #  lcd_16x2.py

9 #  16x2 LCD Test Script

10 #

11 # Author : Matt Hawkins

# Date   : 06/04/2015
12
#
13
# http://www.raspberrypi-spy.co.uk/
14 #

15 #--------------------------------------

16  

# The wiring for the LCD is as follows:


17
# 1 : GND
18
# 2 : 5V
19
# 3 : Contrast (0-5V)*
20
# 4 : RS (Register Select)
21
# 5 : R/W (Read Write)       - GROUND THIS PIN
22 # 6 : Enable or Strobe

23 # 7 : Data Bit 0             - NOT USED

24 # 8 : Data Bit 1             - NOT USED

25 # 9 : Data Bit 2             - NOT USED

# 10: Data Bit 3             - NOT USED


26
# 11: Data Bit 4
27
# 12: Data Bit 5
28
# 13: Data Bit 6
29
# 14: Data Bit 7
30
# 15: LCD Backlight +5V**
31 # 16: LCD Backlight GND

32  
33 #import

34 import RPi.GPIO as GPIO

35 import time

36  

37 # Define GPIO to LCD mapping

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():

57   # Main program block

58   GPIO.setwarnings(False)

  GPIO.setmode(GPIO.BCM)       # Use BCM GPIO numbers


59
  GPIO.setup(LCD_E, GPIO.OUT)  # E
60
  GPIO.setup(LCD_RS, GPIO.OUT) # RS
61
  GPIO.setup(LCD_D4, GPIO.OUT) # DB4
62
  GPIO.setup(LCD_D5, GPIO.OUT) # DB5
63
  GPIO.setup(LCD_D6, GPIO.OUT) # DB6
64   GPIO.setup(LCD_D7, GPIO.OUT) # DB7

65  
66   # Initialise display

67   lcd_init()
68  

69   while True:

70  

71     # Send some test

    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  

    # Send some text


88
    lcd_string("Follow me on",LCD_LINE_1)
89
    lcd_string("Twitter @RPiSpy",LCD_LINE_2)
90
 
91
    time.sleep(3)
92
 
93
def lcd_init():
94
  # Initialise display
95   lcd_byte(0x33,LCD_CMD) # 110011 Initialise

96   lcd_byte(0x32,LCD_CMD) # 110010 Initialise

  lcd_byte(0x06,LCD_CMD) # 000110 Cursor move direction


97
  lcd_byte(0x0C,LCD_CMD) # 001100 Display On,Cursor Off, Blink Off
98
  lcd_byte(0x28,LCD_CMD) # 101000 Data length, number of lines, font
99 size

100   lcd_byte(0x01,LCD_CMD) # 000001 Clear display

101   time.sleep(E_DELAY)

102  

def lcd_byte(bits, mode):


103
  # Send byte to data pins
104
  # bits = data
105
  # mode = True  for character
106
  #        False for command
107
 
108
  GPIO.output(LCD_RS, mode) # RS
109
 
110   # High bits

111   GPIO.output(LCD_D4, False)

112   GPIO.output(LCD_D5, False)

113   GPIO.output(LCD_D6, False)

114   GPIO.output(LCD_D7, False)

  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:

121     GPIO.output(LCD_D7, True)


122  

123   # Toggle 'Enable' pin

124   lcd_toggle_enable()

125  

  # Low bits


126
  GPIO.output(LCD_D4, False)
127
  GPIO.output(LCD_D5, False)
128
  GPIO.output(LCD_D6, False)
129
  GPIO.output(LCD_D7, False)
130
  if bits&0x01==0x01:
131     GPIO.output(LCD_D4, True)

132   if bits&0x02==0x02:

133     GPIO.output(LCD_D5, True)

134   if bits&0x04==0x04:

135     GPIO.output(LCD_D6, True)

  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)

144   GPIO.output(LCD_E, True)

145   time.sleep(E_PULSE)

146   GPIO.output(LCD_E, False)

147   time.sleep(E_DELAY)

148  
149 def lcd_string(message,line):

150   # Send string to display

151  

  message = message.ljust(LCD_WIDTH," ")


152
 
153
  lcd_byte(line, LCD_CMD)
154
 
155
  for i in range(LCD_WIDTH):
156
    lcd_byte(ord(message[i]),LCD_CHR)
157
 
158
if __name__ == '__main__':
159
 
160
  try:
161     main()

162   except KeyboardInterrupt:

163     pass

164   finally:

165     lcd_byte(0x01, LCD_CMD)

    lcd_string("Goodbye!",LCD_LINE_1)
s166
    GPIO.cleanup()
167

168

169

170

171

172

173

174

175
176

177

178

179

180

You might also like