This is only a preview of the August 2020 issue of Practical Electronics. You can view 0 of the 72 pages in the full issue. Articles in this series:
|
Micromite LCD
BackPack V3
This BackPack is the
most convenient and
powerful yet.
It has all the features of
the V1 and V2 BackPacks,
supports both 2.8-inch
and 3.5-inch touchscreen
displays and boasts five new
by Tim Blythman
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 recent article on 3.5-inch
touchscreen displays (see the June
2020 issue), 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.8-inch 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
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 (480×320 compared to 320×240).
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 2018
issue of PE, you might want to read that
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.
16
But the V3 BackPack is more than
just a screen upgrade. While you can
build the new V3 BackPack using the
same components as the V2 BackPack,
you can also add several extra components to add handy features without needing to connect 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 lets you use 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.
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 functions. It is a PIC32MX170F256B (or the 50MHz variant,) 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
2018 issue of PE 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
and 3 of IC2. These provide the reset
function, program data and clock signals, which connect to pins 1, 4 and
5 respectively on the Micromite (IC1).
The programming output on the Microbridge is only active when it is in
programming mode, so the Microbridge
Practical Electronics | August | 2020
Features
• Compatible with Micromite LCD BackPack V1 and V2
• Suits 2.8-inch and 3.5-inch touchscreen LCD modules
• Built-in Microbridge provides serial communications
and programming interface
• Mini USB socket for power and communication
• Native support for 3.5-inch display using initialisation
CFUNCTION
• Manual or software (PWM) dimming for LCD backlight
• 4-pin I2C communication header
• Optional onboard infrared receiver
• Optional onboard DHT22 temperature and humidity
sensor or DS18B20 temp sensor
• Optional onboard DS3231 real-time clock
• Optional onboard Flash memory/RAM IC
• Optional onboard BME180/BME280/BMP280
temperature/pressure/altitude sensor
does not interfere with the Micromite
when it is using pins 4 and 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
makes it easy to add a third PCB to the
LCD BackPack ‘stack’ which can carry
circuitry specific to your application
(eg, amplifiers or relay drivers). 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
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 and 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
Practical Electronics | August | 2020
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: do not power the BackPack
from both CON1 and USB – 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
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.8-inch
320×240 pixel touchscreen or a 3.5inch 480×320 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 BackPackbased 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 if we were making these
changes then 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
five optional extra components can
be used to add extra features to your
Micromite project without needing to
add another board or module.
1. 3.3V Infrared receiver (IRD1)
This mounts near the edge of the board,
so that its leads can be bent to face outwards 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. However, we tried 4.5V
receivers (eg, Jaycar ZD1952) on a 3.3V
supply and they normally worked fine.
17
2. Serial Flash memory or static RAM
Use either an 8-pin DIP or SOIC package for 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 or temporary
working data. 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,
REG1 MCP1700-3302E
+5V
JP1
MINI USB
TYPE B
CON4
5V
12
13
4
8
9
1kW
10
MODE
S1
D–/RA1
IC2
RC5/RX
PIC16F1455
D+/RA0
MCLR/RA3
RC4/TX
RC0/SCL/AN4
GND
6
DATA IN
12
+3.3V
7
3
AN3/RA4
14
CON5
ICSP
1 RESET
10kW
2 +3.3V
CON6
10
10
14 MISO
14
16 IRPIN
16
21
21
5 PGEC
22
22
24
24
25 SCK
25
26
26
7
SD (3.5in)
8
Vcc
WP
CS
HOLD
1
IC3
FLASH
/RAM
Vss
+3.3V
2
SO
SCK
RB12/AN12
RB2/AN4
RB7/TDI
L_RST
L_CS
2
3
GND
1
VCC
+5V
VR1
100W
RB14/AN10
1kW
RB15/AN9
19
27
+3.3V
20
Q2
S IRLML2244
G
D
10kW
D
CON2
Q1
2N7002
G
+3.3V
PWM
BACKLIGHT
CONTROL
(OPTIONAL)
S
100nF
4
1 +3.3V
4.7kW
4.7kW
2
3
+3.3V
SCL
16
SDA
15
PGEC
3
4.7kW
SDA
RST
1
TS2
TS1
3
l
2
Vcc
10mF
1
IRPIN
(IC1 PIN16)
DATA
DHT22
GND
1
3
2
2
3
1
4
SC MICROMITE
Micromite
LCDLCD
Backpack
V3 V3
BACKPACK
Vcc
DQ DS18B20
VBAT
32kHz
14
CON9
1
NC
100W
K
A
IC4
DS3231
INT/SQW
5–12
GND
13
IRD1
LED1
2
Vcc
SCL
SDA
(IC1 PIN5)
SCL
4
18
3
10-47mF
2
Ó2019
6
L_D/C
MANUAL
BACKLIGHT
RB13/AN11
MICROMITE
I/O
6
LED (A)
PINS ON IC1
RB11/PGEC2
8
CON8
IRD1
4
RB9/TDO
+3.3V
IC
5
23
RB10/PGED2
4
SCK
2
14 25
3
MISO
8
RB8/TCK
GND
5
SI
RA3/CLKO
+5V
+5V
SCK
9
6
RA0/AN0
RB5/PGED3
MOSI
T_CS
7
RA2/CLKI
4
2
MOSI
9
MISO
10
RB1/AN3/PGEC1
9
4 PGED
1
CON7
SD_CS
5
T_IRQ
11
RA1/AN1
18
3
4
SCK
PGEC
100nF
3
MISO
5
7
RB0/AN2/PGED1
18 SDA
2
MOSI
12
4
17
1
RA4/SOSCO
PGED
17 SCL
+3.3V
13
4
3 GND
2x 10kW
SD (2.8in)
14
RB4/SOSCI
3 MOSI
RESET
CON3
AVDD
15
PGEC3/RB6
RB3/AN5
IC1
PIC32MX170F1
MCLR
256B-50I/SP
3
1
2
0V
K
SD_CS
VDD
11
LCD
TOUCHSCREEN
28
13
DATA OUT
PWM2/RA5
l
100nF
100nF
5
RC2/SDO/AN6 AN7/RC3
A
LED1
11
VUSB3V3
RC1/SDA
10mF
+3.3V
Rx
+V
5V
+3.3V
Tx
1
1
2
3
X
4
GND
10mF
+3.3V
OUT
IN
POWER
AND
+3.3V
CONSOLE
CON1
100nF
3. 4-pin I2C header
This connects to the I2C bus and 3.3V
power supply (CON8). Two 4.7kΩ pullup resistors are 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
same as for the SD card. That is why
you can’t use both at the same time.
If fitting this IC, 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.
Ensure your IC’s pin-out for this board
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.
2
RTC
BATT
1
Q1: 2N7002
2
3
Q2: IRLML2244
D
G
D
G
S
S
REG1
MCP1700
IN
OUT
GND
Fig.1: the Micromite LCD BackPack V3 circuit
comprises the complete V2 BackPack circuit,
(TS1 & TS2 ARE
ALTERNATIVES)
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).
GND
Practical Electronics | August | 2020
commonly available Arduino compatible I2C modules, such as character LCD
screens and other sorts of sensors.
4. DS3231 real-time clock IC
This (IC4) also uses the I2C serial bus.
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. Environment sensor
This is 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.5-inch display; 2.8-inch and smaller
displays based on the ILI9341 are natively supported by the Micromite.
The CFUNCTIONs for the 3.5-inch
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.5inch 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 above-mentioned optional
components are already supported by
MMBasic, so we didn’t need to write
much code to allow you to use all the
new features of the V3 BackPack. The
only thing that is not natively supported is the Flash or SRAM memory IC,
for which we’ve written demonstration
code, as explained earlier.
Practical Electronics | August | 2020
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, a V2 BackPack),
and then describe what parts to add if
you want to use any of the optional
features. See Fig.2, the PCB overlay
diagram, to see which parts go where.
Begin 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 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 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
with the other components installed.
If you use SMD capacitors, they will
all be the same type, but the two transistors are not. Check 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
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
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.
Here’s how the
3.5-inch display fits
over the BackPack V3 PCB. It
can also accommodate the 2.8-inch
display if you wish, but it’s designed
to suit the larger display.
19
Fig.2: the slightly
larger V3
BackPack PCB
can accommodate
a 2.8-inch
(320×240 pixel)
or 3.5-inch
(480×320 pixel)
LCD touchscreen,
using the inner or
outer set of four
mounting holes
respectively.
whether you are using a 2.8-inch
or 3.5-inch display – do 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.
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.
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 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.
If you are using PWM backlight control, the two resistors below Q1 and Q2
must be fitted. (Remember to check resistor values with a DMM.)
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 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 highvalue capacitors will be the same type.
There are three MKT or multi-layer
ceramic through-hole capacitors to fit.
Solder them in place and trim their leads.
Fit the two IC sockets next, if you
are using them. These are a good idea
20
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.5-inch 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 lefthand 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
Fitting optional components
The parts list mentions what
components you need to populate each optional add-on section.
These are all through-hole parts,
except the Flash IC (IC3), which
can be a through-hole or surfacemount type, and the DS32321 IC
(IC4), which is only available in a
surface-mount 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 oriented 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).
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.5-inch
touchscreen. The two four-way headers at left allow
either a 2.8-inch or 3.5-inch touchscreen to be fitted to this board.
Practical Electronics | August | 2020
Parts list – MicroMite BackPack V3
(to provide the same functions as the V2 BackPack)
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
1 double-sided PCB, coded 07106191, 99 x 54.5mm, available
from the PE PCB Service
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.8-inch or 3.5-inch LCD touch panel
[eg, SILICON CHIP ONLINE SHOP Cat SC3410]
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
Semiconductors
1 MCP1700-3302E/TO, TO-92 (REG1)
1 PIC32MX170F256B-50I/SP programmed with MMBasic
firmware, narrow DIP-28 (IC1) – from micromite.org
1 PIC16F1455-I/P programmed with the Microbridge
firmware, DIP-14 (IC2) – from micromite.org
1 3mm red LED (LED1)
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
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
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 whenever
power to the board is cut.
There isn’t much room for a battery
on the PCB (no mounting location is
provided) so you’ll have to figure out
how to mount it (eg, 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,
Practical Electronics | August | 2020
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 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 OR
1 GY-BMP280 temperature/pressure sensor module OR
1 GY-BME280 temperature/pressure/humidity sensor
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
PCB, reduced kit and PCB with presoldered SMD parts
The BackPack V3 PCB is available from the PE PCB service,
A reduced kit of parts and PCB with the SMD parts presoldered are available – visit micromite.org for full details.
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 (inside the box labelled TS1),
which needs to be fitted if either TS1
or TS2 is installed.
TS1 is tall, so it can be fitted laid over
towards IC4 – the vented side of the
case faces away from the 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, orient 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 is easier
to solder, and is oriented 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 include pullup 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 just one
set of pull-up resistors in the circuit.
21
Programming the chips
Both chips are available pre-programmed from our Micromite partner,
micromite.org, but you only really
need IC2 to be pre-programmed since
it is capable of loading the software
onto IC1, using pic32prog (see below).
However, having IC1 pre-programmed
will save you some effort.
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 2018
issue of PE.
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
baud on a freshly programmed Micromite, if you want to check this out
now, using your favourite serial terminal program.
Drivers
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.8-inch display,
then the same instructions as given
in the article from May 2018 (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.5-inch 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 opposite panel, Using the optional components,
which describes the software required
to use them.
Reproduced by arrangement with
SILICON CHIP magazine 2020.
www.siliconchip.com.au
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:
LIBRARY SAVE
22
To store the CSUB as a library instead of BASIC code, 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.8-inch 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.8-inch display.
Peter also noted the glitch with the MISO pin on these displays which we found (and worked around) while trying them
out in our June 2020 3.5-inch displays article and then on the V3
BackPack board.
Finally, future releases of the Micromite V2 firmware will include
a copy of Peter Mather’s ILI9488 CSUB driver.
Practical Electronics | August | 2020
Using the optional components
Using the infrared receiver (IRD1)
MMBasic only supports an infrared receiver on pin 16 of the 28pin 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; 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.
Practical Electronics | August | 2020
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 (see PE, May 2020).
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 2018 issue of PE explaining how to use a BMP180 or BMP280 module with a Micromite. You
can download the sample BASIC code for free from the August 2020
page of the PE website.
The BMP180/BMP280 provide temperature and pressure/altitude data,
but the BME280 also includes humidity. You can find MMBasic source
code to read data from a BME280 sensor at the (very useful) BackShed
forum: www.thebackshed.com/forum/forum_posts.asp?TID=8362
23
Driving the 3.5-inch touchscreen
When using the 2.8-inch 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.5-inch 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.8-inch 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 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.5-inch displays have twice as many pixels to manage as the 2.8-inch displays.
The following code needs to appear before the display functions
can be used with the 3.5-inch 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))
Our demonstration program, ‘ILI9488_SPI_minimal working. bas’,
can be downloaded from the August 2020 page of the PE website.
24
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 (in the same download package from the PE website)
shows how to read raw touch data and also calculate touch locations on the screen. In addition to 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.5-inch displays, although it is left connected
on our board, for use with the 2.8-inch displays.
Practical Electronics | August | 2020
|