Silicon ChipMax’s Cool Beans - July 2021 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Subscriptions: PE Subscription
  4. Subscriptions: PicoLog Cloud
  5. Back Issues: PICOLOG
  6. Publisher's Letter
  7. Feature: The Fox Report by Barry Fox
  8. Feature: Techno Talk by Mark Nelson
  9. Feature: Net Work by Alan Winstanley
  10. Project: ATtiny816 Breakout and Development Board with Capacitive Touch by Tim Blythman
  11. Project: Infrared Remote Control Assistant by John Clarke
  12. Project: Touchscreen Wide-range RCL Box by Tim Blythman
  13. Feature: Practically Speaking
  14. Feature: PIC n’Mix by Mike Hibbett
  15. Feature: AUDIO OUT by Jake Rothman
  16. Feature: Make it with Micromite by Phil Boyce
  17. Back Issues: Circuit Surgery by Jake Rothman
  18. Feature: Circuit Surgery by Ian Bell
  19. Feature: Max’s Cool Beans by Max the Magnificent
  20. Feature: Max’s Cool Beans cunning coding tips and tricks
  21. PCB Order Form
  22. Advertising Index

This is only a preview of the July 2021 issue of Practical Electronics.

You can view 0 of the 72 pages in the full issue.

Articles in this series:
  • (November 2020)
  • Techno Talk (December 2020)
  • Techno Talk (January 2021)
  • Techno Talk (February 2021)
  • Techno Talk (March 2021)
  • Techno Talk (April 2021)
  • Techno Talk (May 2021)
  • Techno Talk (June 2021)
  • Techno Talk (July 2021)
  • Techno Talk (August 2021)
  • Techno Talk (September 2021)
  • Techno Talk (October 2021)
  • Techno Talk (November 2021)
  • Techno Talk (December 2021)
  • Communing with nature (January 2022)
  • Should we be worried? (February 2022)
  • How resilient is your lifeline? (March 2022)
  • Go eco, get ethical! (April 2022)
  • From nano to bio (May 2022)
  • Positivity follows the gloom (June 2022)
  • Mixed menu (July 2022)
  • Time for a total rethink? (August 2022)
  • What’s in a name? (September 2022)
  • Forget leaves on the line! (October 2022)
  • Giant Boost for Batteries (December 2022)
  • Raudive Voices Revisited (January 2023)
  • A thousand words (February 2023)
  • It’s handover time (March 2023)
  • AI, Robots, Horticulture and Agriculture (April 2023)
  • Prophecy can be perplexing (May 2023)
  • Technology comes in different shapes and sizes (June 2023)
  • AI and robots – what could possibly go wrong? (July 2023)
  • How long until we’re all out of work? (August 2023)
  • We both have truths, are mine the same as yours? (September 2023)
  • Holy Spheres, Batman! (October 2023)
  • Where’s my pneumatic car? (November 2023)
  • Good grief! (December 2023)
  • Cheeky chiplets (January 2024)
  • Cheeky chiplets (February 2024)
  • The Wibbly-Wobbly World of Quantum (March 2024)
  • Techno Talk - Wait! What? Really? (April 2024)
  • Techno Talk - One step closer to a dystopian abyss? (May 2024)
  • Techno Talk - Program that! (June 2024)
  • Techno Talk (July 2024)
  • Techno Talk - That makes so much sense! (August 2024)
  • Techno Talk - I don’t want to be a Norbert... (September 2024)
  • Techno Talk - Sticking the landing (October 2024)
  • Techno Talk (November 2024)
  • Techno Talk (December 2024)
  • Techno Talk (January 2025)
  • Techno Talk (February 2025)
  • Techno Talk (March 2025)
  • Techno Talk (April 2025)
  • Techno Talk (May 2025)
  • Techno Talk (June 2025)
Max’s Cool Beans By Max the Magnificent Flashing LEDs and drooling engineers – Part 17 O ooh! I have something so tantalising tasty to talk about that I’m squirming in my seat in anticipation, but first we have one last experiment to perform, peruse, and ponder on my 12×12 array of ping-pong balls. Life, what can you do, eh? Just to make sure that we’re all tap-dancing to the same drumbeat, each of the ping-pong balls in my array is equipped with a tricolour LED. A couple of columns ago (PE, May 2021), we used the array to realise a first-pass implementation of Conway’s Game of Life (GOL). In my previous column (PE, June 2021), we enhanced our original program: first, to add a smooth fade between transitions, and then to use additional colours to reflect any intergenerational states (Fig.1). Before we proceed, it might be a good idea for you to take a look at the latest version of that program to refresh yourself as to how it performed its magic (file CB-June21-02.txt, which is available on the June 2021 page of the PE website at https://bit.ly/3oouhbl). Also, for your delectation and delight, I uploaded a video to YouTube showing all of this in action (https://bit.ly/3sXsHPr). The way we left things was to have two cell patterns, called ‘gliders’, that translate themselves across the grid over the course of multiple generations. Although this was reasonably effective, I wanted to see something a tad more interesting, so I decided to randomly seed the initial population of the array, let things evolve until nothing was changing, and then start the whole thing all over again with a new randomly generated population. There are a couple of considerations to contemplate here. The first was the approximate percentage of live cells with which we wish to populate the array. I started with two definitions: RAND_MAX, which I set to 100, and RAND_CUT, which I use as a cut-off value. Next, I created an InitializeUniverse() function that ‘walks’ through every row (indexed by yInd) and every column (indexed by xInd) in the array, performing the following actions: After a little experimentation, I discovered that making RAND_ CUT too small (say 15), which resulted in ~85% of the cells being alive in the seed population, caused all the cells to die in the next generation due to overpopulation. Similarly, making RAND_CUT too large (say 95), which resulted in only ~5% of the cells being alive in the seed population, typically caused all the cells to die within a few generations due to underpopulation. Eventually, I settled on a RAND_CUT value of 85, which resulted in ~15% of the cells starting off alive in the seed population. You can see the whole program by downloading file CB-Jul21-01.txt, which is available on the July 2021 page of the PE website. Now, observe the fact that my first-pass InitializeUniverse() function sets the values of the current (‘n’ for ‘now’) generation (nGenState) to be ALIVE or DEAD. Although this seemed to be a reasonably intuitive way to do things at first, there were some unintended consequences, including requiring us to employ our old DisplayCurrentGeneration() function, whose sole purpose was to display the seed generation, which seems a bit wasteful if you ask me. After a little thought, I modified the core of the InitializeUniverse() function to set the values of the next (n + 1) generation (xGenState) as opposed to the current generation as follows (see also file CB-Jul21-02.txt): tmpRand = random(0, RAND_MAX); if (tmpRand > RAND_CUT) Cells[yInd][xInd].xGenState = COMING_ALIVE; else Cells[yInd][xInd].xGenState = STAYING_DEAD; As well as allowing us to dump the DisplayCurrentGeneration() function, this also lets us make things look a little spiffier, because we start with all the cells dead (black), then the new seed generation first fades from black to cyan, and then from cyan to green, after which we allow the game to commence evolving. Finally, at the end of each run when all the cells have died, the array returns to all the pixels being black. int tmpRand = random(0, RAND_MAX); I captured a video showing all of this in action (https:// youtu.be/znyvsyVUITA). As we see, the first randomly seeded if (tmpRand > RAND_CUT) universe evolves over only a couple of generations before all Cells[yInd][xInd].nGenState = ALIVE; of the cells shrug off this mortal coil. Similarly, for the second else randomly seeded universe. However, the third random seed Cells[yInd][xInd].nGenState = DEAD; proved to be significantly more interesting, resulting in cell patterns that evolve over multiple generations before Time eventually settling into a simple ‘blinker’ oscillator with a period of two generations. D ead To be honest, I hadn’t considered what would happen L iv e if the system evolved to end up containing one or Stay i ng A l i v e more oscillators. My current code waits for things to C o mi ng A l i v e stop changing before re-initialising the universe, but having an oscillator pattern means that things never D y i ng stop changing. Just to complicate matters, different H al f w ay State G ener ati o n n G ener ati o n n+ 1 oscillators can have different periods, so what can we do to determine that we’ve evolved as far as we can go Fig.1. Representing Conway’s Game of Life intergenerational states. 62 Practical Electronics | July | 2021 Fig.2. The classic 7-segment LED display. and proceed to a new random seed? If you have any suggestions, this would be the perfect time for you to expound, explicate and elucidate. Sumptuous segments Until recently, if I’d heard the term ‘seven-segment display,’ my knee-jerk reaction would have been to think of LED-based devices that can be used to display the decimal digits 0 through 9 (Fig.2 and Fig.3a). These little scamps originated in the 1970s and remain with us to this day. When these little rascals first arrived on the scene, you could have any colour you wanted, so long as that colour was red. They quickly started to appear in all sorts of devices that were considered to be amazingly cool in those days of yore, such as 4-function electronic calculators and digital watches. Unfortunately, you couldn’t leave the display on because it would drain the battery, so you had to press a button on the side of the watch whenever you wished to check the time or flaunt your wrist-bound chronometer. Did I mention how cool these displays were considered to be back in the day? I feel like an honorary member of Monty Python’s Four Yorkshiremen sketch (https://bit.ly/3xFUYOb), but it’s true that you can tell the young people of today that these displays were the ‘bee’s knees,’ and they will think you are exaggerating... and they won’t believe you! In addition to decimal digits, 7-segment displays can also be used to represent hexadecimal values, although – in this case – the alpha characters are obliged to be presented as a mixture of uppercase and lowercase symbols: A, b, C, d, E, and F. Of course, adding more segments allows us to represent more characters with increased fidelity, so it wasn’t long before displays with 9, 14, and 16 segments started to appear on the scene (Fig.3b, Fig.3c, and Fig.3d, respectively), where the latter can be used to display all of the Arabic digits (‘0’ to ‘9’), the Latin Practical Electronics | July | 2021 To cut another long story short, Steve has created his own version of the 21-segment Victorian display board (Fig.5a) boasting 35 tricolour WS2812B-2020 LEDs (one each for the seven smaller segments and two each for the 14 (a) 7-Segment (b) 9-Segment (c) 14-Segment (d) 16-Segment larger segments). These boards are 50mm wide and 64mm tall. Furthermore, Steve designed a Fig.3. More and more display segments increases 3D printed shell that mounts on the range of characters that can be displayed. the face of the board to provide a 10mm separation between the LEDs letters (‘A’ to ‘Z’), and a large swath of and a diffuser attached to the front of punctuation and other symbols. the shell. Steve has shared his cunning creations Vaunting Victorians with yours truly, and both of us are in I saw a cartoon the other day where an the process of creating 10-character interviewer asks, ‘So, why do you want droolworthy displays, which – it has to become an editor?’ The interviewee to be said – look rather amazing, as I’m replies, ‘Well, to cut a long story short’ sure you will agree when you get to see (think about it). So, I’m going to cut a them in future columns. long story short. Two guys called Chris Barron and John Smout founded (and currently act as co-moderators) of a Taking control group called Smartsockets on Groups. Steve and your humble narrator have io (https://bit.ly/2PPnVGl). competitively created complementary The Smartsocket concept is for a WS2812 LED-based projects in the past. software and hardware system for Generally speaking, the ground rules for driving multi-segment alphanumeric these projects have been the same (eg, displays. Each digit is equipped with number, location and orientation of the its own simple PIC microcontroller. LEDs), but we’ve gone different ways Via simple ASCII-type instructions and with regard to the underlying hardware industry-standard protocols — coupled (in the form of the microcontroller with built-in fonts and transition effects development platforms we’ve used), — it is possible to use Smartsockets to the software (in the form of the LED produce arrays comprising many display libraries we’ve employed), and any devices of similar and different types. additional augmentations, like soundSome time ago, John discovered that processing strategies and suchlike. As a guy called George Lafayette Mason a result, not surprisingly, it’s proved filed a patent for 21-segment displays diffi cult, if not impossible, for us to in 1898. This patent was eventually share code and detailed design ideas. granted in 1901 (https://bit.ly/3gWHl7s). In the case of our Victorian displays, The original versions of these bodacious we’ve decided to use the same core beauties involved 21 small incandescent bulbs (one per segment), where the bulbs were controlled by a complicated electromechanical switch that could activate various groups of segments to represent different characters as required (Fig.4). After John became aware of this 21-segment concept, he decided to add a tricolour LED version to the Smartsockets portfolio, and this work continues apace. Great minds Although I love the Smartsocket concept, I’ve never been a PIC man myself. Also, rather than having a separate microcontroller for each digit, I tend to use a single microcontroller – like an Arduino – to control multiple displays. My chum Steve Manley is of like mind. ‘Great minds think alike,’ as they say (of course, they – whoever ‘they’ are – also say that ‘Fools seldom differ,’ but I’m sure they weren’t talking about us). Fig.4. Copy of an original 21-segment display patent from 1901. 63 Fig.5. LED board and 3D printed shell for 21-segment display: a) LED board (left); b) 3D printed shell (right). hardware, thereby allowing us to jointly work on the software together (I think that the ‘together’ in this sentence was redundant, but I don’t care). As part of this, we decided to create a control board that would not only satisfy the immediate needs of our 10-character displays in the present, but that will also be applicable to a wide range of other projects in the future. When it comes to microcontrollers, Steve is currently favoring the Teensy 3.2 from PJRC (https://bit.ly/3h5tifW). This boasts a 32-bit Arm Cortex-M4 running at 72MHz (it can be overclocked to 96MHz) with 256KB of Flash memory, 64KB of SRAM, and 2KB of EEPROM. Personally, I prefer a Teensy 3.6, which has more I/O pins and features a 32-bit Arm Cortex-M4F (ie, it has a floatingpoint unit (FPU)) running at 180MHz (it can be overclocked to 240MHz) with 1MB of Flash, 256KB of SRAM, and 4KB of EEPROM. As a compromise, we decided that our control board would support both, although only one at a time, of course. Next, we had a brain-stem-storming session regarding any relevant features and functionalities we’ve variously employed on previous projects. These include using a highly accurate realtime clock (RTC) chip to keep track of the date and time when power is removed from the system. Also, having a light-dependent resistor (LDR) that can be used to vary the brightness of the display depending on the level of ambient light. We also desire access to an audio input so that we can use sound to control the patterns being displayed. On one of our previous competitive projects, I used a line-in audio input in my design, while Steve used a microphone in his implementation, so we decided to support both options with our new board. Also, we’ve both used MSGEQ7 audio spectrum analyser chips in past projects (https://bit.ly/3h23QYv). More recently, Steve has been experimenting 64 Fig.6. Using a cheap-and-cheerful IR controller makes life much simpler. with a sophisticated audio codec chip coupled with the Teensy Audio Library (https://bit.ly/3tpnrEA), and we decided that Steve’s approach offers the best route for the future. With regard to controlling the system using pushbuttons, one of my earlier projects used a 3-button scheme while another employed a 6-button approach. For the purposes of our new control board, we compromised on a 5-button solution that Steve has evolved over a number of his recent projects. We can use the left, right, up, down, and ‘OK’ buttons to access menus, select modes and effects, and enter values (eg, date and time). Even better, one of Steve’s recent projects also had the ability to support a cheap-and-cheerful infrared (IR) controller (https://amzn. to/3b6iJ8x). In addition to left, right, up, down, and ‘OK’ buttons (Fig.6), this also has buttons for the numbers 0 to 9, which makes performing tasks like entering the date and time much quicker and easier, so we’ve decided to incorporate this capability into our new board. As part of this, we decided to add a Seeedunio XIAO from Seeed Studio (https://bit.ly/2QYem8v) to handle the IR control functions (Steve previously used an Adafruit Trinket for this purpose). While the XIAO is only the size of a regular postage stamp, it packs a punch with a 32-bit Arm Cortex-M0+ running at 48MHz with 256KB of Flash and 32KB of SRAM. In reality, we could probably have handled the IR control functions using the main Teensy, but sometimes it’s easier to employ a ‘divide and conquer’ approach. Also, although the XIAO is total overkill for use as an IR controller, it’s extremely cheap and – like the Teensy microcontrollers – can be programmed using the Arduino’s integrated development environment (IDE). Plus, it’s always useful to have spare compute capability available in case one needs it in the future. Based on all of the above, along with a raft of other considerations, Steve has designed an amazingly cool board that will serve us well for many projects to come (Fig.7). At the time of this writing, we have no plans to make this control board available as a product – nor are we going to sell the Victorian displays themselves – all of this is just a hobby project. On the other hand, I will be sharing some of the nitty-gritty details in my Cool Beans columns because you may find them useful for your own projects. Also, some extremely exciting news is that we’ve just designed a special SMAD (Steve and Max’s Awesome Display) board with 45 low-current tricolour LEDs that can be driven by a regular Arduino. This board can be used to prototype the sort of special effects we’ll be using on our Victorian displays, and we will be making it available for purchase via the PE store (all will be Fig.7. The control board that will drive our 10-character, 21-segment displays. Practical Electronics | July | 2021 revealed in my next Cool Beans column in PE, August 2021). Some nitty-gritty details In the short time remaining to us in this column, let’s take a brief stroll around the control board to peruse and ponder particular points of interest. On the left-hand side we see a Teensy 3.6 plugged into some headers. This can be removed and replaced with a Teensy 3.2 if required. On the right-hand side we see the XIAO, which is also plugged into some headers, and which will be used to process the incoming signals from the IR controller. Just behind the Teensy are two potentiometers, which can be used to adjust the brightness of the display and its audio sensitivity (or anything else we program them to do). Just in front of the Teensy is a coin-cell battery to keep the RTC running when power is removed from the system. With regard to the RTC, in earlier projects I’ve used the ultra-precise ChronoDot breakout board (BOB) from Adafruit (https://bit.ly/3tkCHml). Meanwhile, Steve has been using the DS3231 integrated circuit (IC) on his custom boards. The DS3231 is a lowcost, extremely accurate I2C RTC with an integrated temperature-compensated crystal oscillator (TCXO) and crystal. By some strange quirk of fate, this is the same chip that’s used on the ChronoDot. The DS3231 and any other surfacemount ICs are presented on the bottom side of the board and so are not visible in Fig.7. These ICs include an SGTL5000 low-power stereo audio codec from NXP, an LS119 switch debounce IC from LogiSwitch, and an SN74HCT245 octal bus transceiver acting as a voltage-level shifter from Texas Instruments. Observe the five control buttons that are located in the middle-right of the board. It’s also possible to connect five more case-mounted buttons in parallel via the green screw block connectors. Above the middle button is the LDR and an electret microphone; below the middle button we see the IR detector. The way the board has been designed, most of its features and functions, such as the IR control, the RTC and the audio codec are optional. Also, as opposed to soldering components like the microphone, LDR and IR detector directly onto the board, these can be mounted remotely and connected via the green screw-block terminals. The header pins to the right of the Teensy grant access to any uncommitted microcontroller pins. The header pins to the lower-right of the coin-cell battery allow additional I2C-enabled sensors and other devices to be connected to the board. Finally, observe the 8×3 cluster of header pins to the lower left of the coin cell battery. These are presented as eight groups, each consisting of 5V, 0V and a data signal that can be used to drive WS2812 tricolour LEDs. The SN74HCT245 discussed earlier is used to convert the 3.3V outputs from the Teensy to the 5V signals required to drive the LEDs. The reason for using this octal buffer is that the Teensy is capable of driving eight strands of LEDs simultaneously. We will be delving deeper into this capability in my next Cool Beans column. In the meantime, as always, I welcome any and all 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 Teach-In 8 CD-ROM Exploring the Arduino This CD-ROM version of the exciting and popular Teach-In 8 series has been designed for electronics enthusiasts who want to get to grips with the inexpensive, immensely popular Arduino microcontroller, as well as coding enthusiasts who want to explore hardware and interfacing. Teach-In 8 provides a one-stop source of ideas and practical information. The Arduino offers a remarkably effective platform for developing a huge variety of projects; from operating a set of Christmas tree lights to remotely controlling a robotic vehicle wirelessly or via the Internet. Teach-In 8 is based around a series of practical projects with plenty of information for customisation. The projects can be combined together in many different ways in order to build more complex systems that can be used to solve a wide variety of home automation and environmental monitoring problems. The series includes topics such as RF technology, wireless networking and remote web access. PLUS: PICs and the PICkit 3 – A beginners guide The CD-ROM also includes a bonus – an extra 12-part series based around the popular PIC microcontroller, explaining how to build PIC-based systems. EE FR -ROM CD ELECTRONICS TEACH-IN 8 £8.99 FREE CD-ROM SOFTWARE FOR THE TEACH-IN 8 SERIES FROM THE PUBLISHERS OF INTRODUCING THE ARDUINO • Hardware – learn about components and circuits • Programming – powerful integrated development system • Microcontrollers – understand control operations • Communications – connect to PCs and other Arduinos PLUS... PIC n’MIX PICs and the PICkit 3 - A beginners guide. The why and how to build PIC-based projects Teach In 8 Cover.indd 1 04/04/2017 12:24 PRICE £8.99 Includes P&P to UK if ordered direct from us SOFTWARE The CD-ROM contains the software for both the Teach-In 8 and PICkit 3 series. ORDER YOUR COPY TODAY! JUST CALL 01202 880299 OR VISIT www.epemag.com Practical Electronics | July | 2021 65