Silicon ChipMax’s Cool Beans - April 2024 SILICON CHIP
  1. Contents: FLOWCODE
  2. Subscriptions
  3. Back Issues
  4. Publisher's Letter: Welcome to the future
  5. Feature: Techno Talk - Wait! What? Really? by Max the Magnificent
  6. Feature: Net Work by Alan Winstanley
  7. Project: Basic RF Signal Generator by Charles Kosina
  8. Project: Swiss Army Knife by Richard Palmer
  9. Project: Silicon Chirp - the pet cricket by John Clarke
  10. Project: Teach-In 2024 by Mike Tooley
  11. Feature: Circuit Surgery by Ian Bell
  12. Feature: Max’s Cool Beans by Max the Magnificent
  13. Project: AUDIO OUT by Jake Rothman
  14. PartShop: Peak Test Instruments
  15. Advertising Index: Peak Test Instruments
  16. Back Issues

This is only a preview of the April 2024 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)
Articles in this series:
  • Win a Microchip Explorer 8 Development Kit (April 2024)
  • Net Work (May 2024)
  • Net Work (June 2024)
  • Net Work (July 2024)
  • Net Work (August 2024)
  • Net Work (September 2024)
  • Net Work (October 2024)
  • Net Work (November 2024)
  • Net Work (December 2024)
  • Net Work (January 2025)
  • Net Work (February 2025)
  • Net Work (March 2025)
  • Net Work (April 2025)
Articles in this series:
  • Teach-In 2024 (April 2024)
  • Teach-In 2024 (May 2024)
  • Teach-In 2024 – Learn electronics with the ESP32 (June 2024)
  • Teach-In 2024 – Learn electronics with the ESP32 (July 2024)
  • Teach-In 2024 – Learn electronics with the ESP32 (August 2024)
  • Teach-In 2024 – Learn electronics with the ESP32 (September 2024)
  • Teach-In 2024 – Learn electronics with the ESP32 (October 2024)
  • Teach-In 2024 – Learn electronics with the ESP32 (November 2024)
Articles in this series:
  • Circuit Surgery (April 2024)
  • STEWART OF READING (April 2024)
  • Circuit Surgery (May 2024)
  • Circuit Surgery (June 2024)
  • Circuit Surgery (July 2024)
  • Circuit Surgery (August 2024)
  • Circuit Surgery (September 2024)
  • Circuit Surgery (October 2024)
  • Circuit Surgery (November 2024)
  • Circuit Surgery (December 2024)
  • Circuit Surgery (January 2025)
  • Circuit Surgery (February 2025)
  • Circuit Surgery (March 2025)
  • Circuit Surgery (April 2025)
  • Circuit Surgery (May 2025)
  • Circuit Surgery (June 2025)
Articles in this series:
  • Max’s Cool Beans (April 2024)
  • Max’s Cool Beans (May 2024)
  • Max’s Cool Beans (June 2024)
  • Max’s Cool Beans (July 2024)
  • Max’s Cool Beans (August 2024)
  • Max’s Cool Beans (September 2024)
  • Max’s Cool Beans (October 2024)
  • Max’s Cool Beans (November 2024)
  • Max’s Cool Beans (December 2024)
Articles in this series:
  • Audio Out (January 2024)
  • Audio Out (February 2024)
  • AUDIO OUT (April 2024)
  • Audio Out (May 2024)
  • Audio Out (June 2024)
  • Audio Out (July 2024)
  • Audio Out (August 2024)
  • Audio Out (September 2024)
  • Audio Out (October 2024)
  • Audio Out (March 2025)
  • Audio Out (April 2025)
  • Audio Out (May 2025)
  • Audio Out (June 2025)
Articles in this series:
  • Circuit Surgery (April 2024)
  • STEWART OF READING (April 2024)
  • Circuit Surgery (May 2024)
  • Circuit Surgery (June 2024)
  • Circuit Surgery (July 2024)
  • Circuit Surgery (August 2024)
  • Circuit Surgery (September 2024)
  • Circuit Surgery (October 2024)
  • Circuit Surgery (November 2024)
  • Circuit Surgery (December 2024)
  • Circuit Surgery (January 2025)
  • Circuit Surgery (February 2025)
  • Circuit Surgery (March 2025)
  • Circuit Surgery (April 2025)
  • Circuit Surgery (May 2025)
  • Circuit Surgery (June 2025)
Max’s Cool Beans Arduino Bootcamp – Part 16 Way back in the mists of time we used to call Part 14 (PE, February 2024), we commenced with me complementing you on your perspicacious and sagacious appearance, after which I invited you to sa something nicethe aboutMagnificent me. By Max Well, a reader we will call Ron (because that’s his name) rose to the challenge. Ron just emailed me say: You look great in that Hawaiian shirt, and I love the way you digress loquaciously with verbosity circumlocution when talking about things of an electronic nature. Well done, Ron. Although I don’t li to boast (I’m known far and wide for priding myself on my humility), I must admit that I take some satisfaction with respect to the garrulity and circuitousness of my humble scribblings. Arduino Bootcamp – Part 16 W ay back in the mists of time we used to call Part 14 (PE, February 2024), we commenced with me complementing you on your perspicacious and sagacious appearance, after which I invited you to say something nice about me. Well, a reader we will call Ron (because that’s his name) rose to the challenge. Ron just emailed me to say: You look great in that Hawaiian shirt, and I love the way you digress loquaciously with verbosity and circumlocution when talking about things of an electronic nature. Well done, Ron. Although I don’t like to boast (I’m known far and wide for priding myself on my humility), I must admit that I take some satisfaction with respect to the garrulity and circuitousness of my humble scribblings. Do you know the time? In our previous column, we added a DS3231 real-time clock (RTC) to our spiffy new dual-breadboard setup. The great thing about an RTC is that its backup battery allows it to remember the time when power is removed – either accidentally or intentionally – from the main system. Just to remind ourselves of where we’re at, you can download an image of our current hardware setup (file CB-Apr24-01.pdf). As usual, all the files mentioned in this column are available from the April 2024 page of the PE website: https://bit.ly/pe-downloads Next, we created two small programs (or ‘sketches’ in the vernacular of the Arduino). The first loaded the RTC Fig.1. Checking the baud rate in the Serial Monitor. 56 Do you know the time? with current datewe and time. The real-time office) to transfer 10 characters In ourthe previous column, added a DS3231 clock (RTC) data to ouratspiffy new dual-breadboard second looped reading theisdate second. The UART the Arduino setup. The greataround thing about an RTC that its per backup battery allows it toinremember the time when and time from the– RTC displaying Uno supports ofsystem. 300, 600, 750, power is removed eitherand accidentally or intentionally – fromvalues the main these values in the Serial Monitor. If 1200, 2400, 4800, 9600, 19200, 31250, you’ve forgotten what this program looks 38400, 57600 and more.of our current hardware set Just to remind ourselves of where we’re at, you can download an image like, you can download a copy now The default for the is 9600 (file CB-Apr24-01.pdf). As usual, all the files mentioned in this column Arduino are available from the April 20 (file CB-Apr24-02.txt). baud. We can dictate the baud rate used page of the PE website: https://bit.ly/pe-downloads I don’t know about you, but I’ve been by our program by specifying its value jolly busy recently, paddling up a creek in the Serial.begin() function. And Next, we created two small programs (or ‘sketches’ in the vernacular of the Arduino). The first loade without a paddle (or a creek), up to my we can specify the value used by the the RTC with the current date and time. The second looped around reading the date and time from t armpits in alligators (I never metaphor Serial Monitor by clicking the downRTC and displaying these values in the Serial Monitor. If you’ve forgotten what this program looks lik I didn’t like), and running around in pointing arrow next to the baud rate you can downloadcircles a copyshouting, now (file CB-Apr24-02.txt). ever-decreasing ‘Don’t value in the interface (Fig.1). Panic!’ As a result, I haven’t played with In our previous column, we decided I don’t know about beenLet’s jolly busy paddling upusing a creek without a paddle (or a my prototype sinceyou, lastbut weI’ve spoke. torecently, speed things up by 57600 baud. creek), up to my armpits in alligators (I never metaphor I didn’t like), and running around all power up our Arduinos and fire up However, I commenced this current in everdecreasing circles shouting, ‘Don’t Panic!’ As a result, I by haven’t played our programs together. Are you ready? session updating mywith IDEmy to prototype the latest since last w spoke. Let’s allthree… power up our Arduinos and fireversion. up our programs together. Are you One… two… Go! I’m assuming it was thisready? that One… two three… Hmm.Go! Is your Serial Monitor displaying reset the Serial Monitor in my IDE weird and wonderful characters back to 9600 baud. This resulted in a Hmm. Is your Serial displaying weird and characters something the following something like theMonitor following? fewwonderful seconds of gnashing of teethlike and rending of garb before I realised what 7t)LT)L�’T)L�7t)L�#t... was going on. As soon as I’d set the correct baud ratedate in my monitor, then I started If so,although although may accurately If so, thisthis may accurately represent the andserial time somewhere in the multi-universe, it to seewe the date and time wasthing to do i represent the date andhere timeon somewhere to satisfy requirements planet Earth. When see something like values this, theI first expecting, liketothe in the that multi-universe, fails‘communication to satisfy check the baud rateit(think speed’) in looking the Serialsomething Monitor is set the same valu following requirements on to planet Earth. When we’ve used in here the call the Serial.begin() functionlines: in our program. Sometimes the Arduino’s we see something like this, the first thing integrated development environment (IDE) remembers the last value we used in the Serial Monitor… 2024/2/10 (Saturday) 10:24:18 to dosometimes is check that the baud rate (think and it doesn’t. 2024/2/10 (Saturday) 10:24:21 ‘communication speed’) in the Serial 2024/2/10 (Saturday) 10:24:24 Monitor is set to the same value we’ve The Arduino uses a universal asynchronous receiver/transmitter (UART) function to communicate w 2024/2/10 (Saturday) 10:24:27 used in the call to the Serial.begin() the host computer. This is a very simple interface in which both the data format and transmission : transmit and receive in both directions (both e function our program. Sometimes speeds arein configurable. It requires only two wires to etc. the Arduino’s integrated development also require a connection to ground). environment (IDE) remembers the last I feel like shouting, ‘It’s alive! It’s alive!’ value we used in the Serial Monitor… Note that these values are updated every and sometimes it doesn’t. three seconds because we’ve included a The Arduino uses a universal three second (3000 millisecond) delay at asynchronous receiver/transmitter the end of the loop() function in our (UART) function to communicate program. (Try changing this to 1000 and with the host computer. This is a very observe that your display now updates simple interface in which both the each second.) data format and transmission speeds are configurable. It requires only two Drifting along wires to transmit and receive in both I’m sorry. I drifted off there for a moment. directions (both ends also require a There’s something hypnotic about connection to ground). watching this series of date and time There are a variety of ‘standard’ baud values appearing on one’s screen. But rates used for serial communications wait! Do the minutes values in your implemented using UART protocols. Serial Monitor fail to precisely match Many of these are historical in nature. the time displayed in the menu bar of For example, 110 baud was used by ASR your host computer? 33 Teletype machines (like the one in my Practical Electronics | April | 2024 Don’t freak out if there is a small discrepancy. One source of any potential difference is associated with the way in which we loaded the time and date into our RTC in the first place. The technique we used in our first program was to set the RTC to the date and time at which the program was compiled. This took place prior to uploading it into the Arduino and using it to initialise the RTC, all of which took time. Another source of error is that RTCs aren’t perfect and they’re subject to drift. The DS3231 we’re using is phenomenally accurate in the scheme of things. If you look at its data sheet – available at: https://bit.ly/42CloQS – you’ll see this little scamp has a specified accuracy of ±2ppm (parts per million) over a temperature range of 0°C to +40°C. This means a worst-case drift of 2 seconds for every million seconds. Since there are 60 x 60 x 24 x 365 = 31,536,000 seconds in a year (assuming we aren’t in a leap year), then this equates to a worst-case drift of ~0.2 seconds a day, ~1 second a week, or ~1 minute a year. One final potential source of error may depend on whether you purchased a real DS3231 that was manufactured by Maxim Integrated, which is a subsidiary of the American multinational semiconductor company Analog Devices, or whether you acquired a cheaper Chinese ‘knock-off,’ which may or may not be up to par. One of the things we will be talking about at some stage in the future is adding a few pushbutton switches to our prototype and using them to implement a menu system that will allow us to do things like setting the date and time by hand, but that’s a discussion for another day because we currently have other poisson à frire (fish to fry). people (not you, of course) think there are no surprises to be uncovered. Let’s see, shall we? In the case of a 24-hour clock, the day runs from midnight to midnight and is divided into 24 hours, which are numbered from 0 to 23. This scheme may be referred to as ‘military time’ in the US and parts of Canada, ‘continental time’ in the UK, and ‘railway time’ in other parts of the world. By comparison, in the case of a 12-hour clock, the 24 hours of the day are divided into two 12-hour periods designated as a.m. (from the Latin ante meridiem, meaning ‘before midday’) and p.m. (from the Latin post meridiem, meaning ‘after midday’). The 12 hours in each period are numbered: 12 (which, amusingly, acts as 0), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 and 11. Surprisingly, there is no widely accepted convention for how midday and midnight should be represented. However, in English-speaking countries, 12 a.m. means 12 o’clock midnight, while 12 p.m. indicates 12 o’clock noon. One 7-segment display (sad face) As you will doubtless recall, we currently have only a single 7-segment display at our disposal (sad face). This wasn’t an issue with our first experiments in which we wished to display only the ten digits 0 through 9. Later, when we came to experiment with our ultrasonic sensor (PE, February 2024), we decided to present distances on our display, where these distances were measured in centimetres using values between 0 and 99. As part of this, we elected to always employ two digits in the form 00, 01, 02… 97, 98, 99. As we said at that time: If we call our most-significant and least-significant digits MSD and LSD, respectively, and if we think of ‘…’ as indicating a pause, then a first-pass view would be to display MSD … LSD … … … MSD … LSD … … …, and so forth. Well, we now want to display the hours and minutes portions of the date and time values returned from our RTC. For our purposes, each of these values will involve two digits, which we can think of as HH:MM for hours and minutes. This means we have four digits to display. If we refer to the most-significant and least-significant hour and minute digits as H-MSD, H-LSD, M-MSD, and M-LSD, respectively, then one approach would be to display: H-MSD … H-LSD … … … M-MSD … M-LSD … … … … … … … … … H-MSD … H-LSD … … … M-MSD … M-LSD – and so forth. To put this another way, we will display the H-MSD and H-LSD digits with a short pause between them, wait for a mediumsized pause, display the M-MSD and M-LSD digits with a short pause between them, wait for a longer pause, and then do everything all over again, and again, and… you get the idea. Decisions, decisions… Now it’s time for us to make a choice. Do we want to display time in a 24-hour or 12-hour clock format? We all use digital clocks in one form or another myriad times each day, typically without thinking about things too deeply, so I bet most Practical Electronics | April | 2024 Listing 3a. Displaying hours and minutes in 24-hour format. 57 Let’s start by implementing the 24hour clock system, which is the flavor our DS3231 RTC uses by default. In this case, each day officially begins in the middle of the night (a.k.a. midnight) at 00:00. A value of 12:00 occurs only at noon (ie, the middle of the day, a.k.a. midday). The last minute of the day begins at 23:59 and ends at 24:00, which is identical to 00:00 of the following day. This means our HH values will span 00 to 23, while our MM values will span 00 to 59. 24-hour clock What we are going to do is to take the program that we discussed earlier (file CB-Apr24-02.txt) which displays the date and time from the RTC, plus take the program we used to display the 2-digit values from the ultrasonic sensor (file CB-Feb24-03.txt from PE, February 2024). Then we are going to munge and merge these little rascals together, add a sprinkle of programming magic, and ‘Bob’s your uncle’ (or aunt, depending on your family dynamic). I just did this and it works like a charm. But before you look at my solution, why don’t you have a bash yourself? One ‘word to the wise’ is to remember to change the Arduino pin assignments to our PinSegs[] variable to be {9, 8, 7, 6, 5, 4, 3, 2} to match our new breadboard layout. We discussed this in our previous column, but it’s easy to forget this sort of thing (as I just discovered to my cost). Once you have your own solution up and running, you can then compare it to mine (file CB-Apr24-03.txt). Since we’ve already seen most of this program before, we’ll just look at the loop() function here (Listing 3a). Note that I’ve created three definitions, SML_PAUSE, MED_PAUSE, and BIG_PAUSE to which I’ve assigned values of 150, 450, and 1350 (milliseconds), respectively. I made each delay three-times the length of its predecessor because… that’s just the sort of fellow I am. You can tweak these values to your heart’s content Listing 4a. Converting to 12-hour format. 58 to settle on what’s most pleasing to your eye. The first thing we do on Lines 60 and 61 is declare four variables of type byte. We’re going to use these to store the segments associated with our H-MSD, H-LSD, M-MSD, and M-LSD digits. On Line 63 we declare two variables of type int (integer) called hour and minute. (I’ll leave the mystery of what we are going to store in these to your imagination.) As we discussed in last month’s column, the RTC library we are using declares a new data type called DateTime. This is a structure containing multiple members whose values we can access using full-stop/period ‘.’ delimiters (we introduced enumerated types, structures and type definitions in PE, December 2020). On Line 65, we declare a variable of type DateTime called now, to which we assign the values returned from a call to the rtc.now() function. On Lines 67 and 68 we copy the hours and minutes values out of our now variable into our hours and minutes variables (as we’ll see, doing things this way will make our lives much easier when we come to implementing a 12-hour format). As a reminder, our DigitSegs[] array contains the segments associated with the digits we wish to present on the 7-segment display. The way we’ve set things up, DigitSegs[0] contains the segments associated with the number 0, DigitSegs[1] contains the segments associated with the number 1, and so on. Remember that, if we have a number between 0 and 99, then dividing it by 10 using the division operator ‘/’ will return the most significant digit, while dividing it by 10 using the modulus operator ‘%’ will return the least-significant digit. This is what we are doing on Lines 70 through 73 to determine which segments we wish to light up to display our most-significant and least-significant hour and minute values. After this, it’s easy-peasy-lemonsqueezy to present the 4-digit sequence on our display, with each pair of digits being separated (ie, all segments turned off) by appropriate delays. 12-hour clock A lot of people find it difficult to wrap their brains around the 24-hour clock format and they much prefer to use its 12-hour counterpart. As fate would have it, the DS3231 can run in either 24-hour mode (the default) or 12-hour mode. If you look at the DS3231’s data sheet, you will see that bit 6 of the hours register is defined as the 12-hour or 24-hour mode select bit. Alternatively, we can take the default 24-hour format returned from the DS3231 and convert it into a 12-hour form ourselves. Which approach do you think we should use? I agree – let’s do it ourselves. The easiest way to start out here is to take a step back and think about what we want to do (not surprisingly, this approach works well for most problems). The hours values returned by the DS3231 running in 24-hour mode are numbered 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23. If we wish to present time in a 12-hour format, we need to convert these values to be 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11. Well, that seems easy enough. If the hours value returned from the RTC is 0, we need to change our version to 12. Alternatively, if the hours value returned from the RTC is greater than 12, we need to subtract 12 from this value. I just made this modification to my program (file CB-Apr24-04.txt). As we see in Listing 4a, the only difference between our previous program and our new version is the addition of a simple conversion routine on Lines 71 through 74. Remember that the ‘-=‘ operator used on Line 74 is known as a compound operator. The following two lines have the same functionality: hour –= 12; hour = hour – 12; We introduced the concept of compound operators quite some time ago (PE, March 2022). I know they can look a little ‘tricky’ when you are starting out. However, they do allow us to concisely capture what we are trying to do, and – after a while – you’ll find it becomes easier to parse and process expressions using compound operators than their expanded versions. The more you capture code, the more you will grow to love compound operators (trust me, have I ever lied to you before?). As one final thought before we proceed, if we are displaying time in a 12-hour format, we could use the decimal point (DP) segment on our 7-segment display to indicate if the time is a.m. (DP = Off) or p.m. (DP = ON). Personally, I’m usually aware of whether it’s the morning, afternoon, or evening, so this would be superfluous to requirements. However, this may be of interest for those who are temporally challenged. We will return to consider this further (by which I mean using the DP to indicate a.m. or p.m.; not people who have a tortuous grasp on time) in our next column. Two 7-segment displays (happy face) I’ve said it before, and I’ll say it again, when it comes to tedious, tiresome and turgid music, you’d have to go a long Practical Electronics | April | 2024 Adding more current-limiting resistors The first thing I want you to do is return to the illustration showing our full prototype as it currently stands (file CB-Apr24-01.pdf). In the following discussions, any references to wire colours reflect those I’ve used in my illustrations, your wire colours may vary depending on what you have available and what you decide to use. We’re going to leave the green and blue wires connecting the Arduino to our RTC on the lower breadboard as-is. In the case of the eight orange wires connecting the Arduino to one side of the 150Ω (brown-green-brown) current-limiting resistors on the upper breadboard, I want you to leave the ends plugged into the Arduino as-is, but unplug the ends connected to the breadboard. In the fullness of time, we are going to deploy four 7-segment displays, which we will call D0, D1, D2 and D3. Currently, only D0 is installed on our breadboard. Our existing eight current-limiting resistors are connected to the eight segments on D0 by the eight purple wires. Now, I want you to add eight more 150Ω resistors along with eight blue wires on the right-hand side of the upper breadboard, as illustrated in Fig.2. Talking about the colour choices for our wires just reminded me of a time when not everyone had colour televisions and BBC snooker commentator Ted Lowe famously said something along the lines of: ‘He’s going for the pink, and for those of you watching in black and white, the pink is next to the green.’ Hopefully you are not reading a black-and-white photocopy of this issue of PE. Practical Electronics | April | 2024 D1, 7, A D1, 6, B D1, 4, C D1, 2, D D1, 1, E D1, 9, F D1, 10, G D1, 5, DP 10 9 8 7 6 D0, 7, A D0, 6, B D0, 4, C D0, 2, D D0, 1, E D0, 9, F D0, 10, G D0, 5, DP 1 2 3 4 5 D3 DO NOT ADD THIS WIRE ! D1 D0 Display segments way to find anything worse than One (commonly known for its opening line ‘One is the loneliest number you’ll ever do’) as covered by Three Dog Night in 1969. Defying all possibility, the second line is even worse than the first: ‘Two can be as bad as one, it’s the loneliest number since the number one’ (I mean, come on, give me a break!). Well, we are here to refute the premise of this second line, because we are going to add a second 7-segment display to our breadboard (happy face). Was that a squeaky squeal of excitement I just heard? (Yes, it was, but I just realised that it was me). Display number Fig.2. Adding eight more current-limiting resistors and wires. Wot? Not enough pins? For our purposes here, we are going to ignore the fact that the Arduino Uno’s six analogue pins A0 through A5 can also be used as digital input/output (I/O) pins. This is because we’ve been using our analogue pins for other tasks – like reading the value of a potentiometer (PE, November 2023) or reading the value from a light-dependent resistor (LDR) to measure the level of ambient light (PE, December 2023). No one knows what the future holds, but there’s more than a betting chance we might wish to add these types of functionalities into a future incarnation of our clock. Also, as discussed in our previous column, analogue pins A4 and A5 are no longer available to us because we are using them to provide I2C communication with our RTC. So, this is where we run into a problem. The Arduino Uno has only 14 digital input/output (I/O) pins numbered from 0 to 13. We can’t use pins 0 and 1 (well, we can, but we’re not going to) because these are used to implement any UART conversations with our host computer. Examples of these communications are when the host computer programs the Arduino, or when our programs send messages to the host computer using Serial.print() function calls. This means we have only 12 digital I/O pins at our disposal. Thus far, we’ve been using eight of these pins (2 through 9) to drive the eight segments on our 7-segment display (remember, the decimal point counts as a segment in its own right). This means we have only four digital I/O pins (10 through 13) remaining that are available to us. But wait, there’s more. Although we aren’t doing so presently, in the past we’ve used our four free digital pins Display pin numbers Display segments Display number Display pin numbers D0, 7, A D0, 6, B D0, 4, C D0, 2, D D0, 1, E D0, 9, F D0, 10, G D0, 5, DP 5V and 0V from lower breadboard D1, 7, A D1, 6, B D1, 4, C D1, 2, D D1, 1, E D1, 9, F D1, 10, G D1, 5, DP Adding and connecting the second display The next step is to add a second 7-segment display to the left-hand side of the upper breadboard, as illustrated in Fig.3. Once you’ve inserted this display, connect the blue wires coming from our new set of current-limiting resistors. Now, this part is important. Observe the black wire shown as connecting pin 3 of display D0 to ground (0V). I want you to remove this wire but remember it for a thought experiment we are poised to perform. Similarly, observe the black wire shown as connecting pin 3 of display D1 to ground. Do not add this wire but – once again – remember it for the thought experiment to which we are racing (try not to lose your breath). REMOVE THIS WIRE ! Fig.3. Adding and connecting the second 7-segment display (D1). 59 This is easy to do in practice (it’s also easy to mess up if you From Current-Limiting Resistors aren’t paying attention), but it’s <at>#$%^ difficult to draw as – once again – I just discovered to my cost. The thing is that, to make things understandable in my illustrations, D1 D0 I don’t want any of these wires to cross each other. When I was a kid, my dad drew three boxes on a piece of paper and said they represented three houses. Then he drew three circles on the same piece of paper and said they BC 377 represented three utility companies (gas, water and electricity). He told E 3 1C me that my goal was to use lines 2B to connect each house with each utility company without any of the lines crossing over. He promised me this was possible (I’m sure he had his fingers crossed behind his back when he said this). This kept me occupied for days, so – as 9 8 7 6 5 4 3 2 G ND 5V From Arduino 11 10 far as dad was concerned – it was From Arduino ‘mission accomplished.’ Just for giggles and grins, Fig.4. Reconnecting the Arduino. Fig.5. Adding two transistors. I created a drawing showing the resistors in the upper breadboard and the wires from to implement tasks like driving our piezoelectric buzzer (PE, the Arduino plugged into the lower breadboard – see file December 2023 and January 2024) and communicating with CB-Apr24-05.pdf. Why don’t you download this, print it out, our ultrasonic sensor (PE, February 2024). Once again, we and try adding the requisite wires without any of them crossing. may wish to add these types of functionalities into a future Once you’ve finished, compare your version to mine (Fig.4). incarnation of our clock. Yes, I’m afraid that is a somewhat self-satisfied smirk you So, ignoring any potential additional functionalities for see plastered on my visage. I must admit that I’m rather the moment, now that we’ve added our second display, we proud of this implementation. have 16 segments to drive and only 12 pins to drive them with, which presents us with a bit of a poser… Lower Breadboard Lower Breadboard Reconnecting the Arduino As a first step, I want you to connect the free ends of the orange wires coming from the Arduino to free rows of terminal strips on the lower breadboard. Next, I want you to add more orange wires such that each signal from the Arduino drives the same segment on both displays. For example, we want pin 2 on the Arduino to be connected to the free ends of the current-limiting resistors driving the A segments on both the D0 and D1 displays, pin 3 on the Arduino to be connected to the free ends of the currentlimiting resistors driving the B segments on both the D0 and D1 displays, and so forth. Upper Breadboard T o Display D 0 Upper Breadboard T o Display D 1 Components from Part 1 LEDs (assorted colours) https://amzn.to/3E7VAQE Resistors (assorted values) https://amzn.to/3O4RvBt Solderless breadboard https://amzn.to/3O2L3e8 Multicore jumper wires (male-male) https://amzn.to/3O4hnxk Components from Part 2 7-segment display(s) https://amzn.to/3Afm8yu Components from Part 5 Momentary pushbutton switches https://amzn.to/3Tk7Q87 Components from Part 6 Online resources For the purposes of this series, I’m going to assume that you are already familiar with fundamental concepts like voltage, current and resistance. If not, you might want to start by perusing and pondering a short series of articles I penned on these very topics – see: https://bit.ly/3EguiJh Similarly, I’ll assume you are no stranger to solderless breadboards. Having said this, even if you’ve used these little scamps before, there are some aspects to them that can trap the unwary, so may I suggest you feast your orbs on a column I wrote just for you – see: https://bit.ly/3NZ70uF Last, but not least, you will find a treasure trove of resources at the Arduino.cc website, including example programs and reference documentation. 60 Passive piezoelectric buzzer https://amzn.to/3KmxjcX Components for Part 9 SW-18010P vibration switch https://bit.ly/46SfDA4 Components for Part 10 Breadboard mounting trimpots https://bit.ly/3QAuz04 Components for Part 12 Light-Dependent Resistor https://bit.ly/3S2430m Components for Part 13 BC337 NPN Transistor https://bit.ly/40xAgyS Components for Part 14 HC-SR04 Ultrasonic Sensor https://bit.ly/49AMBq4 Components for Part 15 Real-Time Clock (RTC) https://bit.ly/3S9OjHl Practical Electronics | April | 2024 What would happen if… This is where we arrive at the thought experiment we discussed earlier. Suppose our displays were to be wired up as shown in Fig.3. That is, with the two black wires connecting pin 3 on each display to ground. What would happen if we started to run one of our old programs that repeatedly counts from 0 to 9 while driving the corresponding segments on the 7-segment displays? Well, two things would occur. First, since our two displays are wired in parallel (side by side), the same value would be presented on each display, which isn’t tremendously useful to us in the scheme of things. Second, since we are using 150Ω current-limiting resistors, each segment will be drawing 20mA of current when it’s turned on (we discussed this in excruciating detail in PE, February 2023). As we now have two displays in parallel, this means the Arduino pins driving our displays will have to source 2 x 20mA = 40mA of current. They can do this… but not for long… especially if a lot of them are doing it at the same time. One solution to our 40mA problem would be to double the values of our current-limiting resistors to 300Ω, thereby halving the current flowing through each segment to 10mA. However, in addition to reducing the brightness of the displays, this wouldn’t help us with the fact that both displays are presenting the same values. Another, much more promising solution is… Adding two transistors Do you remember when we used a BC377 transistor to vary the brightness of a single 7-segment display (PE, January 2024)? In that case, we turned the transistor on and off very quickly, and we varied the ratio between it being on and off to vary the brightness of the display. Well, we are going to do something similar here. In this case, however, we are going to use two transistors to ensure that only one display is on at any time. In addition to limiting the current to a single display at a time, this will also allow us to present different values on each display. So, after first ensuring that there are no black wires connecting pin 3 on each display to ground (Fig.3), we are going to add two BC377 transistors, two resistors and two control wires coming from the Arduino (Fig.5). For your delectation and delight, you can download an image of our latest and greatest hardware setup including all the changes we’ve discussed in this column (file CB-Apr24-06.pdf). Next time In our next column, we are going to use our dual displays to first display the hours (HH) and then the minutes (MM), after which we will start to consider how we might further boost our clock to employ four 7-segment displays (be still my beating heart)! In the meantime, I think it would be a good idea for you to start performing your own experiments with our current dual display setup – just make sure that you only ever have one of our transistors turned on at a time! 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 EE FR -ROM CD ELECTRONICS TEACH-IN 8 FREE CD-ROM SOFTWARE FOR THE TEACH-IN 8 SERIES FROM THE PUBLISHERS OF 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. £8.99 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 | April | 2024 61