This is only a preview of the August 2019 issue of Silicon Chip. You can view 47 of the 112 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Articles in this series:
Items relevant to "Micromite LCD BackPack Version 3":
Items relevant to "“HEY! THE SIGN SAYS NO JUNK MAIL!”":
Items relevant to "Car Radio Head Unit Dimmer Adaptor":
Articles in this series:
Items relevant to "Discrete Logic Random Number Generator":
Purchase a printed copy of this issue for $10.00. |
Micromite
LCD BackPack V3
by Tim Blythman
This BackPack is the most
convenient and powerful yet.
It has all the features of the V1 and V2
BackPacks and supports both 2.8in and 3.5in
touchscreen displays plus five new optional features
which provide convenient functions. These include extra memory, temperature,
humidity and pressure sensors, a real-time clock, an infrared receiver and more!
I
n our article on 3.5in touchscreen displays in the May
2019 issue (siliconchip.com.au/
Article/11629), we looked at three different screens. But we were particularly
impressed by one.
It uses an ILI9488 controller with
SPI interface and has the same connections as the popular 2.8in touchscreen
display used by the original and V2
BackPacks.
For that article, we supplied code to
drive that new display from an Arduino and a standard Micromite. We also
mentioned that we planned to write
30
Silicon Chip
some CFUNCTIONs to speed it up, as
the BASIC code is quite slow at refreshing the screen.
Not only have we now done that, but
we’ve also designed a new version of
the BackPack to properly accommodate the larger, higher resolution screen
with twice as many pixels as the original (480x320 compared to 320x240).
While this article gives sufficient
information for you to fully understand what we’ve done, if you haven’t
seen the V2 BackPack article in the
May 2017 issue (siliconchip.com.au/
Article/10652), you might want to
Australia’s electronics magazine
read that one before coming back to
this article.
Essentially, the BackPack is a small
PCB that hosts a PIC32 running the
Micromite firmware. It also provides a
simple power supply, a USB interface,
a header and mounting screws for a colour touchscreen and an I/O pin header.
The best part about it is that MMBasic has native touchscreen support. It’s
such a great idea that we’ve used the
BackPack in numerous other projects.
But the V3 BackPack is more than
just a screen upgrade.
While you can build the new V3
siliconchip.com.au
Features
• Compatible with Micromite LC
D BackPack V1 & V2
• Suits 2.8in and 3.5in touchscre
en LCD modules
• Built-in Microbridge provides
serial communications and pro
gramming interface
• Mini USB socket for power and
communication
• Native support for 3.5in displa
y using initialisation CFUNCTION
• Manual or software (PWM) dim
ming for LCD backlight
• 4-pin I2C communication hea
der
• Optional onboard infrared rec
eiver
• Optional onboard DHT22 tem
perature and humidity sensor
or DS18B20 temp sensor
• Optional onboard DS3231 rea
l-time clock
• Optional onboard flash memo
ry/RAM IC
• Optional onboard BME180/BM
E280/BMP280 temperature/pre
ssure/altitude sensor
BackPack using the same components
as the V2 BackPack, you can also add
several extra components to add handy
features without needing to connecting
extra modules, PCBs or wiring.
You can fit it with an infrared receiver/decoder for remote control, a flash
memory IC or SRAM, a DHT22 temperature and humidity sensor, a DS18B20
temperature sensor or a DS3231 realtime clock IC.
There’s also a header for connecting additional I2C devices, such as a
BMP180/BMP280/BME280 temperature/pressure/humidity sensor, which
can be mounted directly to the board
if desired.
Also, this BackPack gives you the
possibility of using the SD card socket
that’s mounted on the back of the touchscreen board.
All the functions that were in the
original and V2 BackPack are retained
in the V3 BackPack, including its
50MHz 32-bit processor loaded with
a powerful BASIC interpreter, which
can be programmed over a virtual USB
serial port.
functions. It is a PIC32MX170F256B (or
the 50MHz variant, which is what we
supply) in a 28-pin dual inline package. It requires some bypass capacitors
for normal operation: two 100nF MKT
capacitors across its supply rails and a
10µF ceramic capacitor to filter its internal core supply.
There’s also a 10kΩ resistor used as
a pull-up on IC1’s RESET line, to prevent spurious resets.
IC2 is a Microchip PIC16F1455 microcontroller which is both a USB/serial converter and a PIC32 programmer – the Microbridge article in the
May 2017 issue (siliconchip.com.au/
Article/10648) describes its functions
in more detail.
When running as a USB/serial converter, pin 5 on the PIC16F1455 receives data (ie, data from the Micromite to the PC USB interface) and pin
6 transmits data (from the PC USB interface to the Micromite).
These signals also run to the edge
pins for the console connection (CON1)
in case you build this PCB but for some
reason do not plug the Microbridge IC,
IC2, into its socket. In this case, you can
use an external USB/serial converter.
The PIC32 programming interface
from the Microbridge is on pins 7, 2
Circuit description
We’ll start by describing the core
functions, which are carried over from
the V2 BackPack.
Refer to Fig.1, the circuit diagram. IC1
is the main processor which runs the
MMBasic interpreter and handles other
siliconchip.com.au
Australia’s electronics magazine
August 2019 31
and 3 of IC2. These provide the reset
function, program data and clock signals, which connect to pins 1, 4 & 5
respectively on the Micromite (IC1).
The programming output on the
Microbridge is only active when it is
in programming mode, so the Microbridge does not interfere with the Micromite when it is using pins 4 & 5 as
general purpose I/O pins.
Switch S1 is used to select programming mode and LED1 indicates
the mode (lit solid when in programming mode).
CON2 is the main I/O connector for
the Micromite and is designed so that
it can plug into a solderless breadboard
for prototyping. The connector also
REG1 MCP1700-3302E
+5V
100n F
JP1
MINI USB
T YP E B
CON4
5V
12
13
4
8
9
1kW
10
MODE
S1
D – /R A 1
IC2
R C5 / R X
PIC16F1455
D+/RA0
MCL R / R A 3
R C4 / T X
6
DATA IN
12
1
2
3
AN3/RA4
14
l
CON5
ICSP
1 RESET
10kW
2 +3.3V
CON6
PGEC
5
9
10
10
14 MISO
14
16 IRPIN
16
21
21
5 PGEC
22
22
24
24
2 5 SC K
25
26
26
+3.3V
7
SD (3.5in)
Vcc
WP
CS
HOLD
1
IC3
FLASH
/ RA M
+3.3V
Vss
SCK
RA0/AN0
RB12/AN12
RB5/PGED3
RB2/AN4
RB7/TDI
6
3
L_D/C
L_RST
L_CS
2
3
GND
1
VCC
PINS ON IC1
+5V
MANUAL
BACKLIGHT
RB11/PGEC2
RB13/AN11
VR1
100W
RB14/AN10
1kW
RB15/AN9
19
27
+3.3V
20
Q2
S IRLML2244
G
D
10kW
D
C ON 2
Q1
2N7002
G
+3.3V
4
1 +3.3V
4. 7k W
4.7kW
3
SCL
4
SDA
+3.3V
SCL
16
SDA
15
R ST
PWM
BACKLIGHT
CONTROL
(OPTIONAL)
S
IC4
D S 3231
(IC1 PIN5)
PGEC
3
4. 7k W
1
INT/SQW
100W
TS 2
TS 1
3
l
Vcc
10m F
1
2
IRPIN
(IC1 PIN16)
DATA
DHT22
GND
1
3
2
2
3
1
32kHz
4
( T S1 & T S2 A R E
ALTERNATIVES)
M I C R O M I T E L C D BA C K P A C K V 3
Silicon Chip
GND
K
A
14
CON9
1
5–12
G ND
13
2
RTC
BATT
1
Q1: 2N7002
2
3
Q2: IRLML2244
D
G
D
G
S
S
R E G1
MCP1700
IN
Vcc
DQ DS18B20
VBAT
IR D1
LED1
2
Vcc
SCL
SD A
NC
32
LED (A)
100n F
2
SC
4
10-47mF
2
Ó2019
5
23
14 25
8
CON8
IR D1
2
RB10/PGED2
+3.3V
IC
S CK
9
RB9/TDO
4
S CK
T_CS
10
RB8/TCK
3
MISO
M O SI
11
6
RA3/CLKO
MICROMITE
I/ O
6
MI SO
8
4
2
7
T_IRQ
7
G ND
5
SI
RB3/AN5
IC 1
PIC32MX170F256B-50I/SP
RA2/CLKI
+5V
+5V
2
SO
12
RB1/AN3/PGEC1
9
4 PGED
1
CON7
MO SI
5
18
8
RA4/SOSCO
RB0/AN2/PGED1
18 SDA
3
4
SD_CS
4
100 n F
3
S CK
PGED
14
RA1/AN1
17
2
MISO
4
CON3
15
13
MCLR
17 SCL
1
MO SI
3
3 GND
2x 10k W
SD (2.8in)
1
RESET
3 MOSI
AVDD
PGEC3/RB6
RB4/SOSCI
+3.3V
7
P W M2 /R A 5
R C0 / SCL / A N 4
VDD
11
LCD
TOUCHSCREEN
28
13
DATA OUT
0V
K
SD_CS
100nF
G ND
5
RC2/SDO/AN6 AN7/RC3
A
LED1
11
VUSB3V3
R C1 / SD A
100n F
+3.3V
Rx
+V
5V
+3.3V
10mF
Tx
1
1
2
3
X
4
G ND
10mF
+3.3V
OUT
IN
POWER
AND
+3.3V
CONSOLE
CON1
makes it easy to add a third PCB to the
LCD BackPack “stack” which can carry
circuitry specific to your application
(such as amplifiers, relay drivers etc).
This connector is wired identically to
the original BackPack.
The Micromite communicates with
the LCD panel using an SPI interface
where pin 3 on the Micromite feeds
OUT
GND
Fig.1: the Micromite LCD BackPack V3 circuit
comprises the complete V2 BackPack circuit,
which is based on 32-bit microcontroller IC1,
plus numerous optional components. This
includes an infrared receiver (IRD1), a flash
memory or RAM chip (IC3), a real-time clock
chip (IC4), a temperature/humidity or temperature
sensor (TS1/TS2) and an I2C header (CON8).
Australia’s electronics magazine
siliconchip.com.au
data to the LCD while pin 25 provides
the clock signal. When the Micromite
pulls pin 6 low, it is communicating
with the LCD panel, and when pin 7
is pulled low, the Micromite is communicating with the touch controller
on the display panel.
The 28-pin Micromite has only one
SPI port and so pins 3, 14 & 25 (SPI
data and clock) are also made available on CON2 so that you can also use
this SPI serial channel to communicate
with external devices.
Backlight control
You have two choices for controlling
the brightness of the LCD’s backlight.
The first is to fit Mosfets Q1 and Q2
to the PCB, along with their associated resistors (this area is marked with
a box on the PCB).
When you do this, PWM output 2A
on the Micromite is used to control the
backlight brightness from within your
program. This is described in more
detail later.
Alternatively, as with the original
BackPack, you can fit VR1, a 100Ω
trimpot. This is in series with the power to the backlight LEDs, so it limits
the current drawn by them and therefore sets the brightness. Note that you
should install one set of components
or the other (not both). You also have
the option of fitting a link across VR1’s
pads to permanently set the backlight
to full brightness.
The LCD panel has a 3.9Ω resistor
in series with the backlight so you will
not burn out the backlight if you set
the PWM output to 100%, wind VR1
to zero ohms or link it out.
The power supply is derived from
either the 5V connector pin on CON1
or if JP1 is installed, from USB connector CON4. Powering the Micromite
LCD BackPack from USB power is
handy during program development,
but for an embedded controller application, you would typically remove
the jumper from JP1 and supply 5V
power via CON1.
Note that you should not try to power the BackPack from both CON1 and
USB as you could cause damage to
the USB interface on your computer.
The 3.3V power supply for both the
Micromite and the Microbridge is provided by REG1, which is a fixed output
regulator with a low dropout voltage
suitable for use with USB power supplies. This supply is also made available on CON2 so you can use it for
siliconchip.com.au
powering external circuits (to a maximum of 150mA).
Improvements
As mentioned above, one of the major improvements with the BackPack
V3 is that you can use either a 2.8in
320x240 pixel touchscreen or a 3.5in
480x320 pixel touchscreen. The board
is sized to fit the larger screen. It still
fits comfortably inside a UB3 jiffy
box, the same box which we’ve used
to house several Micromite BackPack
based projects over the years.
We have also designed the board so
that with both screen options, the onboard SD card socket is wired up to
IC1. While the Micromite Plus software has read/write support for SD
cards, it will not work on any throughhole PICs. The regular Micromite code,
which works on our 28-pin DIP chip,
does not natively support SD cards.
However, it would be possible
to write BASIC code (or perhaps a
CFUNCTION) to access an SD card
with the regular Micromite, so we decided to wire up the SD card socket
that already exists on the touchscreen
module.
This extra header also helps to hold
the touchscreen squarely onto the
BackPack module without needing
mounting hardware. The SD card is
connected to the same SPI interface
that’s used to drive the touchscreen,
but it has a separate CS line, which is
connected to pin 4 on the Micromite.
If you don’t insert an SD card, it won’t
have any effect on this pin so it can be
used for other purposes.
We decided that as long as we were
making these changes, we should add
some other useful features at the same
time.
Added features
The BackPack V3 has provision
for many extra onboard components
which provide various useful functions. None of these need to be fitted;
if you leave them off, the board will
work much the same as the V2 BackPack, except for the option of the larger
screen and SD card access.
These optional extra components
can be used to add extra features to
your Micromite project without needing to add another board or module.
They are:
1) 3.3V Infrared receiver (IRD1).
This mounts near the edge of the board,
so that its leads can be bent to face outAustralia’s electronics magazine
August 2019 33
wards for convenient remote control
of the unit. Its supply is filtered for
reliable operation. Its output is connected to Micromite pin 16, which is
the MMBasic IR input pin, making it
trivial to receive remote control commands in BASIC.
The IR receiver should ideally be a
3.3V type such as the Vishay TSOP2136
or TSOP2138. Having said that, we have
used 4.5V receivers such as the Jaycar
ZD1952 on a 3.3V supply and found
they normally work satisfactorily.
2) Serial flash memory or static
RAM, in either an 8-pin DIP or SOIC
package (IC3). If you aren’t using the
SD card interface, you can fit a flash or
SRAM chip with a standard pin-out to
the board and use this to store configuration data, logging data, temporary
working data etc.
These chips are easier to drive than
SD cards; the BASIC code to access
them is easy enough, and we provide
a sample sketch to do this.
The memory chip’s SPI interface is
connected to the usual SPI pins on the
Micromite, while the chip select line
(CS, pin 1) goes to pin 4 of IC1, same as
for the SD card. That is why you can’t
use both at the same time.
If fitting this chip, you have the option to fit either or both of the pull-up
resistors on pin 3 (write protect/WP)
and pin 7 (HOLD). These may be required to read and write data on the
chip. We’ve also provided for a 100nF
supply bypass capacitor; always a
good idea.
When purchasing a chip for this
board, make sure its pin-out matches
that shown and that it can run off a 3.3V
supply. This is by far the most common
pin-out for 8-pin serial memory chips
and they will virtually all operate from
3.3V, but it’s best to check.
3) A 4-pin header which connects
to the I2C bus and 3.3V power supply
(CON8). A pair of 4.7kΩ pull-up resistors are also provided on the SCL and
SDA lines, although these can be left
out if pull-ups are provided externally.
The pinout of CON8 matches the
commonly available BMP180/BMP280
temperature and atmospheric pressure
sensor modules, as well as the BME280
temperature/pressure/humidity module. So any of these can be soldered directly to the BackPack at CON8.
Alternatively, a four-way header
can be fitted and leads run to one of
the many commonly available Arduino compatible I2C modules, such as
34
Silicon Chip
character LCD screens and other sorts
of sensors.
4) A DS3231 real-time clock IC
which also uses the I2C serial bus (IC4).
It too has a 100nF bypass capacitor and
a header (CON9) to connect a back-up
battery so that the time and date are
maintained even when the board has no
external power. Micromite BASIC has
built-in commands for I2C-based realtime clocks, so this is another feature
that can be used easily.
The I2C pull-up resistors need to be
installed if a DS3231 chip is installed,
unless they are already present on another connected module.
5) A DHT22 one-wire temperature and humidity sensor (TS1) or a
DS18B20 one-wire digital temperature
sensor (TS2). These connect to pin 5 of
IC1, and there is provision for the required 4.7kΩ pull-up resistor too.
Data from the DHT22 can be read by
a CFUNCTION which is available for
download with the Micromite firmware, while there is a built-in BASIC
function to read the temperature from
a DS18B20.
If fitting a DHT22, it’s best to lay
it over on its side over the top of the
DS18B20 footprint to allow a display
to fit above.
Software support
As noted above, we have written
CFUNCTIONs to provide support for
the 3.5in display; 2.8in and smaller displays based on the ILI9341 are natively
supported by the Micromite.
The CFUNCTIONs for the 3.5in displays ‘hook into’ the existing graphics commands, so once the display
has been initialised, the drawing commands are the same. If you have already written some MMBasic software,
you only need to add a few lines at the
start to support the higher-resolution
3.5in display.
The other great thing about our
CFUNCTIONs is that they do not take
complete control of the SPI bus, allowing other SPI devices to be used.
Unfortunately, these CFUNCTIONs
interfere with the touch controller’s
BASIC functions, so we have had to
write a separate set of CFUNCTIONs
to handle the touch panel.
Most of the other optional components mentioned above are already
supported by MMBasic, so we didn’t
need to write much more code to allow you to use all the new features of
the V3 BackPack. The only thing that
Australia’s electronics magazine
is not natively supported is the flash
or SRAM memory IC, for which we’ve
written some demonstration code, as
mentioned earlier.
High-value ceramic capacitors
Previous Micromites have required
between one and three capacitors
which were either specified as SMD
‘chip’ ceramics (10µF) or through-hole
tantalum capacitors (47µF). This is because of the strict ESR requirements
for some of the parts; 10µF tantalum
capacitors often had too high an ESR
to work reliably.
Some people didn’t like having to
solder the chip capacitors, and tantalum capacitors are more expensive
and can be less reliable. Since then,
through-hole 10µF ceramic capacitors
have become available, and they use
our preferred dielectric too (X7R). So
we have specified those in the parts list.
The other two options are still valid
and can be used instead, if you prefer.
Construction
We’ll start by assembling the basic
V3 BackPack (effectively equivalent to
the V2 BackPack), and then we’ll describe what parts to add if you want to
use any of the optional features. Refer
to Fig.2, the PCB overlay diagram, to
see which parts go where.
Start by fitting the surface-mount
components. This includes the miniUSB socket, CON4, and possibly some
of the capacitors as well as Mosfets Q1
and Q2 for PWM backlight control.
The pads for the mini-USB socket have been extended to make them
easier to solder. Line the small posts
in the underside of the socket up with
the holes in the PCB; this should make
everything else correspond. If so, solder one of the large mechanical pads
in place to keep the socket in position
and flush against the PCB.
Now apply some flux to the pads for
the electrical connections. You should
be able to touch the iron to the pad extensions, allowing the solder to run up
to the pins on the socket. Ensure that
the four pins are well attached and not
bridged. If there are any bridges, carefully remove with solder wick. The
pin with the shorter pad is not used in
this application and does not need to
be soldered.
Solder the remaining mechanical
pads to complete the attachment of the
socket. Double check your work, as it
will be difficult to access the pins later
siliconchip.com.au
Parts list – MicroMite BackPack V3
(to provide the same functions as the V2 BackPack)
1 double-sided PCB, coded 07106191, 99 x 54.5mm
1 mini USB type B socket, SMD (CON4) [Altronics P1308]
1 SPST momentary tactile pushbutton (S1)
1 28-pin narrow (0.3in) DIL socket for IC1
1 14-pin DIL socket for IC2 (optional)
1 4-way header (CON1) (Micromite UART breakout; optional)
1 18-way straight header (CON2)
1 14-way female header (CON3)
1 5-way right-angle header (CON5) (for ICSP; optional)
1 4-way female header (CON6 or CON7)
1 2-way header and jumper shunt (JP1)
8 M3 x 6mm panhead machine screws (for mounting LCD)
4 M3 x 12mm tapped spacers (for mounting LCD)
1 2.8in or 3.5in LCD touch panel
[eg, SILICON CHIP ONLINE SHOP Cat SC3410]
1 UB3 Jiffy Box (optional) with laser-cut acrylic lid
[Lid only: SILICON CHIP ONLINE SHOP Cat SC5083]
Semiconductors
1 MCP1700-3302E/TO, TO-92 (REG1)
1 PIC32MX170F256B-50I/SP programmed with MMBasic
firmware, narrow DIP-28 (IC1)
[SILICON CHIP ONLINE SHOP Cat SC4262]
1 PIC16F1455-I/P programmed with the Microbridge firmware,
DIP-14 (IC2)
[SILICON CHIP ONLINE SHOP Cat SC4263]
1 3mm red LED (LED1)
Capacitors
3 10µF 16V X7R multi-layer ceramic capacitors (3216/1206
SMD or dipped leaded*) OR
2 10µF 16V tantalum AND 1 47µF 16V tantalum
3 100nF 50V MKT polyester or multi-layer ceramic
Resistors (all 1/4W, 5%)
1 10kΩ
1 1kΩ
Optional parts for PWM backlight control
1 2N7002 N-channel Mosfet, SOT-23 (Q1)
1 IRLML2244TRPBF P-channel Mosfet, SOT-23 (Q2)
1 10kΩ 1/4W, 5% resistor
1 1kΩ 1/4W, 5% resistor
Optional parts for manual backlight control
1 100Ω 1/2W mini horizontal trimpot
Optional parts for infrared reception
1 three-pin 3.3V‡ infrared receiver (IRD1) [eg TSOP2136]
1 10µF 16V X7R multi-layer ceramic or tantalum capacitor
(3216/1206 SMD or dipped leaded*)
1 100Ω 1/4W, 5% resistor
‡see text
Optional parts for external RAM or flash memory
1 SPI RAM or flash IC, DIP-8 or SOIC-8 (IC3) [eg, 23LC1024
RAM or AT25SF041 flash; pinout as in Fig.1]
1 100nF 50V MKT polyester or multi-layer ceramic capacitor
2 10kΩ 1/4W, 5% resistors
Optional parts for real-time clock
1 DS3231 RTC IC, SOIC-16 (IC4)
1 100nF 50V MKT polyester or multi-layer ceramic capacitor
2 4.7kΩ 1/4W, 5% resistors
1 2-pin header for CON9 (optional)
1 2.3-5.5V battery [eg, CR2032 lithium button cell; Jaycar
Cat SB1762]
Optional parts for temperature/humidity sensor
1 DHT22 digital temperature and humidity sensor (TS1) OR
1 DS18B20 digital temperature sensor, TO-92 (TS2)
1 4.7kΩ 1/4W, 5% resistor
Optional parts for external I2C interface
1 4-pin header (CON8)
2 4.7kΩ 1/4W, 5% resistors ^
^ These resistors
shared with RTC
above.
Optional parts for temperature/pressure/altitude sensor
1 GY-68 BMP180 temperature/pressure sensor module
(SILICON CHIP ONLINE SHOP Cat SC4343) OR
1 GY-BMP280 temperature/pressure sensor module
(SILICON CHIP ONLINE SHOP Cat SC4595) OR
1 GY-BME280 temperature/pressure/humidity sensor
module (SILICON CHIP ONLINE SHOP Cat SC4608)
1 4-pin header (CON8)
2 4.7kΩ 1/4W, 5% resistors ^
* eg, Mouser Cat 810-FA26X7R1E106KRU6 or
Digi-Key Cat 445-173437-1-ND
Resistor Colour Codes (quantites vary depending on options fitted)
Value
4-Band Code (1%)
5-Band Code (1%)
10kΩ
4.7kΩ
1kΩ
100Ω
brown black orange brown
yellow violet red brown
brown black red brown
brown black brown brown
brown black black red brown
yellow violet black brown brown
brown black black brown brown
brown black black black brown
with the other components installed.
If you are using SMD capacitors, they
will all be the same type, but the two
transistors are not. Check that these are
not mixed up before soldering them
in place.
For the other SMD components,
which are all quite small, an easy way
to fit these is to apply solder to one of
the pads then hold the component on
siliconchip.com.au
top with tweezers. Apply the iron again
to allow the solder to melt onto the
component lead. This avoids having to
handle three things at the same time.
If necessary, adjust the location of
the parts so that the pins are fully lined
up with the pads, and when you are
happy, apply some solder to the remaining pins. Finally, go back and retouch the first pin to relieve any stress
Australia’s electronics magazine
in the solder.
Through-hole parts
The remaining components can be
added in the usual order. Fit the 10kΩ
resistor between IC1 and IC2 and the
1kΩ resistor near LED1. Check these
values with a multimeter if you are not
sure, although the circuit would probably still work if they were swapped!
August 2019 35
Fig.2: the slightly
larger V3
BackPack PCB
can accommodate
a 2.8in (320x240
pixel) or 3.5in
(480x320 pixel)
LCD touchscreen,
using the inner or
outer set of four
mounting holes
respectively. Both
screens share the
CON3 I/O and
power connector
while CON6
makes electrical
connections
to the SD card
socket on the
smaller display,
and CON7
on the larger
display. CON2,
the I/O header,
is identical to
that of the two
earlier BackPack
designs.
If you are using PWM backlight control, the two resistors below Q1 & Q2
must be fitted. Their values are marked
on the silkscreen, and they should be
checked with a multimeter too.
Alternatively, you can fit potentiometer VR1 for manual backlight control, or a wire link as shown in our
photo (below right) if you prefer to
have the backlight fully on all the time.
If your potentiometer is more than
9mm tall, it may foul the display PCB
and can be laid over in the space set
aside if necessary.
Solder the capacitors next. If you
are using tantalum capacitors, then
the larger 47µF capacitor goes next to
IC1, while the two 10µF capacitors sit
either side of REG1. Tantalum capacitors are polarised, so take care that the
positive leads (generally marked on the
body) go to the pads with a “+” sign.
If you are using ceramic capacitors
instead, their polarity does not matter and you can use a 10µF ceramic
in place of the 47µF tantalum, ie, all
three high-value capacitors will be the
same type.
There are also three MKT or multilayer ceramic through-hole capacitors
to fit. Solder them in place and trim
their leads.
36
Silicon Chip
Fit the two IC sockets next, if you
are using them. These are a good idea
in case you need to replace one of the
chips. The notches on both face to the
left, towards the USB socket. Note that
if you do use sockets, IC2 will touch
the underside of the SD card socket on
the 3.5in display. This shouldn’t cause
any problems, but it can be avoided
by separating the boards with 12mm
tapped spacers.
The tactile switch sits near the
left-hand edge of the board. Ensure it is pushed down firmly
against the PCB before soldering
its pins. It may take some force,
but should pop into place
. JP1 can also be fitted, below
the USB socket. Unless you are
powering the BackPack from an
external 5V power supply, the
jumper shunt will need to be fitted to source power from the USB
socket.
The other headers should be fitted now. You will probably only
need to install one of CON6 or
CON7, depending on whether you
are using a 2.8in or 3.5in display,
although you can fit both if you
wish to experiment.
It’s a good idea to temporarily
fit the headers onto the display
you are using during soldering as
this will keep the headers aligned
squarely and correctly. CON3 can
be fitted at the same time, to simplify lining up the display with
the BackPack.
All that is left is to install the
semiconductors. LED1 is mounted with its cathode (flat side) towards
the USB socket. Ensure REG1’s outline
matches the footprint on the PCB and
solder it down close to the PCB.
Fitting the optional components
The parts list mentions what components you need to populate each
optional add-on section.
These are all through-hole parts, except for the flash IC (IC3), which can
be a through-hole or surface-mounting
This is the basic
version of the V3 BackPack.
With these parts fitted, this
provides equivalent functions to the V2
BackPack, except for the ability to use the larger 3.5in
touchscreen. The two four-way headers at left allow
either a 2.8in or 3.5in touchscreens to be fitted to this board.
Australia’s electronics magazine
siliconchip.com.au
Using the optional components
Using the infrared receiver (IRD1)
MMBasic only supports an infrared receiver on pin 16 of the 28-pin
PIC32, so that is where we have connected it. You therefore lose this
pin as a general purpose I/O when you fit IRD1.
MMBasic can trigger a software interrupt when a valid command
is received and then call a user-defined subroutine. This is set up as
follows:
IR DevCode, KeyCode, IR_Int
DevCode and KeyCode specify the variable names which will contain the device and key codes respectively when the user routine (“IR_
Int” in this case) is called. So you could define the function like this:
SUB IR_Int
PRINT “DEVICE:” DevCode ”KEY:” KeyCode
END SUB
Using the real-time clock
MMBasic has built-in routines to use an RTC module connected to
the hardware I2C pins, as is the case here. Set the Micromite’s internal
clock from the DS3231 IC thus:
RTC GETTIME
Setting the time on the DS3231 is done with a single command
specifying the current date and time:
RTC SETTIME year, month, day, hour,
minute, second
If you are using any other I2C devices, you can connect them via
CON8. If, as is often the case, the module(s) have their own pull-up
resistors, either remove them or omit the onboard I2C pull-up resistors. It may work with both in place, but this is not recommended
Temperature and humidity sensors
The temperature from a DS18B20 (TS2) can be read with a single
MMBasic command:
TEMPERATURE = TEMPR(5)
Functions for communicating with a DHT22 were built into early
versions of MMBasic, but have been removed in later versions; instead, a CSUB is supplied to do the same job. The required code and
documentation can be found in the “Humid.pdf” file in the “Embedded
C Modules” subfolder of the Micromite firmware download, available
from http://geoffg.net/micromite.html#Downloads
After the CSUB has been copied into the BASIC program, the temperature and humidity can be read by a single command like this:
HUMID 5, TEMPERATURE, HUMIDITY
The first parameter (5) tells this function which Micromite pin the
DHT22 sensor is connected to. The results are saved in the TEMPERATURE and HUMIDITY variables. Due to the way the DHT22 works, the
results are actually from the previous time this command was issued,
with the current call starting the next conversion in the background.
Therefore, you will need to ignore the values of TEMPERATURE and
HUMIDITY the first time you call this command. Hence, it’s a good idea
to issue it during your initialisation routine.
Using a RAM chip
We test-fitted our board with a 23LC1024 RAM IC (IC3). It’s similar
to the 23LCV1024 used in the 433MHz Wireless Range Extender project in the May 2019 issue (see siliconchip.com.au/Article/11615).
siliconchip.com.au
There is no WP (write-protect) function on the RAM IC, but it does
have a HOLD pin which needs to be held high, so the 10kΩ pull-up resistors are still required.
We’ve written a sample program to demonstrate using such a chip,
which is named “23LC1024 RAM IC.bas”. It simply writes data to the
chip, based on the contents of the TIMER variable, then reads those
values back and prints them out on the Micromite terminal.
The CS pin of IC3 is hardwired to the Micromite’s pin 4, and this is
set as a constant at the start of the sample program. The SETRAMMODE subroutine provides page, byte and sequential options. Using
the sequential option means that the entire RAM contents can be read
or written in one pass.
A read or write starts with a STARTRAMREAD/STARTRAMWRITE
command, which pulls CS low and sends a command sequence containing the supplied start address.
After that, subsequent calls to RAMREAD or RAMWRITE read or write
a single byte before incrementing the address pointer. The sequence
ends with a call to ENDRAMREAD/ENDRAMWRITE which brings CS
high, releasing the SPI bus.
Using external flash memory
For testing out the flash interface, we tried an AT25SF041 4Mbit
(0.5MB) flash IC (again, as IC3). On this chip, the WP and HOLD pins
are internally pulled high, so the 10kΩ resistors are not needed, although they were fitted to our prototype; it doesn’t hurt to have both
internal and external pull-ups.
Writing to the device is a bit more complicated than for a RAM chip,
but reading uses the same command and format as the RAM IC.
Flash memory cannot usually be written byte by byte. An entire ‘page’,
4KB in this case, must be erased (set to all 1s), then data can be written
byte by byte (or ‘programmed’ according to the data sheet terminology). Writes occur in blocks of up to 256 bytes. The data to be written
is actually stored into a RAM buffer; it isn’t written to flash until the CS
line goes high, at the end of the process.
There are a few more details than what’s described here; so the device data sheet is a good place to check out the subtleties of the process. One wrinkle, for example, is that the writes will wrap around at
addresses that are multiples of 256 bytes. There is also a software flag
(WEL; write-enable latch) that must be set before any changes (erase
or write) can occur to the flash memory contents.
Thus a typical write sequence would consist of setting the WEL flag,
erasing a page, setting the WEL flag again and then writing the actual data.
The sample program is called “AT25SF041 FLASH IC.bas”. Unlike
the RAM demo, which loops continuously, this program reads the flash
once, writes data to the flash once, then rereads it, displaying the results
on the terminal. This is to avoid wearing out the flash.
The flash chip we used has a minimum endurance of 100,000 cycles, which means that it would take 27 hours at one write per second
(to the same part of the flash memory) to potentially cause a failure.
Using a BMP180, BMP280 or BME280 sensor module
We published an article in the December 2017 issue explaining how
to use a BMP180 or BMP280 module with a Micromite; see siliconchip.
com.au/Article/10910 You can download the sample BASIC code for
free from siliconchip.com.au/Shop/6/4521
While the BMP180 and BMP280 provide temperature and pressure/
altitude information, the BME280 also includes humidity data. You can
find MMBasic source code to read data from a BME280 sensor at TheBackShed forum. See: www.thebackshed.com/forum/forum_posts.
asp?TID=8362
Australia’s electronics magazine
August 2019 37
Driving the 3.5-inch touchscreen
When using the 2.8in touchscreen, you set it up once using the
OPTION command (as described in the main text) and from then
on, the Micromite automatically configures it each time the chip
is powered up. But because MMBasic doesn’t natively support the
3.5in touchscreen, setting it up is a bit different.
You need to run some code at the start of your program, every
time the chip is powered up, to configure this display. This code
initialises the display and also sets up the ‘hooks’ into Micromite
BASIC’s graphics commands so that you can draw to this screen
using the same commands as for the 2.8in display.
One big difference of this implementation is that it does not block
use of the SPI pins to other interfaces. In fact, the user program
must start the SPI peripheral just as for any other interface. This is
also the reason why the in-built touch commands won’t work, as
they too require exclusive use of the SPI interface.
Although the various control pins for the LCD and touch controllers
(such as CS, DC and RESET) are hardwired into the CFUNCTION to
match the hardware that is on the BackPack, they need to be set up
by the user program. The advantage here is that control can be taken
back if your program wants to use these pins for other purposes.
The CFUNCTION assumes that all this setting-up has been done,
and will fail if it has not. This is so that the CFUNCTION has minimal overhead and is thus quite fast. This is handy, as the 3.5in displays have twice as many pixels to manage as the 2.8in displays.
The following code needs to appear before the display functions
can be used with the 3.5in display. You can also find this code in
our example programs:
DIM INTEGER ROTATION=1,BUCKET,
ILI9488_SPI_ADD
ILI9488_SPI_ADD=PEEK(CFUNADDR ILI9488_SPI)
SPI OPEN 20000000,0,8
SETPIN 2,DOUT
SETPIN 23,DOUT
SETPIN 6,DOUT
BUCKET = ILI9488_SPI(ILI9488_SPI_ADD,
ROTATION)
The first line defines three integer variables. ROTATION sets the
display orientation. Set it to a value between one and four. Mode
one is portrait, two is landscape, three is upside-down portrait and
four is upside-down landscape.
BUCKET (the ‘bit-bucket’) is used as a place to store the return
value of the CFUNCTION. BASIC insists on us storing the return
value of a function when calling it, so even though we don’t need
to use that return value, we need somewhere to store it.
ILI9488_SPI_ADD is used to hold the flash memory address
(shortened to “ADD”) of the CFUNCTION. This needs to be passed
to the CFUNCTION during the initialisation stage, as it needs this
to set up the hooks into the native graphics functions.
The address of the CFUNCTION is retrieved by using the PEEK
function on the second line. We have called the CFUNCTION
“ILI9488_SPI”, so if you change this, you will need to change that
second line too.
The next four lines set up the micro’s SPI peripheral and set up
the I/O pins used to control the screen’s CS, DC and RESET lines.
Finally, the display is initialised by our CFUNCTION according to
the ROTATION setting. After this, you will normally clear the screen
using a command like this:
CLS(RGB(BLACK))
38
Silicon Chip
Our demonstration program, “ILI9488_SPI_minimal working.
bas”, can be downloaded from the SILICON CHIP website. This sets
up the display as described above and then draws some patterns
on the screen using the inbuilt graphics functions.
Using the touch interface
As mentioned in the text, MMBasic’s built-in touch panel support
doesn’t play well with our new driver. We suspect that this is because the display driver is not initialised when the touch controller
attempts to start up at Micromite boot time. So we have written a
separate CFUNCTION to provide the touch functions.
The “ILI9488 with touch calibration.bas” demonstration program
(also in the download package on our website) shows how to read
raw touch data and also calculate touch locations on the screen. As
well as initialising the display controller as noted above, the following lines are required to use the touch controller:
DIM INTEGER TOUCH_X0,TOUCH_Y0,
TOUCH_X1,TOUCH_Y1
TOUCH_X0=110
TOUCH_Y0=1993
TOUCH_X1=2001
TOUCH_Y1=76
SETPIN 7,DOUT
These four variables provide touch panel calibration. Our calibration sketch generates a new set of calibration values for a specific
touch panel, which can be pasted back into your program.
The ROTATION variable also needs to be set, as described earlier, since the calibrated touch coordinates depend on the display
rotation that is being used.
The last line sets up the Micromite pin used to drive the touch
controller’s CS (chip select) line.
To retrieve the x-axis component of the current touch position,
use the following CFUNCTION call:
X=XPT2046(0,ROTATION,TOUCH_X0,TOUCH_Y0,
TOUCH_X1,TOUCH_Y1,MM.HRES,MM.VRES)
This CFUNCTION requires no initialisation, although it assumes
that the SPI interface has already been set up, as this is required
to use the display anyway. This CFUNCTION reduces the speed of
the SPI bus below the 2.5MHz limit of the touch controller IC for
the duration of the CFUNCTION, and returns it to its previous value
afterwards.
To read the y-axis, the value of one is passed as the first parameter instead:
Y=XPT2046(1,ROTATION,TOUCH_X0,TOUCH_Y0,
TOUCH_X1,TOUCH_Y1,MM.HRES,MM.VRES)
To retrieve the raw ADC values (which are necessary for the calibration), values of two, three or four are passed as the CFUNCTION’s
first parameter. The z-axis value (with the first parameter as four)
corresponds to the pressure on the touch panel, and is used by our
function to check whether a valid touch is occurring. For example:
RAWX=XPT2046(2)
RAWY=XPT2046(3)
RAWZ=XPT2046(4)
By using the z-axis value, the IRQ pin on the touch controller is
not needed for the 3.5in displays, although it is left connected on
our board, for use with the 2.8in displays.
Australia’s electronics magazine
siliconchip.com.au
As shown here,
the V3 BackPack can
also be populated with other
sensors and ICs to extend what it can do
without requiring external circuitry. These extra
components include temperature and humidity
sensors, an infrared receiver or a flash IC for non-volatile data storage.
type, and the DS32321 IC (IC4), which
is only available in a surface-mounting package.
If fitting IRD1, you also need to
mount the adjacent 100Ω resistor and
10µF capacitor used to filter and bypass its supply.
It’s a good idea to mount IRD1 with
long enough leads that you can bend
its lens to face in the same direction as
the screen. It can be soldered on either
side of the PCB, as long as its lead connections are not reversed compared to
what is shown in Fig.2.
To fit IC4, the DS3231 IC, apply a
small amount of flux to the pads and
solder one pin in place. Check that
its pin 1 dot is orientated as shown
in Fig.2. Once you are happy that the
part is flat and lined up with the other
pins, carefully solder the rest. Ensure
that no solder bridges have formed; if
necessary, clean them up using flux
paste and solder braid (wick).
You will also need to fit the adjacent
100nF capacitor and both I2C pull-up
resistors (4.7kΩ). It’s also a good idea to
connect a battery (2.3-5.5V) via CON9.
A CR2032 lithium battery is commonly used with the DS3231 and will last
many years.
You can either solder its leads to the
pads for CON9 or fit a pin header and
connect the battery using patch leads
or similar. If you don’t connect a battery, IC4 will lose its time each time
power to the board is cut.
But there isn’t much room for a battery on the PCB, and no mounting location is provided, so you will have
to figure out how to mount it (eg, with
double sided tape) and wire it back to
CON9. If mounting it somewhere on
this PCB, make sure it’s properly insulated so it can’t short to any of the
tracks or components.
Either the DHT22 (TS1) or DS18B20
(TS2) temperature sensor can be fitted,
but not both. They connect to the same
pin on the Micromite (pin 5) but use
different communication protocols.
They share a single 4.7kΩ pull-up resistor, which is inside the box labelled
TS1, but needs to be fitted if either TS1
or TS2 is being installed.
TS1 is quite tall so it can be fitted
laid over towards IC4; the vented side
of the case should face away from the
Breaking news from
While we were preparing this article, Geoff Graham told us that
Peter Mather had made a post on his forum, “The Back Shed”,
describing a driver that he had created for the ILI9488 display
controller.
The Back Shed is a great place to get information on the various
Micromites and other topics. See: www.thebackshed.com/forum/
His code for the display controller can be found at:
www.thebackshed.com/forum/forum_posts.asp?TID=11419
It is implemented as a CSUB which is run by the Micromite at
startup. The initialisation process is different to our CFUNCTION,
but after that, you use the same native graphics commands as
with our code.
The code shown on the forum is for a different Micromite
board, so the initialisation line needs to be changed to suit the
pinouts used on the BackPack. Copy and paste his code labelled
“MM2” into a blank program, then change the second line from:
ILI9488 16,2,9,1
to:
ILI9488 2,23,6,1
These parameters determine the display CD pin, RST pin, CS
pin and orientation. This changes the pin values to suit the BackPack. The orientation is a value from 1 to 4, as explained in the
main text of this article. Upload the program to the Micromite
and run the command:
siliconchip.com.au
LIBRARY SAVE
to store the CSUB as a library instead of BASIC code, then restart the processor with the command:
WATCHDOG 1
The driver will then be loaded. At this stage, the Micromite is at
the same state as if the OPTION LCDPANEL command had been
run for the 2.8in screen, and normal touch panel initialisation can
continue, like this:
GUI TEST LCDPANEL
OPTION TOUCH 7,15
GUI CALIBRATE
GUI TEST TOUCH
Readers who are comfortable with the usual way of setting up
touch panels on the Micromite, such as the ILI9341, may prefer
this method as it works similarly. However, note that you will lose
the ability to use the SPI peripheral for other purposes, as is the
case with the 2.8in display.
Peter also noted the glitch with the MISO pin on these displays
which we found (and worked around) while while trying them
out in our May article and then on the V3 BackPack board; see:
siliconchip.com.au/Article/11629
Finally, future releases of the Micromite V2 firmware will include
a copy of Peter Mather’s ILI9488 CSUB driver.
Australia’s electronics magazine
August 2019 39
baud on a freshly programmed Micromite, if you want to check this out
now, using your favourite serial terminal program.
Drivers
Here’s how the
3.5in display fits over
the BackPack V3 PCB. It
can also accommodate the 2.8in
display if you wish but it’s designed
to suit the larger display.
PCB. If IC4 has already been fitted,
there should still be room to lay TS1 on
its side, but you will need to initially
mount it slightly above the board so
that it will sit flat on top of IC4 when
bent over.
If fitting an SMD flash or RAM chip
for IC3, orientate it with pin 1 towards the bottom edge of the board,
as shown in Fig.2. You can solder it
using a similar technique as described
for IC4 above.
The through-hole version will be a
bit easier to solder, and is orientated
with its pin 1 dot or notch towards the
left as shown.
In either case, you will also need to
fit the adjacent 100nF bypass capacitor and the two 10kΩ pull-up resistors.
Note that some flash ICs have internal
pull-ups; in this case, you can omit
those resistors. Check your device’s
data sheet to find out.
To connect an external I2C module,
including a BMP180 (GY-68 module),
BMP280 (GY-BMP280 module) or
BME280 (GY-BME280 module), fit pin
header CON8 and the two 4.7kΩ resistors above it. As mentioned earlier,
you can solder the module directly to
CON8; match up its pinout, as printed on the module, with that shown in
Fig.2 or on the PCB.
Note that some modules already incorporate pull-up resistors for the SDA
and SCL lines. In this case, either don’t
fit the resistors on the BackPack, or
remove them from the module. There
should be exactly one set of pull-up
resistors in the circuit.
Programming the chips
Both chips are available pre-programmed from the SILICON CHIP ON40
Silicon Chip
SHOP, but you only really need
IC2 to be pre-programmed since it is
capable of loading the software onto
IC1, using pic32prog (see below). But
having IC1 pre-programmed will save
you some effort, and both chips come
programmed if you purchase them as
part of our kit (Cat SC5082).
While it is possible to program IC2
using a BASIC program on IC1 and a
9V battery, we only recommend this if
you have no other way, and this has a
bit of a ‘chicken and egg’ problem, in
that it only works if IC1 has already
been programmed.
See http://geoffg.net/microbridge.
html for more information on this
technique.
You can program IC1 after fitting it,
either using the ICSP header (CON5)
and a PICkit or similar programmer, or
by using IC2 in its Microbridge role.
More information on using the Microbridge and its pic32prog software can
be found in the article from May 2017
(siliconchip.com.au/Article/10648).
We’ll proceed assuming that you
have pre-programmed chips, so fit
them now. If you have used sockets,
gently bend the leads of the ICs inwards to fit the sockets, otherwise,
solder the chips directly to the PCB,
taking great care that they are orientated correctly. Both ICs should have
pin 1 facing towards the USB socket.
It’s a good idea to solder two diagonally opposite corners and ensure the
IC is flat and level before soldering the
remainder.
The V3 BackPack is now usable and
can be tested. Plug the BackPack into
a computer and it should show up as
a new USB-serial device.
Communication occurs at 38,400
LINE
Australia’s electronics magazine
Under Windows 10 and Linux, a
driver should be automatically installed. If it is not, then the driver can
be found at www.microchip.com/
wwwproducts/en/MCP2200 While
this is a different device, it uses the
same USB identification (VID and PID)
codes as the Microbridge firmware.
(Incidentally, the MCP2200 is nothing more than a PIC18F14K50 that has
been programmed to act as a USB-serial bridge, which is why this driver
works).
When properly installed, the Micromite BackPack should appear as a new
virtual COM port on your computer.
Configuring the display
The backlight controls work unchanged compared to the V2 BackPack
(assuming you have fitted Q1, Q2 and
their associated resistors).
The backlight intensity is set on a
scale of 0 to 100 with the PWM function thus:
PWM 2,250,BACKLIGHT
This command works because pin
26 is the first output of PWM channel 2.
Alternatively, the backlight can be
turned on or off by using the SETPIN
and PIN commands to set the output
of pin 26 high or low.
If you are using a 2.8in display, then
the same instructions as given in the
article from May 2017 (on the V2 BackPack) apply. The following commands
initialise and calibrate the display:
OPTION LCDPANEL
ILI9341,L,2,23,6
GUI TEST LCDPANEL
OPTION TOUCH 7,15
GUI CALIBRATE
GUI TEST TOUCH
The 3.5in panel works slightly differently, as it depends on a CFUNCTION to work and is not quite as ‘transparent’ as the inbuilt display driver.
See the panel titled “Driving the 3.5inch touchscreen” for details on how
to set up and use the larger screen.
If you have fitted any of the optional components, see the separate panel “Using the optional components”
which describes the software required
to use them.
SC
siliconchip.com.au
|