HackSpace_-_April_2020

(Frankie) #1
FORGE


  1. Ground

  2. Power

  3. Contrast

  4. Register Select

  5. Read/Write

  6. Enable

  7. Data 0

  8. Data 1

  9. Data 2

  10. Data 3

  11. Data 4

  12. Data 5

  13. Data 6

  14. Data 7

  15. Backlight positive

  16. 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
Free download pdf