siliconchip.com.au Australia’s electronics magazine May 2019 89
straight into the 14-pin header socket
on a Micromite LCD BackPack (V1 or
V2). The mounting holes don’t line
up, but we’re sure that our readers will
figure out clever ways to mount these
boards successfully.
Touch interface
One of the great features of these
displays is the touch interface.
A quick inspection shows that like
the 2.8in touchscreen we’re familiar
with, the 3.5 inch screen uses the same
XPT2046 touch controller IC and the
connections appear to be practically
identical.
We even found some schematics
which indicated that this was the case.
The XPT2046 touch controller is
effectively a multi-channel 12-bit
analog-to-digital converter (ADC),
which is intended to be connected to
a four-wire touch panel. It can drive
its analog pins as needed to supply a
voltage difference across the touch sur-
face. Fig.1 shows a typical connection
for the XPT2046 IC.
An 8-bit command is sent to the
XPT2046 over the SPI bus, which sets
up the drivers and ADC multiplexer
and starts an ADC conversion.
This conversion is clocked (timed)
by the following pulses on the SPI
SCK clock line.
Twelve bits of data are read out from
the chip, along with four zero bits (for
a total of 16 bits or two bytes), after
which the touch controller is ready
for another conversion.
So this is all pretty straightforward,
and we had code which worked with
the 2.8in touch panels, but it would
not work with the 3.5in panels.
We tried many different approach-
es to solve this, including probing the
lines going to the touch panel itself,
and ultimately we discovered that the
problem was due to the LCD control-
ler and touch controller sharing one
MISO (master in slave out) line.
The display controller should not
be driving this pin when its CS (chip
select) line is high, as this is how mul-
tiple devices share an SPI bus.
The touch controller correctly
leaves its MISO pin floating when its
CS line is high. But the LCD control-
ler appeared to be driving MISO all
the time, and this was preventing the
touch controller from pulling it high,
resulting in the micro receiving all
zeros.
The fix was easy; we disconnected
the LCD controller’s MISO line en-
tirely, as it is not needed since we
never read data back from the LCD
controller. Then, everything worked
like a charm.
The final Arduino shield design has
a jumper to disconnect this pin from
the SPI bus, so you should be able to
get the touch controller working sim-
ply by leaving it open.
Once we got the touch interface
working, we wrote a few more sam-
ple programs (both Arduino sketches
and Micromite BASIC). One of these
is a basic demo and the other provides
test and calibration features.
They are named “SPI_3.5_inch_
TFT_shield_demo_wth_touch.bas”
and “SPI_3.5_inch_TFT_touch_cali-
bration.bas”, with the Micromite Plus
equivalents having the same names but
with “MMplus” at the end.
SD card support
Like the smaller 2.8in display mod-
ules, the 3.5in displays also have an
SD card socket connected to a separate
set of pins via 1k resistors. As there
is no direct connection to these pins
on the Micromite or Micromite Plus
BackPack, the only way to access the
SD card with these boards is by add-
ing jumper lead connections.
Our Arduino breakout board has
headers to make connections to the
SD pins for both the 2.8in and 3.5in
displays.
And since the display module has
nothing to prevent 5V being fed into
the SD card pins, we have designed
the breakout board to do all the level
conversion, as this is also needed for
the display and touch controllers.
The Arduino IDE provides a basic
“SD” interface library, and we tried
the “listfiles” example from (Files ->
Examples -> SD).
Our design uses digital pin 6 as the
SD card chip select line, so we sim-
ply changed one line in the “listfiles”
sketch to use the correct CS-bar pin
like this:
if (!SD.begin(6)) {
We were then able to retrieve a list of
the files from an SD card plugged into
the socket on the display. Our break-
out board can also be used to read data
from SD cards.
Verdict
Now that we’ve figured out how to
drive it and use the touch panel, this
display is an excellent choice, espe-
cially for use with Arduino boards.
And since it can also be used with
both the Arduino and Micromite
boards, we hope to use it more in the
future. The SPI interface means that
the pin usage is minimal.
We’ll need to come up with some
CFUNCTIONs if we hope to use this
These are the test patterns you will see when you run our sample programs. The shadowing (particularly on the right
photo) is an artefact from photography – this is almost invisible with the naked eye.