This is only a preview of the August 2022 issue of Practical Electronics. You can view 0 of the 72 pages in the full issue. Articles in this series:
|
Make it with Micromite
Phil Boyce – hands on with the mighty PIC-powered, BASIC microcontroller
Part 38: How to build a PicoMite BackPack
L
ast month, we showed how
easy it is to load the MMBASIC
firmware into a £4 Raspberry Pi
Pico. The result – a ‘PicoMite’ – is
an extremely powerful module that
Micromite code
The code in this article is available
for download from the PE website.
40
offers 26 I/O pins. Since it is based on
the Micromite Plus firmware, it has
all the features of a MicroMite Plus,
which means there are many additional
graphics commands available to the
user compared to a standard Micromite.
Furthermore, there are also commands
that allow connection to an SD card,
enabling storage of program, data, image
and sound fi les. However, to be able
to take advantage of these features we
Fig.1. Some of the available Pico plugin display modules that can be used
to create a PicoMite BackPack. The
screens vary in size from 0.96-inch to
3.5-inch (with different screen-resolutions)
and come in a variety of technologies
including standard LCD, high-clarity IPS
and low-power OLED.
need to add a suitable display and SD
socket to the PicoMite. This is where
we can be smart and take advantage
of the many readily available low-cost
display modules that are designed to
be plugged directly onto a Raspberry
Pi Pico. By connecting an appropriate
display module (preferably with an onPractical Electronics | August | 2022
Display module choice
Fig.2. The Waveshare Pico-RTC-DS3231
is a high-accuracy Real-Time-Clock
module; perfect for adding to a PicoMite
BackPack. It has pins and sockets so it
can easily be sandwiched between the
PicoMite and the display module.
board SD socket) we effectively create a
PicoMite BackPack. As we’ll see, not only
is the PicoMite BackPack much more
powerful than the standard Micromite
BackPack, but also it is much cheaper,
and because no soldering is required,
it is also much quicker to get a project
up and running.
A point worth noting here is that
many of the available Pico display
modules are based on IPS screen
technology, which means superior
image quality – higher contrast and a
wider viewing angle than the screens
commonly used with the standard
Micromite BackPack.
As a bonus, there is nothing stopping
us from also using many of the other
types of plug-in Pico modules with our
PicoMite (ie, non-display modules).
This is a great way to quickly (and often
very cheaply) add a variety of other
features to the PicoMite. For example,
there is a high-accuracy Real-time Clock
(RTC) module available based on our
favourite RTC chip, the DS3231 (see
Fig.2). An RTC is a useful addition to
the PicoMite BackPack, so later in this
article we’ll show you just how easy it
is to add one.
There are many different plug-in display
modules available for the Pico (see
Fig.1). The three fundamental parameters
determining display choice are the physical
screen size, the shape and the pixel
resolution. Many of these displays can
work directly with the PicoMite thanks to
MMBASIC having various built-in display
drivers, but do remember that as with any
other Micromite, only one display can be
connected to a PicoMite at any one time.
To create a PicoMite BackPack, all you
need to do is choose a display for your
project, connect it to the PicoMite, and then
set a few OPTIONs at MMBASIC’s command
prompt (with the parameters dependent
upon the display module chosen).
To demonstrate this, we will discuss
how to set up two different PicoMite
BackPacks; one with a 2.8-inch
320x240 touchscreen (identical size
and resolution to a standard Micromite
BackPack) and the other with a 3.5inch 480x320 touchscreen. Note that
the process we use to create a BackPack
applies to any of the compatible
display modules; it is just the OPTIONs
parameters that vary.
Latest PicoMite Firmware
Since last month’s article, a new version
of the MMBASIC Firmware (v5.07.04)
has been released. The required file
(PicoMiteV5.07.04.uf2) is available for
free download from the August 2022 page
of the PE website (along with the updated
PicoMite User Manual). We advise you
to keep your PicoMite updated with
the latest version of MMBASIC as this
means you will have access to any new
commands or features that are introduced,
plus any bug-fixes.
An alternative source for PicoMite
firmware updates is via Geoff Graham’s
website (www.geoffg.net/picomite.html).
If you scroll to the Downloads section
near the bottom of the page, you will
find both files there, along with a text
file containing a list of known bugs. You
can also find the beta version of the next
PicoMite firmware (currently v5.07.05b9).
It is the most stable version of any beta
software I have ever come across – credit
to Geoff Graham and Peter Mather!
So, update your PicoMite to ensure
you’re running at least MMBASIC
v5.07.04 (or v5.07.05b9). Remember that if
you already have MMBASIC installed on
your Pico module, then you can use the
MMBASIC command UPDATE FIRMWARE
to bring up the Pico’s Flash drive (where
you place the relevant .uf2 file). However,
if it is a brand new (blank) Pico module,
then hold down the ‘BOOTSEL’ button
while powering up the Pico – see last
month in Part 37.
Pico Expander module
Before we begin creating our first
BackPack, we want to alert you to a type of
module that is useful when experimenting
with a PicoMite. This is the ‘Expander’
module which allows multiple Picocompatible plug-in modules to be used
simultaneously by extending all the
Raspberry Pi Pico’s pins to multiple
sets of pin headers (the Pico is plugged
into one socket header set). Expander
modules typically allow two or four plugin Pico modules to be used – see Fig.3.
Regardless of size (and shape), these
Expander modules are also very useful
as they provide quick and easy access
to all I/O pins. By using the popular
Dupont style jumper leads (with a female
connector at one end for plugging onto
the relevant Expander pin), the other end
of the lead (if male) can then be inserted
into a breadboard, or alternatively (if male
or female) the other end can be attached
to a socket or pin on another non-Pico
module (as we will see later when using
a low-cost, non-Pico RTC module).
So, even though an Expander module
is not required to make our BackPack, do
get one. It will be useful when you tinker
with your new PicoMite projects. Make
sure you also have a selection of Dupont
leads (female-male, and female-female).
We prefer leads that are approximately
20cm in length; and have never suffered
any issues with peripherals failing to work
due to impacted signal timing.
Now that we’ve updated the firmware,
let’s create a BackPack.
Fig.3. Pico Expander modules are available from different suppliers. Typically, they can connect either two or four Pico plug-in
modules to the Pico. They also provide easy access to all I/O pins, which are clearly marked on the silkscreen.
Practical Electronics | August | 2022
41
Fig.4. The Waveshare Pico-ResTouch-LCD-2.8 display module incorporates a 2.8-inch IPS touchscreen with a resolution of 320x240.
It also an on-board micro-SD socket (perfect for making a PicoMite BackPack).
2.8-inch (320x240) BackPack
What we will create is an alternative
to the standard 2.8-inch Micromite
BackPack. We will use a display module
from the popular online manufacturer
Waveshare. The specific module is the
Pico-ResTouch-LCD-2.8 (see Fig.4). If
you search online for this exact model,
you will soon find a supplier that has
them in stock; typical cost is around
£14.50 plus delivery. For readers who
are interested in a detailed description
of the module, visit: www.waveshare.
com/wiki/Pico-ResTouch-LCD-2.8
The only information that we really
need to understand from the datasheet is
the pin-out information – see Fig.5. The
reason for showing it here is that it will
help us to define the correct parameter
values when setting OPTIONs.
Now connect this specific display
module to your PicoMite, either by
plugging the PicoMite directly into the
display (Fig.6a), or by using an Expander
module (Fig.6b).
Next, connect your PicoMite to your
Terminal Application (ie, TeraTerm), and
at the command prompt, work through
the 12 steps shown below. (Note that the
PicoMite is reset after setting an OPTION
that saves parameters to memory, so you
may need to press the Enter key to get
Fig.5. The pin functionality and numbering used on the Pico-ResTouch-LCD-2.8. This
information is used to define what parameter values need to be entered in the various
OPTIONs that require setting.
42
the command prompt to appear again
after the PicoMite has reset).
1. Start by clearing any exiting OPTIONs
that have been set by typing the
command: OPTION RESET
2. To check there are currently no
OPTIONs set (or have just been cleared
from step 1), type the command:
OPTION LIST (this should return
no OPTIONs – if you see any listed,
simply type OPTION RESET again).
3. Set the PicoMite to run at its current
maximum speed of 252MHz (this is
not a requirement for the display
module, but it is worth doing so
that your PicoMite can perform
optimally). To do this, type: OPTION
CPUSPEED 252000
4. Next, we need to define the pins
used for the SPI bus (the bus used
to communicate with the display).
We do this by using the command:
OPTION SYSTEM SPI clk_pin,
mosi_pin, miso_pin (replace the
three parameters shown in italics
with the relevant pin numbers). Fig.5
shows this is entered as: OPTION
SYSTEM SPI GP10, GP11, GP12
5. To set the display driver, we use
the command: OPTION LCDPANEL
controller, orientation, DC,
RESET, CS, backlight (replace
the parameters with the relevant
values). The controller used in this
specific display module is the ST7789
(not the more familiar ILI9341). Refer
to the PicoMite User Manual and
you will see that there are various
displays that use this controller (each
with a different pixel resolution). To
distinguish between the different
ST7789 display modules, we add
a reference to the horizontal screen
resolution, so the controller
parameter we need to use becomes
ST7789_320. We will use Landscape
(L) orientation, although we
Practical Electronics | August | 2022
Fig.6. a) (left) Here, the 2.8-inch display module is shown attached directly to the PicoMite, resulting in a compact PicoMite BackPack.
Ensure the PicoMite is oriented correctly (note: the display module’s silkscreen highlights which end to align with the Pico’s USB socket).
Fig.6. b) (right) Alternatively, the display module and PicoMite can be connected together using an Expander module.
deviation will be reported,
but, if necessary, repeat this
command until you have near
to zero deviation. If this sounds
complex, don’t worry, simply
touch the crosshairs that appear
on the screen, and then check
the result displayed after all four
Fig.7. Once the PicoMite’s OPTIONs have been
corners have been touched. If
set, it is worth typing OPTION LIST to check all
either the X or Y value returned
parameters have been set correctly (here, the 2.8is higher than 5, then calibrate
inch settings are shown).
again. With a stylus and a steady
hand, you can get zero deviation.
9. To check the touchscreen calibration,
can choose portrait (P), reverseuse the command: GUI TEST TOUCH
landscape (rl) or reverse-portrait
and then use a stylus to draw on the
(rp). Therefore, with reference to
screen. You should see the pixels
Fig.5, we set the display driver with:
turning on at the point of contact – if
OPTION LCDPANEL ST7789_320,
not, go back and repeat step 8. Press
L, GP8, GP15, GP9, GP13
any key to exit this touch-test.
6. To check the screen is set up correctly,
10. Next we will set up the SD socket by
use the command: G U I T E S T
using the command: OPTION SDCARD
LCDPANEL (which displays the usual
SD_CS[, CLK, MOSI, MISO]. For
test animation of randomly placed,
this display module, we only need to
randomly sized, coloured circles).
define the SD_CS pin number, hence
Press any key to stop it. If you don’t
with reference to Fig.5, this is entered
see this, then use OPTION LIST to
as: OPTION SDCARD GP22
display the OPTIONs that are set, and
11. To check the PicoMite can read an SD
carefully check all of the parameter
card, carefully insert a micro-SD card
values. If you spot an error, simply
into the socket which is mounted on
type: OPTION LCDPANEL DISABLE
the back of the display module. Use
to delete the OPTION, and re-enter it
an SD card that has between 4GB
again with the correct values.
and 32GB capacity, and formatted in
7. To set up the touchscreen, we need
to use the command: OPTION TOUCH
T-CS, T_IRQ [,beep]. The optional
beep parameter is not used here as
the display module does not have
an onboard beeper (you could add a
beeper to any available I/O pin, and
define this pin number as the beep
parameter). Again, with reference to
Fig.5, the command is entered as:
OPTION TOUCH GP16, GP17
8. Next, calibrate the touchscreen with
the command: GUI CALIBRATE.
Simply follow the on-screen
instructions – touch each corner
in turn with a stylus (plastic gives
best accuracy and least wear to the
screen’s touch-overlay). If calibration
is performed successfully, minimal
Practical Electronics | August | 2022
either FAT16 or FAT32. Then type the
command: FILES to display a list of
any files and/or folders that are on the
SD card. If you see the message ‘SD
Card not found’, then chances are you
have entered an incorrect parameter
value (or not fully inserted the microSD card). Check the parameter value by
using OPTION LIST, and if necessary,
use OPTION SDCARD DISABLE to
delete the OPTION, and then repeat
step 10 to re-enter it correctly.
12. As a final check, if you type OPTION
LIST you should see exactly the
same OPTION parameter values as
shown in Fig.7 (but probably five
different parameter values shown
against GUI CALIBRATE)
Once you have successfully followed the
12 steps above, congratulate yourself;
you have just created a working 2.8-inch
PicoMite BackPack.
3.5-inch (480x320) BackPack
We will now describe how to set up a
PicoMite BackPack that uses a bigger
3.5-inch touchscreen, and which has
a higher pixel resolution. For this, we
will use another display module from
Waveshare, the Pico-ResTouch-LCD-3.5
(see Fig.8). Note that the typical price for
the 3.5-inch display module is £18.50 (so
Fig.8. The Waveshare Pico-ResTouchLCD-3.5 display (top left and above) is
similar to the 2.8-inch model (lower left),
apart from being slightly bigger and having
a higher pixel resolution (480x320).
43
Fig.9. The pin functionality and
numbering used on the Pico-RTCDS3231. This information is used
to define the I2C parameters (SDA
and SCL) that need to be entered
for OPTION SYSTEM I2C.
just £4 more than the smaller 2.8-inch). Again, more details
about this display module can be found at: www.waveshare.
com/wiki/Pico-ResTouch-LCD-3.5
Rather than discuss the process step-by-step, we will
instead simply summarise the 12 steps required (which are
essentially identical to the steps performed above for the 2.8inch BackPack).
1. OPTION RESET (clear any previous OPTIONs that were
saved)
2. OPTION LIST (check all OPTIONs have been cleared)
3. OPTION CPUSPEED 252000 (run PicoMite at 252MHz)
4. OPTION SYSTEM SPI GP10, GP11, GP12 (configure
SPI bus)
5. OPTION LCDPANEL ILI9488W, RL, GP8, GP15, GP9,
GP13 (configure the specific display module – note: use
reverse-landscape orientation with this display module)
6. GUI TEST LCDPANEL (check screen set up correctly)
7. OPTION TOUCH GP16, GP17 (configure touch)
8. GUI CALIBRATE (calibrate touch)
9. GUI TEST TOUCH (check touch calibration)
10. OPTION SDCARD GP22, GP5, GP18, GP19 (configure
SD socket – note: we need to define the SPI pins with this
display module)
11. FILES (check SD card)
12. OPTION LIST (check that all OPTIONs parameter values
are correct).
Once you have successfully followed these twelve steps, you
will have a working 3.5-inch PicoMite BackPack.
Steps for using other displays
From the above two examples describing the steps required
to set up a BackPack, you will see that there are only four
steps (4, 5, 7, and 10) that need changes to parameter values,
depending on the specific display module being used. Refer to
the display module’s datasheet for the relevant pin numbers, and
the type of display controller used (ie, the
equivalent of Fig.5). Once you have done
this a couple of times, you will find that
to set up a brand new PicoMite BackPack
will take no more than five minutes (and
that includes loading the firmware onto
a ‘new’ (ie, blank) Pico). Yes, it really is
that quick to set up a powerful PicoMite
module with a choice of display size that
matches your project’s requirements.
Adding an RTC
We will now show how easy it is to add
an RTC to the PicoMite BackPack. For
this, we will use yet another module from
Waveshare; the Pico-RTC-DS3231 (see
Fig.2; and for further details, visit: www.
waveshare.com/wiki/Pico-RTC-DS3231). One thing to point
out here is the cost – it is typically around £9.50 which by
itself isn’t too bad, but when compared to the cost of the Pico
module, the RTC costs almost three times as much! Anyway, let’s
proceed on the basis that we can indeed afford this particular
RTC module (although do see the next section if you have an
alternative DS3231 module available).
The pinout of the Waveshare RTC module is shown in
Fig.9; again, it will be a useful reference to help understand
the parameter values that we use in the single OPTION that
we need to set.
Begin by physically connecting the RTC; this can be done
by either sandwiching it between the PicoMite and the display
module (Fig.10a), or by inserting it into an Expander (Fig.10b).
There are just four simple steps to complete the configuration
of the RTC (including testing that it works correctly):
1. First, we need to define the pins used for the I2C bus (the
bus used by the DS3231 RTC module). To do this, use the
command: OPTION SYSTEM I2C SDA_pin, SCL_pin
Referring to Fig.9, you will see that the command and
parameters need to be entered as: OPTION SYSTEM I2C
GP20, GP21
2. Next, we need to set the Date and Time in the RTC module
with the command: RTC SETTIME year, month, day,
hours, minutes, seconds
If the date is 3 July 2022, and the time is 4:45 pm,
then the command would be entered as: RTC SETTIME
22,7,3,16,45,00 (check with an Internet-based clock:
https://time.is). When you press Enter for the above
command, the precise date and time values will be sent
to the RTC module; and the RTC will manage them until
either the RTC SETTIME command is used again, or the
RTC’s onboard battery is removed (or expires – although
it should last many years before it needs replacing). Note
that if you see an error message along the lines of: ‘RTC
not responding’, then this means one of two things: either
Fig.10. a) (left) The Waveshare Pico-RTC-DS3231 sandwiched between the PicoMite and the display module; b) (right) The
Waveshare Pico-RTC-DS3231 inserted into a quad Expander module.
44
Practical Electronics | August | 2022
Fig.11. This is a low-cost alternative RTC
module. The four labelled pins need to be
connected to the PicoMite (see text).
the RTC is not inserted correctly
(check it’s not rotated 180°!), or the
I2C parameters are incorrect (check
by using OPTION LIST and make
sure that GP20 and GP21 have been
correctly entered).
3. Once the RTC’s date and time have
been set up, there is one more OPTION
that we advise setting: OPTION RTC
AUTO ENABLE – it will force the
firmware to upload the correct date
and time from the RTC into the two
MMBASIC system strings: DATE$ and
TIME$. This ‘upload’ is performed
automatically whenever the PicoMite
is initially powered up, and thereafter
every hour.
4. To test the RTC has been set up
correctly, simply remove power
from the PicoMite, then reconnect
power (the easiest way to do this is
to remove one end of the USB lead
that connects the PicoMite to your
computer, then reinsert it). Then, at
the command prompt, type: PRINT
DATE$ followed by PRINT TIME$.
On pressing the Enter key, you
should see the correct date and time
returned. If not, check the RTC’s
battery! Note that if the RTC is
disconnected from the PicoMite
Fig.12. The alternative lower-cost RTC
cannot be plugged directly into the
PicoMite, so an Expander module and
four Dupont leads are used to connect it.
Practical Electronics | August | 2022
(when OPTION RTC AUTO ENABLE is
set), then the attempted ‘upload’ will
result in an error message (‘the RTC
cannot be seen’) and this OPTION
will also be automatically disabled.
In addition, if this situation arises
at the time of an hourly ‘update’
and while a program is running,
the program will stop, and the error
message displayed.
After following these four steps, you’ll
have a fully functioning PicoMite
BackPack complete with an RTC.
However, as mentioned above, you may
already have a different type of RTC
module, so let’s see what alternative
steps you need to set one up.
Using a non-Pico RTC
Let’s use the cheaper (£2) RPi mini
DS3231 module (see Fig.11). There are
just four connections we need to make;
two for power (3.3V), and two for I2C
communication (SDA and SCL). This RTC
module has a 5-way socket, so we’ll use
four female-male Dupont leads.
The datasheet for the DS3231 shows
that the RTC can run at either 5V or 3.3V;
however, it is important that we use 3.3V
when connecting it to the PicoMite. As
mentioned last month, the maximum
input voltage to any PicoMite pin is
3.6V, and if we accidently power the RTC
with 5V, then the I2C pins (being pulled
high by default) will also be at 5V. To
eliminate any risk to the Pico module,
ensure you connect the RTC power pin
(labelled ‘+’) to the Pico’s 3.3V output pin.
In last month’s Fig.7, the 3.3V pin on the
PicoMite is the fifth pin down from the
top-right corner (pin 36). For the GND
connection, there are several 0V pins to
choose from; for example, the third pin
down from the top-right corner (pin 38).
To make the two I2C connections we
will use the same pins on the PicoMite
as used in the example above for the RTC
Pico module. Hence GP20 is connected
to the RTC’s SDA pin (labelled ‘D’), and
GP21 to the RTC’s SCL pin (labelled ‘C’).
The four connections between the RTC
module and an expander module are
shown in Fig.12. Note that the pins are
‘flipped’ on the pin-headers so that the
left-hand row (in a set of header pins)
is essentially the right-hand row on the
PicoMite; simply follow the silkscreen
printed legends on the expander module
– they are clearly marked (this is exactly
why we find an Expander module so
useful for tinkering). In Fig.12, the
coloured leads are as follows: yellow
= 0V, purple = 3.3V, blue = SDA, and
green = SCL.
Now that we have connected the RTC
to the PicoMite, we can configure the
PicoMite to use it. We have used the same
I2C pins as in the previous example, so
you can follow the same four steps to
configure, set, and test the RTC module.
So, now perform the four steps to ensure
everything works as expected.
RTC demo software
We have made a short demo program
(RTCdemo.txt) available for download
from the August 2022 page of the PE
website. It displays the day, date and time
on your BackPack’s screen (see Fig.13).
Note that as supplied, it can be used on
any screen that has a horizontal pixelresolution of at least 320 pixels; hence
it is ideal for either the 2.8-inch or 3.5inch BackPack described in this article.
That said, it is very easy to follow what
is happening in the code, and so it can
be modified to run properly on different
sized (ie, smaller) screens.
Do test it on your new RTC PicoMite
BackPack, it demonstrates how, with
just three low-cost modules and a few
lines of MMBASIC code, you can quickly
create a working solution; in this case an
accurate clock – you can never have too
many clocks!
Summary
This month, we have given you the tools to
create a PicoMite BackPack. All you need is
the PicoMite created last month, to which
you add a compatible display of your
choice, set up with the relevant OPTIONs.
In addition, you should also understand
how to use other readily available plug-in
Pico Modules with a PicoMite – it is just a
Fig.13. The RTCdemo.txt program in action (running on a PicoMite that has been
assembled on a quad Expander module).
45
quickly do ‘proof-of-concept’
tests. Note too, it is possible to
build a complete project without
soldering (not what you would
expect to read in an electronics
magazine), however, the main
point we’re stressing here is
that the PicoMite BackPack is
a powerful building block that
you can use in virtually any
project – whether that project
requires a soldering iron, or not.
Pico-Eval-Board
The 3.5-inch screen used
on the 3.5-inch display
module discussed above is
also used on the Pico-EvalBoard (see Fig.14). This Pico
module contains many useful
components, such as a buzzer, a
mini-button, a photoresistor for
measuring light level, an RGB
LED (W2812B), a 9-axis motion
sensor (ICM20948), a LiPo
battery header (complete with
recharging circuit), and a reset
button (which, is also present
on the two display-modules
discussed earlier). For more
Fig.14. As well as having a 3.5-inch IPS touchscreen and a micro-SD socket onboard,
details, visit: www.waveshare.
the Pico-Eval-Board has additional components. It is the perfect display for building an
com/pico-eval-board
experimental PicoMite BackPack.
Fig.15 shows the pin numbers
used to connect to the various onboard
identifying the connections available on
matter of understanding the pin-numbers
components. It is shown here to inspire
the module being used.
used on the module being attached,
anyone opting to use this module in
It’s worth searching online to see what
and setting any OPTIONs accordingly.
their BackPack to access some of these
other Pico modules exist, and if any of
Furthermore, you are not limited to using
other components. For example, take a
them could assist you in quickly creating
plug-in Pico modules as we saw when we
look in the User Manual at the BITBANG
your next project idea. By using modules
hooked up a mini RTC module; again,
WS2812 command to see how easy it is
(and Dupont leads), it allows you to
it is just a matter of understanding and
to control the RGB LED. And for anyone
up for a challenge, try reading data from
the 9-axis motion sensor!
The cost of this module is typically
around £29.50, which at just £11 more than
the 3.5-inch display module, represents
good value for money. (It is the actual
module used in the photos in this article
showing the 3.5-inch PicoMite BackPack.)
Next time
At the time of writing, I am still waiting
for various Pico modules that should
have been delivered by now – the
world’s silicon supply chains are still
recovering. So, at this point, the next
topic depends on the postman! However,
I can confirm that we will be using some
more Pico modules to make something
fun and interesting.
Until then, stay safe, and have FUN!
Fig.15. The pin functionality and numbering used on the Pico-Eval-Board. Refer to this (and
PicoMite User Manual) to see if you can interact with some of the additional components.
46
Questions? Please email Phil at:
contactus<at>micromite.org
Practical Electronics | August | 2022
|