Silicon Chip – May 2019

(Elliott) #1

88 Silicon chip Australia’s electronics magazine siliconchip.com.au


it has exactly twice as many pixels.
As you would expect, given the
extra 0.7 inches (20mm) of diagonal
screen size, it is slightly larger, and
the PCB is slightly longer, so the two
pin headers on the board are around
13mm further along than in the smaller
LCD. The mechanical mounting holes
are also arranged differently.
Otherwise, the main 14-pin inter-
face header appears identical, and
the pins are marked with the same
designations. Like the 2.8in display,
you can get these with or without the
touch panel. The difference in price is
small, so we think it’s worthwhile to
get the one that has it.
The main appeal of this unit is that
it can plug into the existing Micro-
mite BackPack and even if you’re us-
ing it with an Arduino Uno, it won’t
take up all that many digital I/O pins,
so you will still have plenty left for
other tasks.
It’s controlled using two SPI inter-
faces, one for the display and one for
the touch panel, although you can
drive both from a single set of SPI pins
on the micro. Like the 2.8in LCD used
with the Micromite BackPack, the full-
size SD card socket is accessible from
one of the long edges of the PCB.
To simplify our experiments on
these displays with Arduino boards,
we designed the aforementioned
breakout PCB that suits both the
2.8in 320x240 display and the 3.5in
480x320 display.
The instructions for assembling this
breakout board can be found below.
If you have one of these displays and
an Arduino board, you might want to
build this board before reading the fol-
lowing usage instructions.


Getting it working


with an Arduino


Because of the prevalence of Ardui-
no libraries, we started our testing us-
ing our breakout board with an Arduino
Uno. After a few attempts, we found a li-
brary that was able to drive the display.
This library can be found at https://
github.com/jaretburkett/ILI9488 (see
Fig.4)
We had to change the pin assign-
ments in the example sketch, named
“graphicstest” to the following:


#define TFT_CS 10
#define TFT_DC 9
#define TFT_LED -1
#define TFT_RST 8

There is no pin ‘-1’, but this value
can’t be empty, so a value of -1 is used
because this is ignored by digitalWrite
commands since it is an invalid pin
number, and therefore has no effect.
On our board, the LED pin is hard-
wired to the 5V rail, forcing the LCD
backlight on, to save as many pins as
possible for other uses.
Interestingly, this library was modi-
fied from another library designed for
the ILI9341 controller, which is what
is in the 2.8” inch displays.
It simply provides a low-level in-
terface to the “Adafruit_GFX” library.
This library provides common, high-
level functions like drawing shapes
and text to displays.
Adafruit has developed a good num-
ber of display boards and modules
(many of which are now appearing as
clones), and they have excellent sup-
port for their displays.
Their libraries are a great resource
for getting many displays running.
While it’s nice to have some library
code that works, we wanted to know
how to control these displays at a
much lower level and get an under-
standing of their operation.
To see what sets the larger ILI9488-
based displays apart from the smaller
ILI9341s, we added some code to the
libraries to print out (to the serial mon-
itor) what commands and text were be-
ing sent to the board, formatting this
output as commands which could be
pasted directly into the Arduino IDE.
This is shown in Screen1.
This showed us the required initial-
isation sequence for the display con-
troller. We then checked the ILI9488
datasheet (http://siliconchip.com.au/
link/aanr) and confirmed that the com-
mands that were being issued were
appropriate.
There are a few commands that re-
quire a delay after they are sent, to al-
low the controller to process the data,
so we needed to know when these
should occur.
We could then build a working
sketch from scratch to drive the dis-
play.
Since the ILI9488’s drawing (as op-
posed to initialisation) commands are
practically identical to those for the
ILI9341, once it’s initialised, the pro-
cess of drawing on the screen is quite
straightforward.
Although the datasheet hints that a
16-bit colour mode (as used with the
ILI9341) is available, it doesn’t appear

to work in SPI mode on the ILI9488,
so we had to modify the code to pro-
duce 24-bit colour values.
We’ve distilled all this code down to
just the essentials and put it in a demo
sketch titled “SPI_320x480_display_
demo”. This demonstrates drawing
on the screen in all four orientations,
including region fills, text and lines
made of individual pixels.

Micromite support
We were then able to translate this
Arduino sketch into working Micro-
mite BASIC (MMBasic) code. We had
to do a search and replace to change
Arduino’s “0x” hexadecimal prefix
with “&H” to suit BASIC, as well as
changing the function definitions to
subroutines, amongst other changes.
The demo BASIC file is called
“SPI_320x480_display_demo.bas”.
For the Micromite, the font data is
embedded as a CFUNCTION. While
this directive is usually used to store
machine code, it can be used to store
any binary data for MMBasic, and is a
more compact way of doing this than
DATA statements.
Some of the display routines have
been modified to work with larger
arrays of data, as the SPI interface
works more quickly with arrays than
individual values.
Before this improvement, clearing
the screen took nearly a minute.
This display code would be an ideal
candidate for a CFUNCTION, as that
would allow it to work a lot quicker,
but the intention here is to demon-
strate what is possible, and also to
show how the interface works.
We expect readers will have an easi-
er time understanding the BASIC code
than the equivalent C code, even if the
C code would be substantially faster.
If you are using the Micromite Plus
BackPack, use the source files with the
“MMplus” suffix at the end. The SPI2
peripheral is used for display commu-
nications on the Micromite Plus, so
you may need to run an “OPTION ...
DISABLE” command if there are any
other peripherals using SPI2 before
the display code will work.
Similarly, on the regular Micromite,
any OPTIONs that lock the SPI bus
may need to be disabled before using
our sample programs.
Note that we have not designed a
breakout board to interface this screen
to a Micromite.
That’s because it can be plugged
Free download pdf