HD44780 based LCD display

In this example we are going to connect to HD44780 based LCD display.

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.

Now before going further then I want it to be known that this guide is much based on the Guide from Xojo Inc on HD44780 displays. I had been struggling a bit with my self if this guide should be made given that Xojo already had one but then I opted to do it for completeness and as base for other displays that we will be doing. As I went on though then I did some substantial improvements to the Xojo guide which should make this guide worth having. Those include custom glyphs, better detail  on connecting and how to not damage your display if your display is not one that protects it self as the ones from Adafruit and other minor things.

LCDImage2


Disclaimer:
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 display or damaged Raspberry PI.

Pieces we use in this example:
  • Raspberry PI 2 (or Raspberry PI 3).
  • Cobbler and Cobbler cable.
  • Bread board (I found it nice to have two for this).
  • Header pins to solder into the display.
  • HD4478 based LCD display. I had 1602 LCD module with blue backlight that I paid about $3 for on Ali Express but I am finding them now all the way down to $1.96 with free shipping.
    (Do not get one with Electro Luminescent backlight as those will draw a lot of power. They might have EL in their names)
  • 10 kΩ potentiometer.
  • 560 Ω resistor
    • Not required if you’re buying the LCD from Adafruit
    • Many displays do not have a current limiting resistor installed for the LED backlight, this resistor is only needed for those.  It is hard to tell until you actually apply power to the LCD if yours has built in resistor or not. So it is a good idea to put in a resistor to begin with at least.
    • This may vary between displays, I used 1 kΩ resistor, and the display was bright. 560 Ω is the most common though and probably would have been fine for me.
    • WiringPI needs to be installed on the Raspberry PI -> See here.

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:

LCDImage5

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.


If you are not familiar with breadboards, how to place a cobbler on the breadboard or need to know how to read the color codings on the resistors then click here bellow

   Using breadboard    Resistor color codings


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.

Connection map:
LCD Raspberry PI cobbler
#1 (GND) or (VSS) GND
#2 (VCC) 5v
#3 (Vo) To potentiometer 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 560 Ω resistor that then goes to 5.0v
(See notes above in the part list on if you
should use this resistor or not)
#16 (LED-) GND

 

Potentiometer Raspberry PI cobbler
#1 GND
#2 #3 (Vo) (In the LCD)
#3 5v

 

GPIO Header


The Xojo code:

For the Xojo code then I mostly use modified version of Paul Lefebvre’s GPIO library from Xojo Inc. I modified it to add support for custom Glyphs. (See download link at bottom for the modified library and the example code). The code I show bellow is how to use the modified library.

(Note the &amp in the binary masks shown bellow should be &, the syntax highlighter does not show it right)

// Property on a Window
Private lcd As GPIO.LCD
 
// Open event of the Window
Sub Open()
 GPIO.SetupGPIO()
 
 
 Const kRSPin = 25
 Const kEPin = 24
 Const kD4Pin = 23
 Const kD5Pin = 17
 Const kD6Pin = 21
 Const kD7Pin = 22
 
 lcd = new GPIO.LCD(kRSPin, kEPin, kD4Pin, kD5Pin, kD6Pin, kD7Pin)
 
 Dim glyph as GPIO.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 GPIO.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("Þ")
 
 lcd.RegisterCustomGlyph(glyph)
 
 // A Glyph that represents the Icelandic Thorn letter (lower case)
 glyph = new GPIO.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("þ")
 
 lcd.RegisterCustomGlyph(glyph)
 
 // A Glyph that represents the ó letter (lower case)
 glyph = new GPIO.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("ó")
 
 lcd.RegisterCustomGlyph(glyph)
 
 
 // A Glyph that represents the ö letter (lower case)
 glyph = new GPIO.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("ö")
 
 lcd.RegisterCustomGlyph(glyph)
 
 // A Glyph that represents the í letter (lower case)
 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)
 
 glyph.LetterCode = Asc("í")
 
 lcd.RegisterCustomGlyph(glyph)
 
End Sub
 
// Action event on a button
Sub Action()
 // And test our glyphs
 lcd.Clear()
 lcd.Home()
 lcd.SetMessage("Þór is the",1,true)
 lcd.SetMessage("thundergod",2,true)
 
 // The last parameter in SetMessage says we want to parse the text and look for custom glyphs in it.
End Sub
 
// Action event for a second button
Sub Action()
 Dim glyph as GPIO.LCDGlyph
 
 // We can also create custom glyph on the spot and just use it without registering it mapped to any character.
 
 // A Glyph that represents a arrow to right
 glyph = new GPIO.LCDGlyph
 glyph.SetLine(0,&b10000)
 glyph.SetLine(1,&b11000)
 glyph.SetLine(2,&b11100)
 glyph.SetLine(3,&b11110)
 glyph.SetLine(4,&b11110)
 glyph.SetLine(5,&b11100)
 glyph.SetLine(6,&b11000)
 glyph.SetLine(7,&b10000)
 
 // Register it in slot 0 (we have 8 slots, numbered 0 to 7)
 lcd.SetCustomGlyph(0,glyph)
 
 lcd.Clear()
 lcd.Home()
 
 lcd.SendByte(0,true)
End Sub

And here are example results what the code generates, notice the Icelandic letters that the display should not support normally without custom glyphs:

LCDImage4

LCDImage1

And finally the arrow glyph that we created which is not mapped to any specific character:

LCDImage3

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:

GlyphMask

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)
Downloading the code:

   Download source code


Thats it for now !!


AliExpress.com Product – Free Shipping 1PCS LCD1602 1602 module Blue screen 16×2 Character LCD Display Module HD44780 Controller blue blacklight

AliExpress.com Product – Freeshipping ! New 2004 204 24 Character LCD 0XModule Display For Arduino

AliExpress.com Product – HoldPeak HP-770D Multimeter

Leave a Reply

Einhugur technical blog that involves Xojo and Einhugur Xojo plugin related topics

%d bloggers like this: