This is only a preview of the September 2021 issue of Practical Electronics. You can view 0 of the 72 pages in the full issue. Articles in this series:
|
Max’s Cool Beans
By Max the Magnificent
Flashing LEDs and drooling engineers – Part 19
I
’m so excited I want to run
round in ever-decreasing circles
shouting, ‘Don’t Panic!’ I first
read the seminal Foundation trilogy
(Foundation, Foundation and Empire,
and Second Foundation) by Isaac
Asimov when I was a young lad, and
I’ve re-read them on multiple occasions
ever since then, but never did I dare
to hope that these masterpieces would
one day be brought to life on the big (or
small) screen. So, you can only imagine
my surprise and delight when, earlier
this year, I became aware that Apple
TV+ was working on the Foundation TV
series. Even better, just a few moments
before I started penning these words,
I heard that this series is set to launch
on 24 September 2021. Now, all we
have to do is wait in antici...
...pation! What we need is something
to take our minds off things as we wait.
I know what we can do. While we are
twiddling our thumbs, we can pass the
time talking about 21-Segment Victorian
displays and SMADs (Steve and Max’s
Awesome Display) boards.
God save the Queen!
Let’s start by reminding ourselves that
Steve Manley in the UK and your humble
narrator in the US are both creating
10-character versions of the 21-segment
Victorian displays we introduced in earlier
columns (PE, July and August 2021). The
patent for the original display was first
filed in 1898 when Queen Victoria was
the ruler of all she surveyed (and quite
a lot beyond her window). In those days
of yore, the illumination was provided
by 21 small incandescent bulbs, while
the control was afforded by a cunningly
complicated contrivance of electromechanical complexion. In our case, each
display segment boasts one or two tricolour
LEDs (Fig.1), while our control functions
will be afforded by a microcontroller.
It goes without saying (but I’ll say it
anyway) that our displays are going to boast
myriad capabilities, including being able
to react to random sounds and music, but
much of the time they will be presenting
alphanumeric information such as the time,
date and a variety of text-based messages.
Is that the time?
So, what can we do with 10 characters?
Well, one obvious application is to display
the time in hours, minutes, and seconds
along the lines of 08:16:20. In this case, we
require only eight characters (six numbers
and two colons), which we could centre
on the display (Fig.2a).
One of the options we will provide is to
present the time in 12-hour (eg, 08:16:20)
or 24-hour (eg, 20:16:20) formats. The
abbreviation AM (or am or a.m.) stands
for ‘ante-meridiem’ (before the Sun has
crossed the meridian line), while PM (or
pm or p.m.) stands for ‘post-meridiem’
(after the Sun has crossed the meridian
line). Now, I don’t know about you, but
I’m usually cognisant as to whether I’m
currently in the AM or the PM, so I’m
reasonably confident in my ability to
work things out if my time is displayed
08 : 16 : 20
(b) 0 8 : 1 6 : 2 0
P
(c) 2 0 2 1 / 0 9 / 0 1
(a)
Fig.1. Map of LEDs (numbers) and
segments (letters) (Image source: Steve
Manley)
44
(d)
01 / 09/ 2021
(e)
09 / 01/ 2021
Fig.2. Time and date format alternatives.
in a 12-hour mode. On the other hand,
some users may prefer a more explicit
presentation, and we always have to
remember that things could become
somewhat confused in the event of a
zombie apocalypse, so we could also
offer the option to indicate ‘A’ (AM) or
‘P’ (PM) while in 12-hour mode (Fig.2b).
Want a date?
When I was a kid, my parents used to
serve a variety of nibbles to visitors over
the Christmas holidays. In addition to a
selection of nuts and pastries, they also
used to serve dates. Since I only saw these
tasty treats once a year, and as I was aware
they originated in exotic Middle Eastern
climes, I thought that these sweet fruits
were really, really special, but that’s not
the sort of date we’re interested in here.
When it comes to presenting the date
in a chronological sense, the format I use
with regards to naming files and folders
on my computer is YYYY/MM/DD with
leading zeros as required (eg, 2021/09/01)
(Fig.2c). For a variety of reasons this
is the most logical format to employ,
which probably explains why its usage
is relatively uncommon (humans; bless
their little cotton socks).
The next logical alternative is to flip
things around and use DD/MM/YYYY,
which places the values in order of
immediate significance to the viewer
(Fig.2d). Finally, for reasons that escape
my powers of description, we have the
MM/DD/YYYY format that is commonly
used in the US (Fig.2e).
It obviously makes sense for us to offer
our users the ability to select between
the three aforementioned formats when
2021 / 09 / 01
(b) 2 0 2 1 / 0 9 / 0 1
(a)
(c)
2021 / 09 / 01
09 / 01/ 2021
(e) 0 9 / 0 1 / 2 0 2 1
(f) 0 9 / 0 1 / 2 0 2 1
(d)
Fig.3. Alternative ways of setting the date.
Practical Electronics | September | 2021
Fig.4. Pseudo-brass front panels (Image source: Steve Manley)
it comes to displaying the date, but this
leads us to consider how our users are
going to set the date in the first place.
On the one hand, we could allow the
user to enter any old values in any old
order, setting the day to be 66 and the
month to be 42, for example, but that
really doesn’t make much sense. What
does make sense is to allow (force) the
user to enter only valid values.
Since the number of days in the
month depends on which month we are
talking about, this means that we must
persuade the user to specify MM before
DD. Similarly, since the number of days in
February depends on whether or not we
are in a leap year, it makes sense for us to
force the user to enter the date starting with
YYYY followed by MM followed by DD.
Let’s assume that the user has previously
specified that the date should be displayed
in the American MM/DD/YYYY format
(Fig.2e). One solution when it comes to
setting the date is to revert to the YYYY/
MM/DD format and guide the user to enter
the values in the correct order (Fig.3a, 3b,
3c). For example, we could implement
a cursor effect by flashing the current
character of interest (CCOI). Or we could
make the CCOI bright while dimming the
other characters, or we could make the
CCOI one colour and the other characters
another colour, and – of course – we could
use any combination of these effects.
On the other hand, if the user has
expressed a preference with regard to
the way in which the date should be
displayed, who are we to compel them
to use a different format when it comes
to setting the little rascal? Using any
combination of the cursor techniques
we just discussed, we could leave the
display in MM/DD/YYYY mode while
still guiding the user to enter the new
date in the order YYYY then MM then
DD (Fig.3d, 3e, 3f).
Can you think of another possibility?
I just did. My alternative suggestion is
at the end of this column.
Why, oh why?
You may be wondering why we are
talking about things as mundane as
displaying and setting the date and time.
Well, the problem is that a lot of people
don’t take the time (no pun intended)
to think this sort of thing out before
they leap into the implementation. As
an example, I have yet to successfully
set the clock in my new (2019) car. I’ve
perused and pondered the manual and
I’ve fought my way through myriad
layers of nested menus, but successfully
updating the display has defied me. It
shouldn’t be so hard. I’m the leading
engineer in my generation* for goodness’
sake (* should you doubt this statement,
may I refer you to my dear old mother
who will be delighted to help you see
the error of your ways).
The point is, at some time in the future,
you may end up creating some sort of
system that has to allow the user to set
and display some form of information.
My hope is that our discussions here
will aid you in your endeavours and
make the radiance of your users’ smiles
lighten your life.
I #### YOU
Fig.5. Analogue/digital multiplexer (Image
source: SparkFun)
Practical Electronics | September | 2021
I don’t think I’ve shown you a
representation of the two laser-cut
pseudo-brass front panels I’m using as
part of my 10-character display (Fig.4).
Steve wasn’t interested in the bottom
panel, but he kindly created the design
files for me, after which my chum Kevin
McIntosh, who is the owner of The Laser
Hut in the UK (https://bit. ly/2RqQ1Zj),
used his laser to cut them out for me.
So, what’s with the bottom panel? Well,
some time ago I was introduced to an
interesting article and video showing a
piece of word art that was created by Matt
Gorbett in 2007 (https://bit.ly/2THZLQf).
This piece involved eight characters
and two spaces that spelled out ‘I ####
YOU’ (when you include the spaces, this
would consume all 10 of the characters
in my display).
In Matt’s implementation, there are
four potentiometers located below the
four #### characters. Passersby can use
the potentiometers to select letters to
complete the message, such as ‘I LOVE
YOU’. After some period of time, the
system starts swapping individual letters
to form related messages until eventually
returning to its ‘I #### YOU’ state.
In my case, in the spirit of overengineering everything, I decided to have
potentiometers associated with each of
my characters. Of course, this potentially
means I’m going to require 10 analogue
input pins on my microcontroller.
Unfortunately (or fortunately, depending
on your point of view), when purchasing
my potentiometers, I didn’t pay as much
attention to the online ordering system
as perhaps I should. As a result, it was
only when the little scamps arrived
that I discovered they had associated
switches. Well, ‘waste not, want not,’ I
thought, but this potentially means that
I’m going to require 10 digital input pins
on my microcontroller, which means 20
pins in all (sad face).
Fortunately, the clever guys and gals at
SparkFun have us covered with a rather
cool 16:1 analogue/digital multiplexer
breakout board (https://bit.ly/2TPFY1a –
see Fig.5). Using only four digital output
pins on the microcontroller, we can select
one of the sixteen analogue signals from
45
Seeing eye to eye
Fig.7. An exploded view of the Owl Glasses display (Image source: Steve Manley).
The wonderful thing about SMADs is that
you can create an awesome display using
just one board. Having said this, much
like eating crisps (‘chips’ in the US), it’s
hard to stop with just one. For example,
one of the things Steve and I discussed
was the possibility of using two SMADs
to form the ‘eyes’ of a pseudo robot head.
Armed with his trusty 3D printer, Steve
created what I refer to as his ‘Owl Glasses’
display. Let’s look at an exploded view
showing the main frame (orange) and
one SMAD (Fig.7). If you want to create
your own Owl Glasses display, Steve has
kindly made the design files available.
A compressed ZIP file containing these
design files is available on the September
2021 page of the PE website at: https://bit.
ly/3oouhbl – file CB-September21-01.zip
contains the files for the main frame and
updated versions of both the 29-segment
and 45-segment shells.
Remember that Steve’s 3D printed
shells come in three parts – the front
half, the back half, and the facia. The
only reason for splitting the main shell
into two halves is to make them easier to
paint (use a white primer followed by a
gloss white finish to obtain the brightest
and most vivid colours).
Also, observe that these shells are
slightly different to the standalone
versions we discussed in the previous
column. Those shells had clear holes for
the machine screws used to mount the
displays because I like to see the screw
heads on my front panels. By comparison,
in the case of the shells for the Owl
Glasses, the holes in the front shell are
threaded (as are the blind holes in the
frame) because Steve prefers a no-screw
look. Also, there are no screw holes in
the facias, which are held in place by
small lips in the frame and aligned with
an alignment key (as are the shells). In
the case of the diffuser, we are employing
the white plastic separator sheets you
can purchase to use with file folders.
(For example, these white polypropylene
dividers from Toner Ink Online (https://
bit.ly/3inEODY – but of course others
will do just fine).
Steve created two versions of his Owl
Glasses display – one with 29-segment
shells and the other with 45-segment shells
(Fig.8). The important thing to note here is
that all four SMADs are displaying exactly
the same colours. This really illustrates the
difference between the larger segments in
the 29-segment shells where the colours
from two LEDs are diffused together, as
compared to the smaller segments in the
45-segment shells where the colours are
kept separate.
By comparison, I decided to create two
‘robot heads’ inspired in part by WALL-E
(https://youtu.be/_kslEYbMr1g – see Fig.9).
The white card box in the foreground of
46
Practical Electronics | September | 2021
Fig.6. It’s a SMAD, SMAD, SMAD, SMAD world: (left) SMAD board, (right) SMAD LED
and segment map.
for only £11.95 each, which includes
the potentiometers, which we can feed
shipping in the UK (shipping outside
to one of the microcontroller’s analogue
the UK will be quoted separately).
inputs. If we add a second board, we can
Each SMAD contains 45 tricolour
use the same four control pins to select
LEDs (Fig.6 left). Typically, we attach
one of the sixteen digital signals from the
a ‘shell’ to the front of the board to
potentiometers’ switches, and we can feed
compartmentalise the light from the
this signal to one of the microcontroller’s
LEDs, where these shells can be 3D
digital inputs. Thus, using only six of
printed or laser-cut (see last month’s
the microcontroller’s pins, we can read
Cool Beans for more details). Our original
the analogue and digital values from ten
shells boasted 29 segments, with 13
potentiometers and associated switches.
segments containing only one LED and
Pretty cool, eh?
16 segments containing two LEDs (Fig.6
right). However, Steve then decided
Are you SMAD?
to experiment with 45-segment shells
As we discussed in last month’s Cool
with one LED per shell, which left us
Beans (PE, August 2021), creating a fullin a bit of a pickle. On the one hand, we
up 10-character 21-segment Victorian
delight in the gradient effects that can be
display is a bigger project than most
achieved by varying the colours of the
readers care to commence. Also, the
LEDs forming the dual-LED segments
software for the little rapscallion is more
in the 29-segment shell; on the other
complex than we want to discuss here.
hand, we relish the stained-glass effect
Our solution was to create SMAD boards,
presented by the 45-segment shells. In
which are available for purchase from the
the end, we decided to use both.
PE PCB Service (https://bit.ly/3wVUgLq)
SMAD PCB (1.6mm)
Back half of shell (5mm + 1.6mm)
Front half of shell (5mm)
Diffuser (0.1mm)
Facia (1mm)
Alignment key
Owl Glasses frame (13.7mm)
Fig.9. Two robot heads with 45-segment shells (left) and 29-segment shells (right).
Fig.8. Two Owl Glasses displays with
29-segment shells (top) and 45-segment
shells (bottom) (Image: Steve Manley).
this image is the mockup I created as a
prototype. Observe that I’ve still got to build
the overhanging tops and sides for the real
heads. Just to vary things up a bit, I decided
to have black shells on a nickel-coloured
face for one head, and nickel-coloured
shells on a black face for the other. I used
slotted, pan-head steel machine screws to
attach the shells because it matches my
‘steampunk aesthetic’ (in the case of the
black shells, I used ‘gun blue’ liquid to
blacken the heads of the screws).
The very first test
For my very first test, I just wanted to
make sure that I could light the red, green
and blue channels in each of my LEDs
individually (you can see my code in
file CB-September21-02.txt). Remember
that we are using WS2812 LEDs (a.k.a.
NeoPixels), which can be daisy-chained
together. In my case, I’ve also daisychained all four SMADs, thereby giving
me a single string of 4 × 45 = 180 LEDs.
At the top of my sketch (program) you
will see the following definitions:
#define NUM_NEOS_PER_SMAD 45
#define NUM_SMADS
4
Also, I define NUM_NEOS as being NUM_
NEOS_PER_SMAD multiplied by NUM_
SMADS. This means that you can easily
modify this program to work with your
own setup comprising one, two, or more
SMADs by simply changing the value
assigned to NUM_SMADS.
We introduced NeoPixels in depth in
an earlier Cool Beans (PE, July 2020), but
it might be a good idea to briefly remind
ourselves as to how these little beauties
work in case you are new to the party.
First, make sure you have the latest version
of the Arduino Integrated Development
Environment (IDE) downloaded to your
Practical Electronics | September | 2021
computer from the Arduino.cc website
(the current version at the time of this
writing is 1.8.15).
Next, make sure you have the latest
version of whatever library you wish to
use to control your NeoPixels. If you wish
to use Adafruit’s NeoPixel library, launch
the Arduino IDE, select ‘Tools -> Manage
Libraries,’ search for ‘Adafruit NeoPixel,’
and install the ‘Adafruit NeoPixel’ entry
(don’t be lured by the DMA and other
options). Alternatively, if you prefer
to use the FastLED library created by
Daniel Garcia, search for ‘FastLED’ in the
Arduino’s library manager. (If you already
have these libraries installed, you can use
the same mechanism to check to see if
they need to be updated.)
When you instantiate your string of
NeoPixels (I named my string ‘Neos’), you
specify the number of pixels in the string
and the microcontroller pin you are using
to control them (look at my test program
for an example).
The act of instantiating the string
creates an array in the Arduino’s memory.
This array contains three bytes for each
pixel, where these bytes are used to
store that pixel’s red, green and blue
components specified as 8-bit integers
with values from 0 to 255. Suppose we
wish to change the colours associated
with pixel 6 to be red = 255 (0xFF
in hexadecimal), green = 128 (0x80),
and blue = 66 (0x42). We can do so by
specifying each channel individually
using Neos.setPixelColor(6, 255,
128, 66) or Neos.setPixelColor(6,
0xFF, 0x80, 0x42). Alternatively,
we can specify all three colour
components as a single value using
Neos.setPixelColor(6, 0xFF8042).
The important thing to remember is that
the setPixelColor() function doesn’t
actually modify the display in the real
world. All it does is to change the values in
the array stored in the Arduino’s memory.
It’s only when we use the Neos.show()
function that all the colour values in the
array are uploaded into the NeoPixel string
and presented to the user.
Good dates
Earlier on, we posed a question as to the
best way to set the date on the Victorian
display. I seem to have dates on my mind,
because I was just reminded of the scene
from Raiders of the lost Ark when Indiana
Jones throws a date into the air and his
friend Sallah (on seeing the dead monkey)
grabs it and says, ‘Bad dates’ (see: https://
bit.ly/2UzTgiu).
Of course, we are dealing with the other
kind (ie, good dates). Originally, when it
came to setting the date on my Victorian
display, I was thinking of the display
showing things in the form YYYY/DD/MM
or DD/MM/YYYY, or even MM/DD/YYYY,
as we discussed earlier. But then it struck
me that we have a full-up alphanumeric
display capability, which means we can
use the display to show, ‘YEAR=?’ followed
by ‘MONTH=?’ followed by ‘DAY=?’ and
– in each case – simply leave the user to
enter the appropriate number and then
press the OK button.
Coming soon
In next month’s column we will start to
experiment with some of the clever effects
we can achieve with our SMADs. In the
meantime, I would love to see pictures
should you decide to create your own
robot head or any other form of SMADbased artifact (we might even feature your
creation in a future column). Until then,
as always, I welcome your comments,
questions and suggestions.
Cool bean Max Maxfield (Hawaiian shirt, on the right) is emperor
of all he surveys at CliveMaxfield.com – the go-to site for the
latest and greatest in technological geekdom.
Comments or questions? Email Max at: max<at>CliveMaxfield.com
47
![]() ![]() |