HackSpace – September 2019

(Jacob Rumans) #1

TUTORIAL


Graphical output for (almost) any board


ometimes you need a little bit of
graphics or text output for your
projects and, for this, TFTs are a great
solution – they’re cheap, available in a
range of sizes, and well supported by
maker hardware. TFT stands for
thin-film transistor – essentially, TFTs are liquid crystal
display (LCD) screens with fast refresh rates. The
main thing you need to know when looking to get one
is the driver chip it uses. There are a few that are easy
to use; in this tutorial, we’ll look at ones driven by the
ILI9341 chip. The driver should come on the TFT
board, so we don’t need to worry about wiring the
two together. Instead, we just need to connect the
module to our microcontroller.
This connection uses SPI (plus a couple of other
wires), so the first thing we need to do is to connect
the four SPI pins to an SPI bus – it’s quite high speed,
so it’s best to make sure it’s on a hardware SPI. Most
microcontrollers have one of these, so look up where
yours are. The following connections go from the
relevant pins on the microcontroller to the labelled pin
on the TFT screen. We did this on an Adafruit Grand
Central, so the numbered pins are the ones we used.

S



  • MISO (Grand Central pin 50)

  • MOSI (Grand Central pin 51)

  • CLK (OR SCK) (Grand Central pin 52)

  • CS (or SS) (Grand Central pin 53)


The following aren’t SPI pins, but also need to be
connected. As they’re not part of SPI, it doesn’t
matter which pins you connect them to, provided
they’re digital IO. The pin numbers we’ve used
could easily be changed.


  • DC (Grand Central pin 49)

  • RST (Grand Central pin 48)


That’s all there is in terms of physical setup.
Let’s now take a look at what code we need. The
Grand Central can use either Arduino or CircuitPython,
so let’s take a look at how to use it in both these
languages. First, we’ll look at Arduino.
You’ll need to install the Adafruit GFX library –
that’s a high-level graphics library that can work
with a range of displays. You’ll also need the
low-level Adafruit-ILI9341 library that handles this
specific driver chip.

Graphical output


for (almost) any board


Add an ILI9341-powered screen in Arduino and CircuitPython


Above
Your TFT board
should have the pins
labelled to make it
easy to connect up to
your microcontroller

Ben Everard
@ben_everard

Ben loves cutting stuff,
any stuff. There’s no
longer a shelf to store
these tools on (it’s now
two shelves), and the
door’s in danger.
Free download pdf