Silicon ChipRaspberry Pi Clock Radio, Pt2 - February 2024 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Check your backups
  4. Feature: Computer Storage Systems, Pt1 by Dr David Maddison
  5. Project: Microphone Preamplifier by Phil Prosser
  6. Project: Mains Power-Up Sequencer, Pt1 by John Clarke
  7. Review: ESP32-CAM WiFi Camera Module by Tim Blythman
  8. Feature: Electronic Markets in Singapore by Tim Blythman
  9. Project: Raspberry Pi Clock Radio, Pt2 by Stefan Keller-Tuberg
  10. Project: Model Railway Points Controller by Les Kerr
  11. Serviceman's Log: The things we do for our pets by Dave Thompson
  12. Product Showcase
  13. PartShop
  14. Vintage Radio: STC Radiotym model 5160 by Associate Professor Graham Parslow
  15. Market Centre
  16. Advertising Index
  17. Outer Back Cover

This is only a preview of the February 2024 issue of Silicon Chip.

You can view 36 of the 112 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Articles in this series:
  • Computer Storage Systems, Pt1 (February 2024)
  • Computer Storage Systems, Pt1 (February 2024)
  • Computer Storage Systems, Pt2 (March 2024)
  • Flowcode (March 2024)
  • Computer Storage Systems, Pt2 (March 2024)
  • Flowcode (March 2024)
Items relevant to "Microphone Preamplifier":
  • Microphone Preamplifier full PCB [01110231] (AUD $7.50)
  • Microphone Preamplifier embedded PCB [01110232] (AUD $7.50)
  • Model Railway Points Controller receiver PCB [09101242] (AUD $2.50)
  • Microphone Preamplifier short-form kit (Component, AUD $70.00)
  • Microphone Preamplifier PCB patterns (PDF download) [10108231/2] (Free)
  • Panel label and drilling diagrams for the Microphone Preamplifier (Panel Artwork, Free)
Items relevant to "Mains Power-Up Sequencer, Pt1":
  • Mains Power-Up Sequencer PCB [10108231] (AUD $15.00)
  • Firmware (ASM and HEX) files for the Mains Power-Up Sequencer (Software, Free)
  • Mains Power-Up Sequencer PCB pattern (PDF download) [10108231] (Free)
  • Panel labels and cutting diagrams for the Mains Power-Up Sequencer (Panel Artwork, Free)
  • PIC16F1459-I/P programmed for the Mains Power-Up Sequencer (1010823A.HEX) (Programmed Microcontroller, AUD $10.00)
Articles in this series:
  • Mains Power-Up Sequencer, Pt1 (February 2024)
  • Mains Power-Up Sequencer, Pt1 (February 2024)
  • Mains Power-Up Sequencer, Pt2 (March 2024)
  • Mains Power-Up Sequencer, Pt2 (March 2024)
  • New use for Mains Sequencer (July 2024)
  • New use for Mains Sequencer (July 2024)
  • Mains Power-Up Sequencer, part one (February 2025)
  • Mains Power-Up Sequencer, part one (February 2025)
  • Mains Power-Up Sequencer, part two (March 2025)
  • Mains Power-Up Sequencer, part two (March 2025)
Items relevant to "ESP32-CAM WiFi Camera Module":
  • Software download package for the ESP32-CAM module review (Free)
Items relevant to "Raspberry Pi Clock Radio, Pt2":
  • Raspberry Pi Clock Radio main PCB [19101241] (AUD $12.50)
  • Raspberry Pi Clock Radio display PCB [19101242] (AUD $7.50)
  • Software for the Raspberry Pi based Clock Radio (Free)
  • Raspberry Pi Clock Radio PCB patterns (PDF download) [19101241-2] (Free)
Articles in this series:
  • Raspberry Pi Clock Radio, Pt1 (January 2024)
  • Raspberry Pi Clock Radio, Pt1 (January 2024)
  • Raspberry Pi Clock Radio, Pt2 (February 2024)
  • Raspberry Pi Clock Radio, Pt2 (February 2024)
  • Raspberry Pi-based Clock Radio, part two (January 2025)
  • Raspberry Pi-based Clock Radio, part two (January 2025)
Items relevant to "Model Railway Points Controller":
  • Model Railway Points Controller transmitter PCB [09101241] (AUD $5.00)
  • PIC16F1455-I/P programmed for the Model Railway Points Sequencer transmitter (0910124A.HEX) (Programmed Microcontroller, AUD $10.00)
  • PIC16F1455-I/P programmed for the Model Railway Points Sequencer receiver (0910124B.HEX) (Programmed Microcontroller, AUD $10.00)
  • Firmware for the Model Railway Points Controller (0910124A/B.HEX) (Software, Free)
  • Model Railway Points Controller PCB patterns (PDF download) (09101241-2) (Free)

Purchase a printed copy of this issue for $12.50.

Raspberry Pi Clock Radio As described last month, this new Clock Radio can also act as a media player and has many alarm options to ensure you wake up at the right time and in the manner you prefer. You can even synchronise the alarms on multiple Clock Radios. Since we’ve already explained how it works, this article will cover construction and how to use it. Part 2 by Stefan Keller-Tuberg T he major functions of the Clock Radio are handled by a Raspberry Pi (model 2, 3, 4, Zero W or Zero 2W). However, we need to add some extra hardware for the time LED display, buttons, switches, audio amplifier to drive the speakers and so on. This additional hardware is hosted on two custom PCBs that mount at right angles to each other, with a series of soldered fillets between them. The construction process will therefore be to mount the components on these two boards, join them together, wire them up to the Raspberry Pi (via a ribbon cable with IDC connectors) and then mount that assembly in the case. Once it’s in the case, it can be wired to all the external switches, connectors etc. The software will function regardless of which bits of additional hardware are connected, so any parts you 72 Silicon Chip don’t need can be left off the PCB without needing to modify the software. For example, if you don’t want the seconds digits, you don’t need to fit that two-digit LED display. Construction We suggest you start by fitting the SMD components to the Display board. This is built on a 150 × 44mm PCB coded 19101242; its overlay diagram is shown in Fig.4. Fit the 48 current-limiting resistors; if you are unsure how well the brightness will match between the larger and smaller displays, you can start by fitting just the 32 resistors associated with the 0.8-inch displays. Either way, it’s easier to solder them in groups. If you’re using different 3mm LEDs than the two options in the parts list, leave the two 1.3kW colon LED series Australia's electronics magazine resistors out for now; otherwise, add them at this stage. It’s easier to solder surface mount components by applying flux to the PCB before positioning the component. When all SMD resistors are soldered, you can clean off the residual flux with isopropyl alcohol, methylated spirits or a specific flux residue cleaner. Stubborn areas can be cleaned with a toothbrush or lint-free cloth. Do this before installing the other components, as you don’t want flux residue to be transferred onto the optical surfaces. Cleaning the board once through-hole parts have been fitted is also much harder. Move on to the 7-segment displays. Make sure you have a clean work surface, as it’s easiest to do this with the front of the displays resting on it. Mount the two 0.8-inch displays on the opposite side of the PCB than the resistors, with their decimal points towards the edge connections. Solder two opposite corner pins first, so you can adjust the displays to be tight against the PCB and nicely horizontal. When you are satisfied with that, solder the remaining two corner pins before completing the others. The 0.56-inch display has a lower profile than the others, so mount it proud of the PCB by a few millimetres to keep its front face in the same plane as the others. Insert the smaller display into its holes, check that it is correctly oriented with the decimal points towards the edge connector and then turn the whole assembly face down onto a flat surface. Press down on the assembly to ensure that the two larger displays are hard against the bench, and you will see that the legs of the 0.56-inch display barely protrude through the PCB. Solder two of its opposite corners as before, then inspect. You can use a straight edge, such as a ruler, to ensure that the front faces of all three displays are aligned in the same plane, adjusting the small one if required until you are satisfied. Then solder the remaining pins as before. Insert the 3mm LEDs into the gap between the larger displays. The cathodes (the shorter leg) are towards the edge connector. Again, place the assembly face-down onto a flat surface and solder one leg only on each 3mm LED. Adjust their angles and heights until you are happy before soldering the other leads. siliconchip.com.au Fig.4: the display board has three 7-segment displays, two colon LEDs and an LDR on the front, while the currentlimiting SMD resistors are on the back. It’s easiest to fit the resistors first, but see the comments in the text about possibly needing to change some of their values depending on which LED displays you use. The two resistors marked with a red arrow can be changed to test the colon LED and the brightness of the small 7-segment display. Fit the LDR next. The procedure is similar to the 3mm LEDs, but the LDR orientation doesn’t matter. Main board assembly The main board is coded 19101241 and measures 150 × 83mm. Fig.5 is its overlay diagram. Before fitting the components, it is worthwhile to verify that the supply rails have not been inadvertently shorted during the PCB fabrication process. Using a multimeter, check for an open circuit between pins 10 and 20 of the 74HCT374 (the diagonally opposite pins) and between pins 8 and 16 of the 74HC139 next to it (also diagonally opposite). It is rare, but if either is shorted, you just saved yourself a headache trying to find an almost impossible-to-find problem after the board is assembled! Start with the surface-mounting amplifier IC (IC13), carefully installing it with the correct orientation. Pin 1 on the chip is marked with a dot or divot and on the PCB silkscreen. Apply flux to the PCB and then position the chip. Solder just one corner pin first and then check that all of the pins align with their pads and the chip is moreor-less centred over the pad area. If not, soften the solder and nudge the chip until it’s properly aligned. When you’re happy, dab solder on the opposite corner and recheck the orientation. Solder the remaining two corner pins before completing the rest. siliconchip.com.au Clean up any bridges with solder wick, then remove any residual flux as you did with the display board. Continue by fitting the throughhole components, beginning with the lowest profile devices. Install the three diodes (watching their cathode stripe polarity) and the resistors, then the IC sockets (notched ends towards the bottom or right), followed by the ceramic or MKT capacitors, except the 100nF capacitor near the top edge of the board. Mount the electrolytic capacitors next, with their longer (positive) lead towards the + symbols. The striped side of the can is negative. Solder the relay next, followed by the transistors from shortest to tallest, except Q2, ensuring they face as shown in Fig.5. Don’t install chips into their sockets just yet, we will do that once the two boards have been joined. You can fit CON5 and the 40-pin header that will go to the Raspberry Pi now, but leave off the polarised headers around the board’s edge. That will give you reasonable access so you can join the two boards. Joining the boards If you’ve never assembled two boards using solder joints at right angles, a little planning will simplify the task. Ideally, the two boards should be aligned close to a right angle, but an error of a degree or two either way will not make much difference. I found that the easiest way to join the boards was to raise the main board above the bench using four PCB standoffs. Using a plastic right angle or similar, carefully tape the main and display boards individually to the right angle, as shown in the photo shown overleaf. Overvoltage protection can trip with poorly regulated supplies One of the 5V plugpacks I pulled from my box of spares measured 5.45V with no load. I figured this plugpack would be OK because the Clock’s protection circuit kicks in at around 5.65V – well above the supply’s no-load output. However, when I actually connected the plugpack, nine times out of ten, I could see the Pi LEDs flash briefly before turning off, a sign that the clock’s protection circuit had kicked in. An oscilloscope revealed that this dodgy plugpack was not very well regulated; at the moment a load was applied, the plugpack’s voltage would fluctuate enough to trigger the protection. I found a simple workaround with a spare 10,000μF electrolytic screwed into the terminals of the clock’s power connector, which smoothed that dodgy plugpack’s ripple enough not to reach the protection-tripping threshold. I have not had this happen with any of my other 5V plugpacks, so we recommend not using a dodgy plugpack in the first place. Australia's electronics magazine February 2024  73 Fig.5: the components on the main board are nearly all throughhole parts. The solder pads along the top of this board will connect to those along the bottom of the display board later. When assembling this PCB, watch the orientations of the ICs, transistors (including Mosfets and the SCR), diodes and electrolytic capacitors. Ensure that the display board evenly overhangs the solder side edge of the main PCB by about one millimetre for the entire length of the mating edge. The slight overhang is so you can add solder beads to the pads on either side of the main board, as there are electrical connections on both sides. That also provides extra mechanical strength. Solder the first joint on the left end of the mating edge, then the one at the right end. For these first two joints, only solder the top side of the main board. This will be fragile, but it allows you to check and easily adjust the alignment of the display board with the main board. If the alignment is imperfect, soften one joint at a time, alternating from one to the other, and make a sequence of minor adjustments until you’re happy. When satisfied, add another three or four solder joints spaced out along the top side to secure it, then flip the assembly over and work on the other side. Solder the opposite ends to shore up the mechanical strength, then solder all the remaining connections. Finally, flip it back over and finalise the original side. The boards will now be very firmly bonded, and you can remove the right angle. Complete the electronics by adding Mosfet Q2, the 100nF capacitor in the top-right corner of the main board and all the polarised headers. clock board can be made from scratch, or you can use an old IDE hard drive cable if you have one. To make it from scratch, carefully position an IDC crimp connector within a vice’s jaws and protect it using small timber offcuts. When you slide the 40-conductor cable into the connector, be careful to align it at right angles. It is easy to accidentally crimp the connector at an angle, in which case the cable probably won’t work. As you tighten the vice, you’ll hear the two ends of the crimp connector click into place, at which point you should ease off the pressure. Old IDE cables can be used for this application, but if the old cable supports two IDE drives, cut off one end of the cable using a Stanley knife. Before you do, double-check that the two crimp connectors have all 40 holes open; some IDE cables have one blocked hole, and those won’t be any good for this project. Next, you need a cable with a 3.5mm stereo plug on one end and a 3-pin polarised header plug on the other. I cut the end off an old 3.5mm headphone cable, stripped back the insulation and crimped the wires to the header pins. I then applied some flux paste, dab-soldered the signal wires and shield, then inserted the pins into their housing. Final assembly The 40-conductor ribbon cable for connecting the Raspberry Pi to the 74 Silicon Chip I found that raising the display board was helpful when joining it to the main PCB. The boards can then be taped together and soldered on both sides. Australia's electronics magazine siliconchip.com.au Because headphone conductors are fragile, I used a sparing amount of hot glue to neatly encapsulate the top of the housing, the loose conductors and the end of the headphone cable. This provides some strain relief; you could also use neutral-cure silicone sealant. Double-check the orientation of the transistors, diodes and electrolytic capacitors on the main board. When happy, carefully install the socketed ICs, noting their orientations & types, and ensuring all pins have correctly entered the sockets. The three chassis-mounting momentary pushbuttons (S2-S4) connect to the main PCB via two-way cables terminated in polarised header plugs, so solder the wires to them and crimp/ solder the plugs on the other end. Similarly, prepare three centre-off momentary toggle switches with three-way cables (that could be stripped from ribbon cable) terminated in three-way polarised header plugs. The banana sockets/binding posts for the speakers (two positive and two negative) are wired to another two polarised header plugs, this time with slightly heavier-duty wire. However, it can’t be too thick, or you won’t be able to get it into the plugs. Medium-duty hookup wire should work. Wire one red and one black terminal to each plug. The polarity doesn’t matter as long as it’s the same for both. For the external 5V supply, solder wires to the chassis socket and then screw them into the pluggable terminal. The positive input should be on the right when plugged into the PCB. If adding a radio receiver input, its audio output goes to a three-way polarised header plug that follows the same arrangement as for the Pi audio input. The GND connection is closest to the relay and the left and right channels sequentially on the other two pins. If your audio source is mono, short the left and right inputs and feed them from the mono source. Connect its power supply to CON5 as per one of the options in Fig.3 last month. Testing the Clock We recommend installing the clock software onto the Raspberry Pi (if you haven’t already) and ensuring the software works before testing the hardware, as explained last month. Commence hardware testing by repeating the earlier multimeter test to verify that the power supply rails are not shorted. The rails will not be completely open-circuit now because there are capacitors and ICs on board, but the rails should not be dead shorted either. You can test the overvoltage protection circuit if you have a current-­ limited bench supply. If you don’t, we recommend you don’t test it and assume it works because if you apply a high voltage and it doesn’t work, you will fry everything. If you have the bench supply, the test procedure is as follows. Use a voltmeter to accurately measure the applied voltage directly at the variable power supply (if it has an onboard meter, you can use that). Tenths of a When connecting the Raspberry Pi to the Clock Radio, take extra care that the polarity is correct on the ribbon cable, it should be connected as shown. siliconchip.com.au Australia's electronics magazine volt make a difference, so it is important that the voltmeter is accurate and measures to at least 100mV resolution! Use another voltmeter to monitor the voltage between the 0V power input on the board and the tab of Mosfet Q1. Starting low, ramp up the variable power supply to around 4.5V, then slow down. As the input approaches 5V, minimal voltage should be registered on the second voltmeter at the tab of Q1, indicating that the Mosfet is switched on, its default during regular operation. Continue slowly increasing the variable power supply so that its output rises just above 5V. The protection threshold voltage will depend upon the ambient temperature and idiosyncratic characteristics of the 5.1V zener diode and the SCR. When the variable input voltage reaches 5.6-5.8V (certainly below 6.0V), a voltage should develop on the Mosfet’s tab, indicating that Q1 has switched off. Don’t wind the variable power supply past 5.85V! If the SCR has not fired by 5.85V, switch off and look for a problem in the protection components above and to the right of RLY1. When satisfied that Q1 is switching off as expected around 5.6-5.8V and before powering down the variable supply, verify that the voltage across the 2.7kW resistor is about the same as the variable supply output, confirming that the SCR has fired. Finishing the wiring Now you can plug everything into the main board. That includes the buttons, switches, the audio cable from the Pi’s output jack socket to the threepin polarised header on our board, the external 5V supply, the speaker terminals and the optional radio board. Also connect the Raspberry Pi via the ribbon cable, being very careful to get its polarity right. Refer to the adjacent photo and Fig.6 to see how it’s done. Pin 1 of the Pi must be wired to the bottom-left pin of the header on the main board; use a DMM set on continuity mode to verify that before applying power. When you apply power to the assembly now, do it via the clock board only and don’t connect a separate power supply to the Pi. The Pi will receive its power via the clock assembly through the ribbon cable. When power is first applied to the February 2024  75 whole assembly, the display will start blank, and the Pi will go through its booting process. You should see the Pi’s power LED turn on as the Pi boots, but the clock display will remain blank for around half a minute. When the display eventually illuminates, it will show an incorrect time. The Raspberry Pi will be trying to connect to your home network, and when it does, it will grab the current time from the internet. The display will then jump to the correct time and will be time-locked from that moment onward. If the 7-segment displays remain blank, double-check the LED brightness and threshold settings on the web setup page. It’s possible that they have been dimmed very low and just need to be brightened. Otherwise, use ssh (eg, via PuTTY) to connect to the Pi and use the alarm clock debugging modes described in the software installation documentation to check the software’s health. The Pi installation script should have been run to completion without errors. If not, that might be a clue as to why it isn’t working. If the display is still not illuminated, but the software appears to be running, use a logic probe, oscilloscope or frequency counter to check that there is activity on the data and address bus GPIO lines between the two boards and on the PWM GPIO line to the gate of Mosfet Q2. Also check that you have used the correct Mosfet types (they must handle logic-level drive). Matching display LED brightnesses If you have not yet installed current-­ limiting resistors for the two colon (“:”) LEDs or the small display, you can start to experiment. Turn off the clock and tack-solder candidate resistors for just one each. Segments within an individual display will have the same brightness, so once you’ve matched one to the rest, that resistor value should work throughout. It is easier to use axial leaded resistors rather than SMDs for these experiments unless you have a sample book of suitable SMD resistors. Start with the default values of 430W for the display and 1.3kW for the colon or 470W/1.2kW if you don’t have those other values. A convenient resistor to choose for the small display is the top one closest to the larger digits because it illuminates a segment alongside the larger displays, making it easier to compare. Both colon resistors are convenient to access. Refer to the two resistors marked with a red arrow in Fig.4. Power on the Pi, go to the web setup page and put the clock hardware into a darkened room. Adjust the minimum brightness slider down to a level where the illuminated LED segments are just visible, then set the maximum brightness slider to midrange. Remember to save the setting using the web save button, or the next step won’t work as expected. Choose the “Start the LED brightness test” web button to turn every LED on (displaying all 8s) and force the display to the minimum brightness setting for a moment. You’ll have to judge whether the test segment and the test colon LED are the same, brighter or dimmer than the large numeric digits. The test will also go to maximum brightness for a moment for comparison. If the brightnesses aren’t even, increase the test resistance to reduce Given the height of the enclosure we recommend, it’s best to mount the Raspberry Pi as shown, so there’s enough clearance. Note that the slim radio board I added down the left-hand side, with its antenna passing through a small hole in the rear panel. Fig.6 (right): the wiring diagram for the Raspberry Pi Clock Radio. 76 siliconchip.com.au the LED brightness or decrease the resistance to make it brighter. Always power down the clock before changing resistor values, as accidentally shorting out the current limiting resistor pads can cook your 7-segment display. As you try different valued resistors, make step changes of about 25% in value, as you won’t notice too much difference when trying smaller steps. For example, change from 430W to 560W to reduce the brightness or from 430W to 360W to increase it. After determining the optimal resistances, you can source and install components for all the missing current limiting resistors, and your clock will be complete. If you don’t want to wait, you could order 16 each of the values 360W, 430W, 560W, 750W and 1kW, as it’s likely one of those will give a good match. Don’t go lower than 360W to avoid exceeding the 74HCT4511 package current limit. Testing The proper functioning of each switch is most easily tested by enabling one of the software debug modes to generate a debug log. Do this siliconchip.com.au A close-up showing the headphone cable connection to the Raspberry Pi. in an SSH session; as described in the software installation documentation, the command is “sudo alarm-clock -B”. As you press each button in the switch debug mode, a message will be logged, making it obvious that it is working. Assuming the LED displays are illuminated, if you cup your hand over the LDR (shielding its sides and the front surface) to reduce the light intake, you should see the display dim after a few seconds. LDRs can be rather sensitive to light, and the actual dimming behaviour will depend on what you’ve configured in the Clock settings. You can use the command “sudo Australia's electronics magazine alarm-clock -X” to watch as the software measures the light level. You can verify that the numbers are smaller when the LDR is dark and become larger as the LDR is illuminated more. Suppose you see this behaviour in the debug log, and there is a reasonable variation in the range between light and dark (for example, 500 counts or more). In that case, the circuit is working sufficiently well for you to be able to adjust the web sliders to achieve your desired dimming behaviour. Use the “Start the display test” button on the web setup page to exercise each seven-segment display and February 2024  77 dots. If some LED segments never illuminate, check that the series current-­ limiting resistors are adequately soldered and that the legs of the 74HCT4511 chips are all correctly inserted into their sockets. If just one of the six digits doesn’t count in the correct sequence, the problem is likely with the associated 74HCT4511. If several of the six digits count incorrectly in the same way, check for problems with the GPIOs used for the data and address bus or potentially with the 40-conductor ribbon cable. The last functions to test are the amplifier and audio inputs. Turn on the amplifier using the media player to stream local media or an internet radio site and verify that you’re getting sound from the Raspberry Pi. If your speakers are dead, plug headphones directly into the Pi to confirm that it is generating audio; if so, you’ll need to debug the amplifier section of the clock. Back on the media player web page, if you type “radio” (without the quotes) rather than entering a path to a media file or URL, you should hear the relay click, and the audio will be taken from the radio input connector. The middle pin of CON5 will be pulled to ground via Q3 when the relay is energised so the radio module will be powered. Putting it into a case You will probably want to mount the clock into an instrument case, as I did with mine. You probably shouldn’t use a metal case for this project because it will interfere too much with the Raspberry Pi’s WiFi and Bluetooth reception. If you’re capable of doing woodwork, I once saw a very cool clock idea that would turn this project into a talking piece. Timber veneer can be translucent if you shine a bright light through it from directly behind. The brightness of the clock’s LEDs can be set quite high, especially the Lumex components, and they should shine clearly through a sheet of 0.4mm or thinner light-toned veneer. You’d want to make yourself an MDF template for the front panel, possibly routing the top edge to round it off and drilling and filing out tightly fitting holes for the seven-segment displays. Mounting the front plane of the seven-segment displays immediately behind the veneer will provide mechanical backing to protect the veneer. You would also need to drill a window for the LDR or mount the LDR elsewhere in the box. I’d love to see photos of this idea if it works as well as I expect. If you choose the more conventional approach and use the plastic instrument case, I used a table saw and the finest toothed blade to cut a 3mm green Perspex sheet to the correct size to replace the front panel. Because the front panel mounting slot is 2mm wide, I firmly taped and then routed the edges of the Perspex so they fitted snugly. 2mm Perspex/acrylic is available, but I’m unsure if you can get the translucent green colour in that thickness. If you feel it’s necessary, you could mask and spray the inside of the Perspex bezel black so that only the displays show through, but I have not done this for my clocks and think they look fine. I mounted my snooze button on the top of the case and all other buttons and switches, speaker posts and the power socket onto the rear panel that came with the case. If you use the recommended While we used a Raspberry Pi model 4 to run our Clock Radio, you can also a model 2, 3, Zero W or Zero 2W. 78 Silicon Chip Australia's electronics magazine instrument case which is 160mm deep, note that the clock board assembly with mounted LEDs amounts to just under 100mm of depth, and the shorter dimension of a Raspberry Pi is 56mm, not accounting for the 3.5mm audio plug and cable which protrude further. That means there isn’t enough room to mount the Pi in the base behind the main board. I mounted the Pi partially overhanging the main board, as shown in the photo on page 76. To raise it above the main board, you can use two long M3 screws through the base of the case, secured with a nut, and M3 standoffs fitted onto the tops of the long screws secured with weak Loctite (eg, 222). Two short M3 screws will hold the Pi onto the M3 standoffs, while the two remaining Pi screw holes overhang the main board and are left vacant. It provides quite a solid mounting, provided you don’t try to insert or remove the Pi’s 40-pin expansion cable while the Pi is screwed down at only two points. I found it sturdier to elevate the Pi using the moulded standoffs in the base of the instrument case, but the hole spacing wasn’t quite right. I elongated one mounting hole to align with the Pi holes and secured the long screws with washers, nuts and Loctite 222. Then with four standoffs attached to the main board and the perspex bezel in position, I carefully positioned the PCB and epoxied the standoffs to the instrument case, saving me the hassle of precisely measuring hole locations and drilling. With the specified instrument case, there is still just enough room to squeeze a small radio board down one side if you’d like to include that option (as I did). To fit larger radio boards, you might need a larger case. The case configuration I adopted has no external access to the USB or Ethernet ports. That wasn’t a significant consideration for me, but if your case is sufficiently deep, you can rotate the Pi so that its network and USB ports are accessible through the back panel. In that case, you’ll need to fold the 40 conductor ribbon into an L-shape to facilitate the connection between the main board and the Pi. I specified a 150mm ribbon cable length and have successfully used that length with some of my prototypes. Shorter ribbons will be OK, but if you need to use a longer ribbon in yours, siliconchip.com.au be watchful for any problems when the LED display gets updated. Suppose you see digit update errors when using a longer ribbon. In that case, you can slow down the settling and latching delay from its current default of 5μs by editing the “alarm_ clock.c” source code file and changing the #defined symbol called WRITE_ BYTE_DELAY to something larger than 5000 (nanoseconds). The microprocessor on the Raspberry Pi consumes 1W, so expect the outside surface of the case in the vicinity of the Pi to be warmer than the room’s ambient temperature. That should not be a concern, but you could add some ventilation to the case if you want to keep it cooler. Using the software The Clock Radio is designed to be intuitive once you’ve logged into the web interface, with plenty of help links to guide you. Still, if you want to tinker with it ‘under the bonnet’ or fully understand how it works, you’ll want more details on how the software works. We’ll start with some of the more common features that most constructors will be interested in, then move on to the nitty-gritty of how the software works. Configuring the Clock via the web interface To reach the web interface, open a browser and go to http://clock.local or whatever system name or IP address you used to SSH into the Clock. You will be greeted by the Clock’s home page, which contains links to the various configuration and media player functions, a summary of the configured alarms, the playlist if media is currently playing, and a list of any other clocks found on the local network if any exist – see Screen 1. Screen 1 shows other clocks that have been discovered on the network. If you only have one Clock, that boxed section will not be displayed. Navigation should be reasonably intuitive. Use the Clock Setup page to configure your preferences. When you hover the pointer over some options, the browser will display hints and a description. Creating alarms is a matter of filling in details from top to bottom on the Alarm Configuration page (Screen 2): what time, how long do you want it siliconchip.com.au Using the Clock as a Bluetooth speaker Raspberry Pi models after the Pi 2 allow the Clock Radio to emulate Bluetooth speakers. Computers, phones and tablets can be paired with the Clock to play audio through its speakers. After ‘pairing’, devices only need to be ‘connected’ whenever you’d like to stream audio via the Clock’s speakers. A “Pair Bluetooth Device” icon on the Clock’s web page allows devices to ‘discover’ it for pairing; you can also enable this mode by simultaneously pressing two of the clock’s physical alarm selection switches. When activated, you’ll have three minutes to complete pairing. You can pair as many devices with the Clock as you’d like. The devices to be paired need to be in pairing/discovery mode at the same time, or they won’t see each other; you’ll need to carefully follow the documented pairing and connection process for your device. If you have difficulties pairing with the clock and are new to this process, confirm the procedure by pairing with something else. When your device is connected, audio will be played through the Clock’s speakers. Set the volume using either the physical volume up/down switch on the Clock or a slider on its web page. Bluetooth audio stutters The clock’s Bluetooth streaming has been tested with Windows, macOS, Android phones and iPhones, and it has worked well using either the Pi 3 or the Pi 4. However, there are certain circumstances where you might notice occasional audio stutter and Bluetooth disconnections. The most obvious situation is when connected Bluetooth devices move beyond their working range. A less obvious reason for Bluetooth stuttering is WiFi interference, as explained in the panel last month. Therefore, you could experience audio stuttering if you access a Pi 3 based Clock’s web interface at the same time as you’re streaming Bluetooth audio to it. Bluetooth channel assignment is typically statically allocated during the pairing process. If your Bluetooth channel experiences interference, you can try resetting pairing and starting over. There is a button on the web interface to reset all paired devices. Suppose you are streaming Bluetooth audio when you start a media player stream on the clock, including when an alarm plays a media source other than the radio. In that case, the clock will disconnect the Bluetooth devices to play the media stream correctly. You will need to reconnect your Bluetooth device afterwards if you wish to continue streaming Bluetooth audio. The finished Clock Radio connected to an iPad via Bluetooth. Australia's electronics magazine February 2024  79 adjustment is applied when the alarm first trips. Each minute after that, the digital volume control will make one step towards the target volume until it is reached (or the next chained alarm trips). So, to gently increase volume when an alarm is tripped, you could set the volume adjustment to -15 and the target adjustment to +0. The alarm will start quietly and gradually get louder until it reaches the normal (system) level. The volume adjustments are added to the current system-wide volume setting! Adjusting the alarm(s) Screen 1: the main web page shows the list of alarms and other Clock Radios on the network (if present). The buttons at the top are hopefully self-explanatory. Clicking on the link outlined in red provides information on what the six buttons/switches on the Clock Radio do. They can be used in combination, so quite a few functions are available. to run, on what days of the week and should it recur indefinitely. The alarm volume adjustment is relative to the current master volume, which is useful when chaining a sequence of alarms from different sources (where each source could have different audio levels). It can also be used to slowly increase or decrease volume with a succession of alarms. Anywhere you see a text box for entering media, you can specify a streaming radio site URL, the full Linux path to a media file or playlist, or the word “radio” (without quotes) to use the external audio input. The path to media files on USB storage devices will normally start with “/media/”. Finding internet streaming sources is easy; any internet radio station that is accessible in your country and that can be listened to with a web browser will work with the Clock. However, determining the correct URL to use with the Clock can be tricky. Instructions on how to use a browser to discover the syntax for a streaming URL are included on the Clock’s in-built web pages (also see Screen 2). Chaining alarms As I live in regional Australia, the national radio network I usually listen to inserts news bulletins from the nearest capital city. Sometimes, your ISP can allocate an IP address from 80 Silicon Chip further afield or the internet’s routing changes, resulting in you hearing news bulletins from a completely different part of the country. I realised I could use ‘chained alarms’ to work around this. When the hour ticks over and the local news commences, I configure a new alarm with its streaming media source being a local news radio station. I configured a new alarm to switch back to the original national stream after the news. The chaining trick works well, and I’ve been enjoying local news by flipping streaming sources for several months. When you chain alarms into a sequence, and a subsequent alarm trips before the timer for the earlier alarm has expired, the earlier alarm is replaced by the subsequent alarm. It will not come back even if the subsequent alarm completes. To return the first streaming source, you must chain a third alarm. Waking up gently You can use alarm chaining to be woken ‘gently’ by setting the volume adjustment low on the initial alarm, then chaining a series of subsequent alarms with progressively increasing volume. But there’s a better way to achieve the same thing. Each alarm includes a “target adjustment” setting as well as the “volume adjustment” setting. The volume Australia's electronics magazine Whenever you adjust the system-­ wide volume, the volume of all future alarms will adjust accordingly, as if you rotated the volume control knob on your traditional alarm clock and waited for the next alarm to trip. If you’ve specified any non-zero volume adjustments for any alarm, those adjustments will be applied to the current system-wide volume to maintain the volume relativity. The Clock Setup page has a “minimum alarm volume” setting. That ensures your alarms will still be loud enough to wake you if you’ve set a low system-wide volume. Alarm-specific adjustments still apply to the minimum alarm volume to maintain relativity between different alarm levels and to ensure that adjustments continue to work as you expect. However, you won’t be able to accidentally set the system-wide volume low and then sleep through an alarm. I therefore strongly recommend you check and adjust this setting during setup. Using the buttons Although there are only six buttons, they can be used in combination with each other, so you can do more with the buttons than you might think. The full description of button operation is provided in a link you will find on the Clock’s internal web page, in Screen 1. Because all functions can be reached via the web interface, it is not strictly necessary to build any or all of the buttons into the Clock. The choice is yours! 12/24 hour time display The setup web page includes a configuration option for choosing between 12-hour and 24-hour displays. This siliconchip.com.au refers to the LED display on the Clock itself, not how times are shown on the web pages. Times displayed in most web browsers are formatted according to the locale setting on the device running the web browser. That means that although you may have configured one particular format on the web settings screen, your browser might steadfastly show a different format. Automatically resuming playlists If internet streaming is not your thing, you can use a playlist of MP3 files from your own media library for your alarm. You can even chain alarms between your local playlist, the radio and internet streams. When you initially create an alarm and specify a directory as an alarm source, the Clock’s web server will build a playlist file of the underlying directory tree. Similarly, a playlist is created if you use the media player function and specify a directory. When playing a playlist, the Clock remembers the last track and will commence from the following track when it uses the same playlist again. You can therefore chain from the playlist to the news and back again, and the playlist will continue from the track after where it left off. Testing the hardware When testing the hardware to ensure the switches are being recognised and ambient light levels are correctly measured, you’ll need to use the Clock’s software debugging mode to view the debugging log. This means you’ll need to temporarily stop the operating system from managing the Clock. By default, the “alarm-clock” program runs automatically at boot time. If it ever crashes, the operating system will restart it. Usually, its text output is hidden. To reveal and watch the log, you can run the alarm-clock program from within an SSH session and enable debugging. To do this, within an SSH session, temporarily stop the alarm-clock program by issuing the command: stop-alarm-clock The Pi will revert to automatic clock management the next time you reboot. Once the program has been stopped, you can run it manually with the command “sudo alarm-clock”, or use “alarm-clock -h” to display the help options for the program. The command “sudo alarm-clock -V” will run the software with full logging. As it runs, messages and time stamps from different threads will intermix. There’s also a setting that enables logging to a file, for catching issues when you’re not around to look. The Clock’s setup file is located in “/etc/ alarm-clock/setup.conf” and you can edit it to enable file logging using the following command, which will launch a text editor: sudo nano /etc/alarm-clock/setup.conf Look for the two following lines and remove the # symbols in the first column: #VERBOSE=0x090 #LOG_FILE = “/var/log/alarm-clock.log” Screen 2: when configuring an alarm, you can choose the time, duration, which days it’s active, whether it recurs, the volume adjustments and the audio source. February 2024  81 Once you’ve made those changes, press CTRL+O to save them and CTRL+X to return to the command prompt. For more information about the configuration, compiling and playing with the code, consult the readme files in the alarm-clock directory tree you extracted from the .tgz file. Checking that the software is running To check that the alarm-clock program is running, issue the following command: ps -A | grep alarm If it is running, you’ll see a response showing how much CPU time it has used so far. If you see nothing, it is not running. Similarly, you can check for a running pigpio daemon (which must be running for us to control the Pi’s digital I/O pins): ps -A | grep pigpiod We need a Bluetooth control process and its daemon to allow us to play Bluetooth audio, so there should be two items displayed when you run this command: ps -A | grep bluetooth The web server and its workers are usually waiting to receive connections, so there should be several items displayed with the command: ps -A | grep apache To see the complete list of all the running processes along with their memory consumption, type “top” and press Enter to start a self-refreshing display (type the letter q to exit). The top command shows lots of helpful information, including how much CPU time each process is currently consuming, expressed as a percentage of a single CPU core. As there are four CPU cores on most Pis, the Pi will be fully maxed out when the sum of all current CPU utilisation reaches 400%. The largest CPU hog is the pigpio daemon [It isn’t surprising that the biggest hog starts with “pig”! – Editor]. ‘Watchdog’ reboot During the testing and running of the four prototype clocks over the past six months, I saw two of the clocks lock up after a prolonged mains power brownout. 82 Silicon Chip So, the software now incorporates several ways to determine that something has gone wrong and trigger a system reboot when it notices. A hardware watchdog will reboot the Pi if the operating system fully locks up. If just one operating system task locks up, the Clock runs a half-hourly health check, triggering a reboot if something seems amiss. The web server also triggers software checks when somebody accesses a web page. If you run “stop-alarm-clock” for debugging or testing, the health checks will eventually fail, and the automatic rebooting processes will reboot the Clock. You can prevent these automatic reboots after you’ve issued the “stopalarm-clock” command by restarting the alarm-clock program from the command line using the debugging flags you need. The health-check features will not trigger a reboot if they see the alarmclock program running. Internet stream audio delays You might notice something strange when using streaming internet radio stations for alarms. Suppose you set your alarm to trip precisely on the hour and expect the hourly news to wake you, as it would with a regular clock radio. In that case, you’ll discover that streaming radio stations can be anything from a few seconds to a few minutes behind the free-to-air version of the same radio station. The news will never start exactly on the hour with an internet stream; it will always start just a little after! A brief delay with internet streaming is to be expected, but I cannot explain why different radio stations stream with delays that change from day to day and month to month. If you notice this happening with your preferred streams, there’s nothing wrong with the Clock. It is just another artefact of the digital world we live in. If you built a traditional radio into your Clock, over-the-air broadcasts will always arrive precisely on time through that medium. That is probably the only way to guarantee your news service commences with precision. Enjoy your new clock, and if you build a couple, enjoy the liberation of both you and your partner being able to control them from either side SC of the bed! Software updates The Install_Clock script downloads and installs an automatic update client program called “unattended_upgrade” and configures it to check for updates at 3:30am every three days. If an update to any of the installed packages is released, such as a Linux security patch, the automatic updater will download and apply the change automatically. If a reboot is required because of a security patch, that will be scheduled also without human intervention. I have been running automatic updates on several Pis for years and have not struck trouble. However, if you prefer to run updates manually and at your own discretion, you can issue the following command over SSH to stop the automatic updates from occurring: sudo systemctl disable unattended-upgrades You can then manually look for and install updates using the command: sudo apt-get upgrade New versions of the Clock Radio software After installing the clock software, there are two methods you could use to install an update, if one becomes available. 1. Open up the clock, remove the Pi’s SD card, and plug it into your computer. Copy the new software .tgz file onto the SD card, put the SD card back into the Pi, exact the file contents and then rerun the Install_Clock.sh script. 2. Copy the new file into the root of your home account on the Pi over the network, using the Pi’s Samba file server. The following commands can be used to install the new software, assuming you copied the .tgz file into your Pi’s home directory (assuming the update is v02): tar zxf alarm-clock_v02.tgz cd alarm-clock make make install Australia's electronics magazine siliconchip.com.au