This is only a preview of the August 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 18
A
s usual, I have so many things bouncing around
my poor old noggin that I don’t know where to start, not
the least of which is that just saying the word ‘noggin’
has reminded me of Noggin the Nog (https://bit.ly/3ckKqed),
which was a cult classic from the golden age of British children’s
television when I was a kid in the early 1960s.
Revisiting Victorians
Let’s start by reminding ourselves that in my previous
column (PE, July 2021) I introduced my new hobby project,
which involves recreating 21-segment Victorian displays
using modern tricolour LEDs. To be honest, my chum Steve
Manley in the UK is doing most of the heavy lifting on this
project – designing the circuit boards, for example – with
me bobbing up and down like a deranged meerkat (https://
youtu.be/57jEMZ87ND8) in the background, offering helpful
(some may say useless) suggestions.
Steve started by creating a single-character display board
50mm wide by 64mm tall. Seven of the segments have only
one tricolour LED, while the other fourteen segments each
have two LEDs, resulting in 35 LEDs in all. Steve also created
a 3D printed ‘shell’ that’s 10mm deep and which separates the
LED board from a diffuser.
Steve and I are both creating 10-character displays, which
therefore employ 10 LED boards and 10 shells. Actually, this
would be a perfect time for you to take a look at a video Steve
posted on YouTube that shows all of this in fantastic detail:
https://bit.ly/2T4sgXl
The problem is that we have 35 × 10 = 350 LEDs, each
requiring 24 bits of data (8-bits each for the red, green and
blue channels). The Adafruit Library uses a clock rate of
800kHz, which means it takes (350 × 24) / 800,000 = 0.0105
seconds (s), or 10.5 milliseconds (ms) to upload all the data.
Let’s round this up to 11ms.
One point to note here is that while the Adafruit library is
uploading the data to the LEDs, it’s consuming 100% of the
microcontroller’s central processing unit (CPU) resources,
which means the CPU cannot be doing anything else during
this time.
I’m reasonably confident that we are going to be performing
a humongous number of calculations to implement the
special effects we have in mind. If we assume that we can
perform all of these calculations in 9ms, this means we have
a total cycle time of 11 + 9 = 20ms. In turn, this means we
have a maximum refresh rate of 1,000 / 20 = 50Hz for our
display. To be honest, this is probably more than adequate
for this particular application but – given a choice – we’d
prefer to do better.
Since we are using a Teensy 3.2 or 3.6 microcontroller,
another alternative is to use PJRC’s OctoWS2811 library
(https://bit.ly/3z589ZO). This library has a limited set of inbuilt functions, which means you have to do things like
fading from one colour to another yourself (this is true of the
Adafruit library also). However, its main claim to fame is that it
Take control
Another thing we discussed in my last column is the fact
that, in previous projects, Steve and I have gone our own
way with regard to hardware (eg, microcontrollers) and
software (eg, libraries), which resulted in an inability to
share our code. In order to address this problem, in the case
of our Victorian displays, we decided to employ a common
platform, thereby allowing us to work on the code in a
collaborative manner.
The first piece of this platform was the control board. Since
we intend this board to be of use for future projects, we’ve
added everything we can think of in a general-purpose sort
of way. Our board includes a real-time clock (RTC), an audio
codec with an on-board microphone so we can respond to
sound, a light-dependent resistor (LDR) so we can respond to
ambient light, and infrared (IR) control. It can be ‘powered’
by either a Teensy 3.2 or a Teensy 3.6 microcontroller from
PJRC: https://bit.ly/3h5tifW
Lucious libraries
Remember that each of our 21-segment characters boasts
35 tricolour LEDs. These are WS2812 devices, which are
known as ‘NeoPixels’ by the Adafruit community. One option
open to us is to use the Adafruit NeoPixel library (https://
bit.ly/2T3s2zH) to control our LEDs. Personally, I love this
library, but that’s probably because it’s the one I first used
deep in the mists of time.
62
Fig.1. Power distribution board (Image source: Steve Manley).
Practical Electronics | August | 2021
Precocious prototypes
Fig.2. Prototyping board (Image source: Steve Manley)..
uses the microcontroller’s on-chip direct
memory access (DMA) engine to upload
eight strands of LEDs simultaneously.
Even better, the DMA engine runs in the
background, thereby leaving the main CPU
free to work on the next set of calculations.
There’s even a busy() function you can
call to determine if the previous upload
has finished before starting a new one.
But wait, there’s more, because there’s
also the FastLED library (fastled.io),
which is the one Steve favours. In addition
to being targeted at lower-performance (8bit) microcontrollers, the FastLED library
offers all sorts of tasty functions, including
HSV support in addition to RGB, where
HSV stands for ‘hue, saturation, and value’
(another name for ‘value’ is ‘brightness’).
There are some awesome FastLED videos
available that explain all of this in detail –
just bounce over to YouTube and perform
a search on ‘FastLED Basics.’
The really cool thing is that the FastLED
library can be used in conjunction with
the OctoWS2811 library. Unfortunately,
we haven’t yet worked out how to set the
DMA engine running in the background
when using this library combo; however,
we can still upload multiple strings
of LEDs simultaneously. Since our
Victorian displays have 10 characters,
we are treating them as five 2-character
pairs, and since each pair comprises 70
LEDs, this means our upload time is now
reduced to (70 × 24) / 800,000 = 2.1ms,
which increases our maximum possible
refresh rate accordingly.
Feel the power
In the case of future projects employing
fewer LEDs, we could decide to power
those LEDs directly from the main control
board. However, as we previously noted,
each of our Victorian characters has 35
LEDs. These devices are of the WS2812B
flavour that consume a maximum of 15mA
for each RGB sub-channel, which means
a total of 3 × 15 = 45mA per device. In
turn, this means that if every LED in
every segment was full-on white, each
character would be consuming 45 × 35 =
1575mA, or around 1.6A, which equates
to 16A for the full display. Eeek!
Obviously, this is a worst-case scenario,
but it has to be taken into account. Thus,
in addition to the main control board, we
also decided to create a power distribution
board (Fig.1). Since we were creating
this board anyway, we decided to throw
on a meaty 3.3V regulator, which can
be used to power things like sensors in
future projects.
Although we attempted to make our
main control board as all-embracing
as possible, your humble narrator is
oftentimes a victim of scope creep
because I keep on wanting to add more
and more features.
For example, in an earlier column (PE,
January 2021), I talked about adding one
of Adafruit’s BNO055-based 9-DOF (nine
degrees of freedom) Fusion sensor breakout
boards (BOBs) (https://bit.ly/3dP8EwU) to
my 12×12 ping-pong ball array, thereby
allowing me to control the ‘rolling’ of a
lit pixel by detecting the tilt of the array.
Well, in the case of my 10-character
Victorian display, I was thinking if might
be fun to add a similar capability such
that tilting the display to the left could
cause text to ‘slide’ in from the right,
and vice versa.
Thus, we also decided to create a
prototyping board (Fig.2). There are
several interesting things to note about
this board. Let’s start with the lowhanging fruit in the form of the mounting
holes, some of which are slots. A similar
arrangement is seen on the main control
board (PE, July 2021). This came about
because Steve decided to increase the
gap between adjacent characters by about
3mm, which caused him to print new 3D
shells that were 1.5mm wider on each
side. Thus, having these slots means that
our control and prototyping boards can
accommodate both types of shells.
Now observe that, as opposed to having
only 5V and 0V rails running horizontally
across the top and bottom of the board, as
would be seen on a traditional prototyping
board, this board also provides 3.3V
rails. Furthermore, by offsetting the vias
(plated-through holes), Steve managed to
Fig.3. Starting the build.
Practical Electronics | August | 2021
63
Fig.4. Feast your orbs on my wiring.
squeeze a trio of 5V, 3.3V, and 0V rails
running across the centre of the board
while still maintaining the traditional
0.3-inch separation between the vertical
component signals on the upper and
lower halves of the board. In fact, there
are a bunch more innovative features
associated with this bodacious beauty,
but we have other fish to fry, as it were.
All together now
Before we go any further, let’s take a
brief stroll through the assembly of the
main section of my 10-character display,
commencing with all of the bits and
pieces being gathered together (Fig.3).
In the middle of this image, we see
the 10 shells. These were 3D printed in
grey plastic. I then sprayed them with a
white primer follower with gloss white,
because this dramatically improves the
intensity of the display.
Behind the shells, we see the back
sides of the 10 LED circuit boards.
These are presented in pairs linked
by small bridging boards that Steve
created, but that he can no longer use
since he increased the spacing of his
characters (Ha!).
In the foreground, we see a pseudo
brass panel, which was cut for me by
my chum Kevin, who is the owner of
The Laser Hut in the UK (https://bit.
ly/2RqQ1Zj). I have awesome plans for
a cabinet to house my display, but we
will leave that for another day.
I won’t bore you with a step-by-step
account of this build, save to say that
the wiring took me a lot longer than I’d
expected because I didn’t want to let
the side down (Fig.4). As I told my wife
(Gina the Gorgeous), I could have wired
everything up a lot faster if I was prepared
to sacrifice neatness. The problem is,
deep in the mists of time, as part of his
apprenticeship before moving on to
research and development, Steve served
in an aircraft electrician’s department. As
a result, his wiring always looks awesome,
and I didn’t want to be outdone.
In my case, I decided to mount the
control board in the middle of the
display, the power distribution board
on the left, and the prototyping board
on the right. Have you noticed that these
boards are coloured red, green, and blue,
respectively? This was a little visual joke
that tickled our fancy. Ideally, we would
have made the power distribution board
red and the control board green, but – for
reasons unknown – the printed circuit
board (PCB) fab Steve used would have
charged a lot more to have the 2 oz copper
required by the power board presented
on a red substrate, so we went with the
flow. I don’t know about you, but I’m
really impressed with the way this all
came out (Fig.5).
A bit of a character
There are multiple ways in which we
intend to use our displays. One will be
to display numerical information like
the date and time. Another will be to
display textual messages. In order to do
this, we need to decide which groups of
segments need to be illuminated in order
to represent the various alphanumeric
characters and punctuation symbols.
In fact, there’s an incredibly useful
character visualisation tool available on
the internet (https://bit.ly/3wYvvyn). This
is presented on two pages, which can be
selected at the top. The ‘Produced’ page
allows you to choose between 8-, 16-, 24-,
Fig.5. The final assembly.
64
Practical Electronics | August | 2021
Fig.6. Segment map (Image source:
Steve Manley).
34-, 43-, 66-, and 93-segment displays
(the 8-segment is actually a 7-segment
with a decimal point). By comparison,
the ‘Experimental’ page allows you to
choose between 6-, 21-, 23-, 50-, 52-, and
55-segment displays.
I strongly recommend that you take the
time to visit and play with this tool. Go
to the ‘Experimental’ page and select the
21-segment option. By default, the display
cycles between random characters, but if
you start typing you will see the characters
you type appear before you. Furthermore,
if you move your mouse cursor across the
display, you will see whatever segment
is under the cursor light up white (if that
segment is currently off) or pink (if that
segment is currently on). You can click
on the various segments to toggle them
on and off in order to see how different
combinations will appear.
Come to the fore
Before we proceed, let’s pause to consider
our LED/segment map (Fig.6). As we
see, we can think of our 21 segments as
being annotated ‘A’ to ‘U’ and our LEDs
as being numbered from 0 to 34. Now,
( a ) R i ng s
we aren’t going to dive deep into our
code here. Suffice it to say that we have
definitions of which LEDs correspond
to which segments and which segments
correspond to which characters. For
example, our letter ‘A’ is defined as
comprising segments A, B, C, D, E, H, I,
J, K, L, O, S, and U.
Our character definitions are
represented as 32-bit hexadecimal values,
of which only 21 bits are used, where each
of these bits corresponds to a segment, and
0 or 1 values are used to specify if that
segment should be off or on, respectively.
So, how are we going to actually display
our characters? Suppose we wish to
display white characters on a black
background. The simplest approach
would be to start by turning all of the
segments off (black), and then setting the
segments corresponding to a ‘1’ in our
definition on (white). Alternatively, if we
desire black text on a white background,
then we could start by turning all of our
segments on (white), and then clearing
the segments corresponding to a ‘1’ in
our definition to off (black).
A more sophisticated approach – the
one we are using – is to have the concept
of a foreground colour, a background
colour, and a mask. Let’s say that we set
our background colour to black and our
foreground colour to white. Our character
definition acts as the mask. In the case
of the segments corresponding to a 0 in
our character definition, we display the
background colour. By comparison, in
the case of the segments corresponding
to a 1 in our character definition, we
display the foreground colour.
Thus far, we’ve assumed static colours.
Where this starts to get really clever is
if we allow both our background and
foreground colours to be dynamic. For
example, we could present a constantly
changing rainbow of colours on the
segments forming our background
while having the foreground colour a
static white. Furthermore, each of the
background segments could be the same
( b ) Verti ca l s l i ces
Fig.7. Different ways of slicing and dicing the LEDs.
Practical Electronics | August | 2021
( c) H ori z onta l s l i ces
rainbow colour, or we could have the
rainbow rippling across the display.
Slicing and dicing
Once you’ve wrapped your brain around
the foreground-background concept – in
particular, the fact that any of the effects
we are displaying are logically separated
from the way in which we control the
segments to represent the characters –
then you will start to realise just how
powerful this technique can be.
This leads us to consider different
ways in which we might decide to ‘slice
and dice’ our LEDs. For example, we
could think of them as being concentric
rings (Fig.7a). In this case we could
implement what Steve and I refer to as
a starburst effect with different colours
radiating out from the centre. Steve
created an example video showing this
type of effect on two adjacent characters
(https://bit.ly/3fZTkjT). Now imagine
displaying the date, time or text with this
starburst effect applied to the background
colour and the foreground colour set to
white. Alternatively, imagine this effect
applied to the foreground colour with
the background colour being set to black.
Similarly, for some effects we might
want to think of the LEDs being grouped
in vertical ‘slices’ (Fig.7b), while for other
effects (eg, a graphic equaliser or audio
spectrum analyser) we might want to
consider the LEDs as being grouped in
horizontal ‘slices’ (Fig.7c).
Get SMAD!
It was around this point that we ran into
a bit of a problem. In future columns,
I would love to share code examples
with you, but the code for our Victorian
displays is a tad too complex to show
anything meaningful in this sort of
setting. Also, it’s unlikely that many
readers would want to invest the time
and effort (and money) in building
something like one of our 10-character
21-segment Victorian displays.
But turn that frown upside down into
a smile because we have a
cunning plan. Indeed, it’s
a plan so cunning that we
could pin a tail on it and call
it a weasel, as Blackadder
would say (always remember
that, while eagles may soar,
weasels rarely get sucked into
jet engines).
What we’ve done is to
create a special incarnation
of our original display, where
this new version is called
a SMAD (Steve and Max’s
Awesome Display). As you
can see, this has the hint of
a sniff of the look-and-feel of
one of our Victorian displays,
but it’s more symmetrical
65
a tempting teaser,
take a look at a
video of an early
test that Steve
performed as
soon as the boards
arrived back from
fabrication and
assembly (https://
bit.ly/3z5xCSJ).
On the left we
see a bare SMAD
board; on the
right we see a
SMAD with a
29-segment 3D
printed shell and
Fig.8. SMAD circuit board with 45 tricolour LEDs (Image source:
diffuser (Fig.9).
Steve Manley).
For our diffand contains 45 tricolour LEDs grouped
users, we are employing the white plastic
into 29 segments (Fig.8). In this case, the
separator sheets you can purchase to
devices we are using are of the WS2812C
use with file folders, such as the white
flavour that consume a maximum of
polypropylene dividers from Toner Ink
only 5mA for each RGB sub-channel,
Online (https://bit.ly/3inEODY). If you
which means a total of 3 × 5 = 15mA per
look closely, in the right-hand image, you
device. This means that if every LED in
can see the corners of the square circuit
every segment was full-on white, each
board sticking out from behind the round
character would be consuming only 15
shell. This explains the ‘breakaway’ holes
× 45 = 675mA or around 0.7A.
and slots in the corners of the board in
The really exciting news is that these
Fig.8. If you break these corners off,
SMAD boards, which are a modest 70mm
the contour of the board will match the
× 70mm square, are available from the
contour of the shell.
PE PCB Service (https://bit.ly/3wVUgLq)
As you will discover, we can create
for only £11.95 each, which includes
mind-boggling ‘Ooh!’ and ‘Aah!’ effects
shipping in the UK (shipping outside the
using a single SMAD. Now, imagine what
UK will be quoted separately). Observe
we can do with two. Do you remember
that there are two sets of 0.1-inch pitch
the WALL-E animated movie in which
3-pin pads shown in the foreground of
the friendly little robot had two big
this image. One set comprises 0V, 5V
eyes? Well, that’s what I’m planning
and Data-in (the legends are on the back
on doing – creating a simple ‘head’ that
of the board); the other comprises 0V,
has two SMADs as eyes and then seeing
5V and Data-Out (for use if you wish to
what effects I can create, like ‘blinking’
daisy-chain multiple SMADs together).
or ‘looking’ left, right, up and down.
Note that you’ll have to provide your
Maybe using colours to reflect emotions
own 3-pin headers, or you can solder
like happy, sad and angry. The world is
wires directly to the pads.
our lobster (or oyster or crustacean of
In future columns, in addition to
our choice).
cogitating and ruminating on our
Victorian displays, we will be perusing
29 or 45?
and pondering small test programs to run
I must admit that I was a happy chappy
on our SMAD boards. I’m thinking that,
– a man with a plan (if we don’t have a
as one of our experiments, we could make
plan, we’re no better than arts students, as
it react to sound in interesting ways. As
the saying goes) – until that little scamp
Fig.9. Early test: Bare SMAD (left). SMAD with shell and diffuser (right).
66
Steve threw a great big spanner into the
works. The man simply cannot stop
playing with his 3D printer. As we saw
in Fig.8 and Fig.9, SMADs were originally
conceived as being 29-segment displays
with 13 small segments containing one
LED each and 16 long segments containing
two LEDs each. But then Steve decided
to see what would happen if he created
a shell that partitioned each of the longer
segments into two halves, thereby creating
a 45-segment display.
Originally, I was not a fan of this idea
because I like the subtle gradient effects
that can be achieved by mixing two
colours in the same segment. But then
Steve created a new video and now I’m
not so sure (https://bit.ly/3pqNavS). On
the left we see a bare SMAD board, in the
middle we see a SMAD with a 29-segment
3D-printed shell and diffuser, and on the
right, we see a SMAD with a 45-segment
3D-printed shell and diffuser (Fig.10).
We now tend to refer to the 29-segment
and 45-segment incarnations as a
‘gradient fill’ and ‘stained glass’ shells/
SMADs, respectively. The problem is
that I can’t decide which I like best. As
a result, I now have to build two robot
heads, one boasting a pair of gradient
fill eyes and the other flaunting a brace
of stained-glass eyes.
For your delectation and delight, if
you decide to purchase one or more
SMADs and you wish to print your
own 3D shells, then Steve has kindly
made his DXF and STL files available
to us. Compressed ZIP files containing
these design files are available on the
August 2021 page of the PE website
at: https://bit.ly/3oouhbl – files CBAugust21-01.zip and CB-August21-02.
zip contain the files for the 29-segment
and 45-segment displays, respectively.
If you do determine to avail yourself
of these files, you’ll see that the shells
come in three pieces: back, front and
facia (or faceplate). Steve split the main
10mm-thick shell into the two 5mmthick front and back sub-shells in order
to make them easier to spray-paint. The
thin sheet of white plastic diffuser is
placed between the front shell and the
1mm-thick facia.
But wait, there’s more... Do you recall
earlier in this column when I mentioned
my chum Kevin, who is the owner of
The Laser Hut? Well, on the off chance
you don’t have a 3D printer, but you
still want some shells for your SMAD
displays, Kevin can use his lasers to
cut shells out of 9mm-thick MDF, along
with facias cut out of 1mm-thick black
or pseudo-metallic (nickel) materials. In
fact, Kevin sent me a video of the laser
cutting a pseudo-nickel facia (https://
bit.ly/3cn7ucu).
As I pen these words, I have four MDF
shells winging their way to me – two
Practical Electronics | August | 2021
Fig.10. Bare SMAD (left), 29-segment shell (middle), and 45-segment shell (right).
29-segment and two 45-segment. Each
of these shells is accompanied by two
faceplates, one black and one pseudonickel. I shall report further in a future
column. For the moment, let me just say
that Kevin has agreed to supply these
little rascals to anyone who wants them
(you can contact him at pe<at>thelaserhut.
co.uk). One 9mm-thick MDF shell and
one 1mm-thick face plate (your choice
of black or pseudo-nickel) will cost
£10, while two of each will cost £18. In
both cases, the postage will be £1.60 in
the UK (postage outside the UK will be
quoted separately).
GET T
LATES HE
T CO
OF OU PY
R
TEACH
-IN SE
RIES
A
VAILA
B
NOW! LE
Next time
Eeek Alors! This column has certainly
‘grown in the telling.’ I’m scared to think
what our illustrious editor and publisher
Matt Pulzer is going to say when he sees
how big it is. I only hope that the radiance
of Matt’s smile will continue to lighten
my life. In my next column, we will
delve deeper into matters pertaining to
my 10-character 21-segment Victorian
display, and we will also start to create
some experimental code and effects to
run on our SMAD displays. Until that
frabjous day (Callooh! Callay!), as always,
I welcome your sage comments, insightful
questions and helpful 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
Order direct from
Electron Publishing
PRICE £8.99
(includes P&P to UK if ordered direct from us)
EE
FR -ROM
CD
ELECTRONICS
TEACH-IN 9
£8.99
FROM THE PUBLISHERS OF
GET TESTING!
Electronic test equipment and measuring
techniques, plus eight projects to build
FREE
CD-ROM
TWO TEACH
-INs
FOR THE PRICE
OF ONE
• Multimeters and a multimeter checker
• Oscilloscopes plus a scope calibrator
• AC Millivoltmeters with a range extender
• Digital measurements plus a logic probe
• Frequency measurements and a signal generator
• Component measurements plus a semiconductor
junction tester
PIC n’ Mix
Including Practical Digital Signal Processing
PLUS...
YOUR GUIDE TO THE BBC MICROBIT
Teach-In 9
A LOW-COST ARM-BASED SINGLE-BOARD
COMPUTER
Get Testing
Teach-In 9 CD-ROM – Get Testing!
Three Microchip
PICkit 4 Debugger
Guides
Files for:
PIC n’ Mix
PLUS
Teach-In 2 -Using
PIC Microcontrollers.
In PDF format
© 2018 Wimborne Publishing Ltd.
www.epemag.com
This series of articles provides a broad-based introduction to choosing and using a wide
range of test gear, how to get the best out of each item and the pitfalls to avoid. It provides
hints and tips on using, and – just as importantly – interpreting the results that you get. The
series deals with familiar test gear as well as equipment designed for more specialised applications.
The articles have been designed to have the broadest possible appeal and are applicable to all branches of electronics.
The series crosses the boundaries of analogue and digital electronics with applications that span the full range of
electronics – from a single-stage transistor amplifier to the most sophisticated microcontroller system. There really is
something for everyone!
Each part includes a simple but useful practical test gear project that will build into a handy gadget that will either
extend the features, ranges and usability of an existing item of test equipment or that will serve as a stand-alone
instrument. We’ve kept the cost of these projects as low as possible, and most of them can be built for less than £10
(including components, enclosure and circuit board).
Teach In 9 Cover.indd 1
01/08/2018 19:56
PLUS – all this extra material!
PIC n’ Mix series of articles. Plus the full Teach-In 2 book – Using PIC Microcontrollers – A practical introduction – in
PDF format. Also included are Microchip’s MPLAB ICD 4 In-Circuit Debugger User’s Guide; MPLAB PICkit 4 In-Circuit
Debugger Quick Start Guide; and MPLAB PICkit4 Debugger User’s Guide.
ORDER YOUR COPY TODAY JUST CALL
01202 880299 OR VISIT www.electronpublishing.com
Practical Electronics | August | 2021
67
|