We do not take any responsibility for possible errors in the guide or errors that you might do wiring it up. Incorrect wiring can result in damaged sensor or damaged Raspberry Pi.
The display I am using has 2 lines with 16 letters each. Same example will also work for HD44780 based displays that have 4 lines with 20 letters per line.
For more specialized versions (custom sizes of the HD44780 then you can find information on those in part 2)
Pieces we use:
Soldering:
Usually those displays do not come with pins soldered on them. So you can either solder header pins on it or wires. The displays take standard header pins with 2,54 mm spacing.
This is how it looked like after I quickly soldered the one I tested:
I opted for letting the pins come out at back so I can push the display into a breadboard, or later if I use the display in permanent project I can use the display in a case without the pins sticking out at front.
Connecting the LCD:
When connecting then its best to connect LCD pins 1, 2, 15 and 16 first as well as fully connecting the potentiometer (see connection map bellow).
Then turn on the Raspberry PI and adjust the potentiometer until you clearly see boxes outlining character placeholders in one of the lines in the display. If you are unable to get the placeholders, then re-check your connections.
Once you can see the placeholders clearly then you can power down your Raspberry Pi and proceed to connect the rest of the pins on the display.
LCD | Raspberry PI cobbler |
Potentiometer (10 kΩ) | 560 Ω Resistor |
---|---|---|---|
#1 (GND) or (VSS) | GND | ||
#2 (VCC) | 5V | ||
#3 (Vo) | Middle pin | ||
#4 (RS) | GPIO25 | ||
#5 (RW) | GND | ||
#6 (EN) | GPIO24 | ||
#7, #8, #9, #10 | Not used | ||
#11 (D4) | GPIO23 | ||
#12 (D5) | GPIO17 | ||
#13 (D6) | GPIO21 | ||
#14 (D7) | GPIO22 | ||
#15 (LED+) | To resistor | ||
#16 (LED-) | GND | ||
5V | To resistor | ||
GND | #1 | ||
5V | #3 |
Make sure that your Raspberry PI is not turned on when your wiring it up.
If you need more information about the GPIO headers on Raspberry Pi or other boards then click bellow.
Raspberry Pi Pin guideOrange Pi One Pin guideOrange Pi Pin guide for most H3 modelsOrange Pi Zero 3 Pin guideOrange Pi 5 Plus Pin guideRock 64 Pin guideThe Xojo Code
This example uses whole screen driver class which you will find in the example project in Git. We will only post highlight here in the code since the code is a bit long.
Private Property mLCD As HD44780Display
And then Opening event for the Window:
Sub Opening() Handles Opening
try
using Gpiod
var chip as Chip = Chip.Open("/dev/gpiochip0")
Const kRSPin as UInt32 = 25
Const kEPin as UInt32 = 24
Const kD4Pin as UInt32 = 23
Const kD5Pin as UInt32 = 17
Const kD6Pin as UInt32 = 21
Const kD7Pin as UInt32 = 22
mLCD = new HD44780Display(chip, kRSPin, kEPin, kD4Pin, kD5Pin, kD6Pin, kD7Pin)
var glyph as LCDGlyph
// We create some glyph, the display can store max 8 at once, but we can set up as many as we want here since our code
// will apply them in smart way so that the limit will not be how many are set up but the limit will be 8 different custom
//glyphs per line in the display.
// A Glyph that represents the Icelandic Thorn letter (upper case)
glyph = new LCDGlyph
glyph.SetLine(0,&b10000)
glyph.SetLine(1,&b10000)
glyph.SetLine(2,&b11100)
glyph.SetLine(3,&b10010)
glyph.SetLine(4,&b10010)
glyph.SetLine(5,&b11100)
glyph.SetLine(6,&b10000)
glyph.SetLine(7,&b10000)
glyph.LetterCode = Asc("Þ")
mLCD.RegisterCustomGlyph(glyph)
// A Glyph that represents the Icelandic Thorn letter (lower case)
glyph = new LCDGlyph
glyph.SetLine(0,&b10000)
glyph.SetLine(1,&b10000)
glyph.SetLine(2,&b11100)
glyph.SetLine(3,&b10010)
glyph.SetLine(4,&b10010)
glyph.SetLine(5,&b10010)
glyph.SetLine(6,&b11100)
glyph.SetLine(7,&b10000)
glyph.LetterCode = Asc("þ")
mLCD.RegisterCustomGlyph(glyph)
// A Glyph that represents the ó letter (lower case)
glyph = new LCDGlyph
glyph.SetLine(0,&b00010)
glyph.SetLine(1,&b00100)
glyph.SetLine(2,&b01110)
glyph.SetLine(3,&b10001)
glyph.SetLine(4,&b10001)
glyph.SetLine(5,&b10001)
glyph.SetLine(6,&b01110)
glyph.SetLine(7,&b00000)
glyph.LetterCode = Asc("ó")
mLCD.RegisterCustomGlyph(glyph)
// A Glyph that represents the ö letter (lower case)
glyph = new LCDGlyph
glyph.SetLine(0,&b01010)
glyph.SetLine(1,&b00000)
glyph.SetLine(2,&b01110)
glyph.SetLine(3,&b10001)
glyph.SetLine(4,&b10001)
glyph.SetLine(5,&b10001)
glyph.SetLine(6,&b01110)
glyph.SetLine(7,&b00000)
glyph.LetterCode = Asc("ö")
mLCD.RegisterCustomGlyph(glyph)
// A Glyph that represents the í letter (lower case)
glyph = new LCDGlyph
glyph.SetLine(0,&b00010)
glyph.SetLine(1,&b00100)
glyph.SetLine(2,&b00000)
glyph.SetLine(3,&b01100)
glyph.SetLine(4,&b00100)
glyph.SetLine(5,&b00100)
glyph.SetLine(6,&b01110)
glyph.SetLine(7,&b00000)
glyph.LetterCode = Asc("í")
mLCD.RegisterCustomGlyph(glyph)
catch e as GpiodException
MessageBox(e.Message)
end try
End Sub
Sending text to the display:
Sub Action() Handles Action
try
mLCD.Clear()
mLCD.Home()
mLCD.SetMessage(tbLine1.Text, 1,true)
mLCD.SetMessage(tbLine2.Text, 2,true)
catch ex as GpiodException
MessageBox(ex.Message)
end try
End Sub
You can find this example code at Example code for GPIO guides.
And here are example results what the code generates, notice the Icelandic letters that the display should not support normally without custom glyphs:
The mask when setting up custom Glyphs is a Binary mask for each line that consists of 5 bits, and you have 8 lines.
So graphically setting up a glyph would look like this:
Which would give the following mask:
glyph = new GPIO.LCDGlyph
glyph.SetLine(0,&b00010)
glyph.SetLine(1,&b00100)
glyph.SetLine(2,&b00000)
glyph.SetLine(3,&b01100)
glyph.SetLine(4,&b00100)
glyph.SetLine(5,&b00100)
glyph.SetLine(6,&b01110)
glyph.SetLine(7,&b00000)