FORGE
- Ground
- Power
- Contrast
- Register Select
- Read/Write
- Enable
- Data 0
- Data 1
- Data 2
- Data 3
- Data 4
- Data 5
- Data 6
- Data 7
- Backlight positive
- Backlight negative
You don’t need all of these pins. Power and ground
obviously need to be connected to power and ground.
Contrast takes a voltage, and the easiest way to create
an adjustable voltage (and therefore giving you a way
of controlling the contrast on the screen) is to create a
voltage divider with a potentiometer. Connect the pin
on one side of the potentiometer to power, the other
side to ground, and the middle one to the contrast
pin. This way, you can vary the look of the display by
twiddling the knob.
Read/write should be connected to ground. You’ll
need six pins on your microcontroller that take register
select, enable, and Data 4–7. Any digital pins should
do. We used an Adafruit Grand Central and pins 21,
19, 17, 16, 15, 14 respectively, but change these out
as you need.
The backlight should also be connected to power.
You might need a resistor to protect this – take a look
at your device’s data sheet or, if you’re not sure, use a
220 ohm resistor just to be safe.
SHOW US THE CODE
We’ll start by looking at how to control this display
with CircuitPython (we’ll take a look at Arduino next).
The following code sets up the LCD and displays the
classic first text, ‘Hello world’.
import board
import digitalio
import adafruit_character_lcd.character_lcd as
characterlcd
import time
lcd_rs = digitalio.DigitalInOut(board.D21)
lcd_en = digitalio.DigitalInOut(board.D19)
lcd_d7 = digitalio.DigitalInOut(board.D14)
lcd_d6 = digitalio.DigitalInOut(board.D15)
lcd_d5 = digitalio.DigitalInOut(board.D16)
lcd_d4 = digitalio.DigitalInOut(board.D17)
lcd_columns = 16
lcd_rows = 2
lcd = characterlcd.Character_LCD_Mono(lcd_rs, lcd_
en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns,
lcd_rows)
lcd.message = “Hello\nworld”
while True:
pass
As you can see, there’s not a huge amount we need
to get everything working. We just need to create
Character_LCD_Mono object using the connections
we’ve used. Once we’ve got this, we can set the
message property to the message we want to display.
As you can see, the message contains the \n newline
character, which makes our test display on two lines.
Using it like this, we can easily send whatever text
we want to the little screen, and it will be displayed for
all the world to see. However, we don’t need to stop
here. There are even more features we can explore to
make our display a little more interesting.
Above
CircuitPython is now
running on over 100
different boards
Below
Adding output to your
Arduino projects has
never been easier