Raspberry Pi Audio Streamer with PSU, Amplifier and Tone Control
I've planned to build a radio for the gerbils for some time as we've found that putting on some low volume classic music helps them to relax.
I'd spent some time building an FM radio from a cheap RDA5807 module, but FM just doesn't quite give the quality you want unless you get a really good signal and free from interference. DAB is a better choice, but we'd be restricted to just UK radio stations.
A better choice would be to build a streamer that can stream not just UK radio stations, but others freely available around the world. A bonus is that you can also play your own stored music, or use UPNP, AirPlay, Spotify Premium etc., or stored mp3 / ogg files from a network drive to stream your own playlist too.
I brought a Raspberry Pi 3b in March 2020 for a different project which I lost interest in and potential use. It's ideal to put it to use now though where it would have been too large for my other Raspberry Pi projects.
I also had a PCM5102 DAC from the other project, plus I've a lot of built but unused amps, a tone control and many other components. All I had to buy was two aluminium project cases, and I ended up buying a 30VA 12V transformer too (as the 100VA one I had was too big!).
The software running on the Raspberry Pi would be moode™ audio player. It's Free Open Source Software (FOSS) GNU GPL. It has the radio feature I like, as well as being able to play mp3s/ogg rips I've stored on my separate server (shared drive). It also supports Spotify Premium playback, which my wife likes. Quite feature rich with a pretty UI, if a little strange to navigate.
MoOde supports all Raspberry Pi's, but I suggest the Pi 3B as the most cost effective option which is both fast enough and has LAN ports and doesn't place too much demand on the PSU. You can find the 3B used on eBay and similar sites. Don't forget an SD card is needed too, and I suggest a high endurance one.
For the speaker, I have an unused centre speaker (Q Acoustics 2000C), which is fairly decent quality (if a bit bland). It's certainly a huge step up from the 90's Philips radio we were using.
If you were building this and buying all the parts though, expect to spend £100 or more, excluding speaker.
Even though this is Raspberry Pi, it is featured as a DIY electronics project because other than installing and configuring the OS with moOde audio, there isn't much software to do.
Please note that although the Raspberry Pi and moOde supports Wi-Fi, signal strength will compromised by the metal case, so I'm using (and recommend) the Ethernet RJ45 port with Cat 5 or better LAN cable.
Hardware
Below is the hardware I'd use for the project:
- Raspberry Pi 3B - the brains of the operation, a cheap ARM computer developed here in the UK but has become extremely popular. Requires a separate Micro SD card.
- PCM5102 DAC - the audio 3.5mm output of the Raspberry Pi 3 B is a bit noisy. A cheap PCM5102 DAC (Digital to Analogue convertor) fixes that! This is not the highest quality DAC of course, but it's a significant step up.
- TDA7391 chip amp - this is decent performing a mono amplifier based on a single chip that I previously made a PCB for. It supports single supply PSU use. You can read more about the TDA7391 here.
- Tone control - for controlling the tone. You can read more about the tone control here.
- Volume control - for controlling the volume. This is simply a 10k Log potentiometer. When viewed from the top, the left pin connects to the ground, middle pin goes to the amplifier input and right pin takes the output from the tone control, or DAC directly.
- 5V Linear PSU - for powering the Raspberry Pi and DAC, regulated by LM2940-5.0, details below.
- 18V/12V Linear PSU - for powering the amplifier and tone control. 12V regulated from a 7812 regulator. Details below.
- Yellow LED and 1k ohm resistor, for amp power on indication
- Two 4-pin DIN plugs (2A rating) and sockets and 4 core 14A 0.75 automotive cable - for connecting the PSU
- Two black aluminium project cases about 150mm wide, 145mm deep and 54mm high - one to house the PSU transformers and rectifiers/smoothing capacitors, and the other for Pi, Amp etc.
- Knobs for the volume and tone controls, toggle switch for power.
- Dupont connectors, 2.54mm headers, PCBs and the like.
I decided on no screen or buttons as operation would be performed remotely via a Smartphone or PC.
As I only intended to use one speaker for the output, this is a mono amplifier build. The DAC and moOde both support stereo playback though, and you can adapt this project with a stereo amplifier quite easily, just use a bigger PSU, two speaker outputs and dual potentiometers for the volume and optionally tone control.
As the amplifier, tone control and volume control are all mono, the stereo output from the PCM5102 DAC is summed to mono via two 1k resistors so sound on only one channel is not lost.
Amplifier choice is vast. There are many pre-built modules you can use if making your own is daunting, or you can look at many of my small, medium power and Hi-Fi amplifiers on my electronics page. I've been impressed by ST Micro's single chip amps such as STA540, TDA7375, TDA7391 and similar though, which sound great, are very easy to build and are pretty efficient and can deliver quite some power from single supply voltages. Many are marketed as car amplifiers, but they are good quality.
I went with the best mono amplifier I already made back in 2020 but haven't used - the TDA7391. Older amplifiers like TDA2003, BA5406 or TDA7056 would also have worked well too, and had I considered that I'd be building separate PSUs for the amplifier and Raspberry Pi, I could have used a split rail Hi-Fi amplifier based on the LM1875, TDA2030 or similar.
I decided to use a tone control in this project since I already had it. Although not as versatile as DSP, be aware that DSP will increase power consumption.
PSU design and information
WARNING:
WIRING TRANSFORMERS MEANS MAINS VOLTAGES ARE INVOLVED. YOU SHOULD NOT DO THIS UNLESS YOU ARE QUALIFIED TO DO SO AND VERY CAREFUL ABOUT YOUR WORK.
For powering my streamer, two linear PSUs are used. There is a low voltage one using a small transformer and a low dropout voltage regulator for powering the Pi and DAC. A higher voltage one with a larger transformer powers the amp.
Both PSUs have their transformers, DC rectifiers and initial capacitor smoothing in a separate case. The voltage outputs are connected to the streamer case (where further regulation is performed) via a 4-pin DIN connector. These are capable of handling 2A of current, so are OK in this case but you'll need something heftier if making a bigger PSU. The cable between the two boxes was 4-core 0.75mm 14A automotive cable.
Linear PSUs were picked for the best noise performance. They will operate for years without going wrong - I have some I built more than 20 years ago that still work today. I also have to consider that this is for the gerbils and most animals are able to hear higher frequencies than us so minimising the chance of high frequency switching noise harmonics that may disturb them is important.
Their disadvantage is that they are less efficient, larger and cost more than the equivalent switching power supply. Picking a transformer with the right secondary voltage helps with efficiency though, and the PSU used here does not consume a large amounts of power when idle, or in general use. I measured 4.1W with the Raspberry Pi idle, amplifier switched off, and 6.5W with the amplifier on and the Raspberry Pi streaming IP radio at a low volume. Standby cost for August 2024 UK electric cost of 22.36p per kWh means the standby cost of this PSU is just over £8 per year.
Switching off at the wall would obviously reduce that, but it is a bit inconvenient because the Raspberry Pi should be shut down properly first or file system corruption can occur. There is also a minute or two boot time.
Information about wiring transformers is here, as well as some general guidelines.
Shown below is a rear view of the PSU box (as well as main box), showing the mains connector (with fuse integrated) and 4-pin DIN used to connect the two DC voltage outputs to the main streamer box.
PSU for 5V
So, let's look at the 5V PSU. Since the Raspberry Pi will be left on, the efficiency matters most for this PSU. Current draw is also a factor, and my design has been sized to power the Raspberry Pi 3B only, and the DAC. A couple of other small peripherals might be OK too, but connecting many USB or GPIO devices is not intended, including any screens.
The Raspberry Pi 3B should consume around 300mA at 5V but can peak up to 900mA. Newer models consume more - so beware! The PCM5102 DAC doesn't have supply current / power info, but it should be less than 50mA at 5V, allowing for some loss in the 3.3V LDO on the board.
Starting at the output, I need an 5V regulator capable of handling 1A. The standard 7805 regulator is easiest, but to provide a regulated 5V output its input voltage should be around 7.5V or higher. That's an efficiency of 67%, but it will be worse because you need your unregulated voltage to be at least 2.5V higher at maximum load. Light load will therefore be much higher (around 10V), and you'll have a typical efficiency of 50% or worse. The power lost becomes heat and 2.5W of heat on a TO220 device will need quite a big heatsink.
I had some LM2940T-5.0 regulators. These are fixed 5V 1A low dropout linear regulators, needing an input voltage just 0.5V higher at 1A. If you read the data sheet though, the input voltage should be 6.25V minimum.
The LM2940 is also available in other voltages or an adjustable version, so check what you are buying. Unlike the almost bullet-proof 7805 regulators, low dropout regulators such as the LM2940 are trickier because they need an output capacitor with a specific ESR and should be close to their load. Get the right capacitor though and the circuit is very easy.
I got lucky with a 100µF 16V AliExpress low ESR capacitor (make sure these cheapo caps have a voltage rating much higher than required). Electrolytic capacitors with higher voltage ratings usually have lower ESR anyway. Keep the cable to the Pi's USB power input connector short.
If you need a 5V supply current more than 1A and still want linear, you can consider the LM1085 (LM1085-5.0) or LM1084 instead. With the same parts, this should be able to supply 2A and could go to 3A with a bigger bridge rectifier and transformer. Be aware that if you are drawing more current, that's more heat to get rid of in the regulator.
To get the >6.25V input voltage, I used a 6V AC toroidal transformer. A 15VA 6V transformer gives 1.25A per secondary winding. In parallel, that's 2.5A, meaning it will still hold up even if the PSU was just 40% efficient overall. Smaller transformers have worse regulation, mine being 16%. This means the no-load voltage is about 7V RMS AC.
Assuming 6V average AC output though, this will get rectified to DC as a higher voltage through a full-wave bridge rectifier (I used a RC201) by 1.8 times, minus forward voltage loses for the rectifier diodes (1.1V ×2) - about 8.6V DC in my case. I measured higher because the no or low load voltage will be higher due to transformer regulation. Under load, the DC output might be worse, hence the risk of using a 7805 which pushes you to use a 9V AC transformer instead and have worse efficiency as a result.
If you can find one, a 5V AC transformer would net better efficiency and should give enough headroom for the dropout voltage of the LM2940 or LM1085/LM1084 regulators.
Capacitor C1 is sized sufficiently enough to smooth the DC output from the bridge rectifier before sending it down the wire between the PSU case and the streamer case. A second smaller capacitor C3 is placed just before the input of the LM2940 for stability.
PSU for 18V and 12V
The PSU for the amplifier is simpler in a way. The amplifier will handle an unregulated DC voltage input fine, but it should be smoothed to ensure no buzz appears on the amplifier speaker output.
I did include an inductor (10µH I think) between the two 2200µF capacitors for when I was experimenting with switch mode PSU input, but this inductor is not needed for a fully linear PSU solution, so it is not shown on my schematic (though does no harm).
This PSU also provides a small regulated 12V DC output for the tone control. The 7812 is overkill for this as the NE5532 in the tone control will pull tens of mA only, but since they are so cheap, easy to build, and I have far too many of them - it's an easy choice. Ceramic bypass capacitors (100nF) are put from ground to the input and output pins as close as possible for best stability. A larger output electrolytic (100µF) is used on the output for further smoothing under load changes. The diodes D1 and D2 protect the regulator - IN4001 or similar are fine.
LED LD1 is a yellow LED for amplifier on power indication, which is current limited by R1 - 100 ohms resistor.
Safety Earth
Since there are mains voltages involved, the case that the transformers and mains wiring is in must be connected directly to the safety earth to achieve Class I equipment classification. Earth IEC standard is the green with yellow stripe wire, or just green in US. This is why an IEC C14 inlet is used with an IEC C13 cable, being a common standard. A C7 / C8 (figure-8) connector and/or two core mains cable is NOT suitable!
Earth is connected to the chassis - both top and bottom halves. This ensures that if any mains connection comes lose, or the transformer coils short to the case, any unsuspecting person who touches the chassis won't get electrocuted. Earth wires must be connected to the chassis with the paint removed via with crimped ring / lug connectors, a screw with tooth washers and nuts, with an extra locking nut at the end.
This chassis screw connection must be dedicated and not used to mount any other boards or connectors. Do not be tempted to use the bolt for the toroidal transformer either - this will create a shorted turn around it (also why the bolt must not touch the top and bottom of the case).
We also need to cover the scenario in case the transformer develops a short between primary / secondary coils (isolation breaks down). Toroidal transformers are rarely double insulated so covering this fault protects the electronics powered by the PSU. That includes protection of the second chassis case where the Raspberry Pi and the amplifier are, or any peripherals connected (including the network cable going to the rest of your cabled devices).
The 6V transformer (for 5V PSU) therefore has its ground wire connected directly to the safety earth too. This covers any fault from the 6V transformer.
Covering for any fault of the 12V transformer (for the 18V amplifier PSU) becomes trickier. If we connect the ground of this PSU to safety earth, a ground loop is formed between the analogue and digital sections which should only be directly connected at the DAC.
To break the loop, but still provide a safety path to earth, a loop breaker is used. This is a bridge rectifier (DB2) with diodes connected back-to-back, and a 10 ohm resistor (R2). A 100nF capacitor (C7) provides a direct path to earth ground for any radio interference. Any AC or DC voltage above 0.6V (i.e. a fault) will travel via the parallel diodes in the bridge rectifier which lasts long enough your switchboard to trip.
Ground layout
An easy problem to run into is ground issues. When digital circuits are involved (such as the Raspberry Pi), switching currents through the ground return can be picked up by audio circuits, such as the amplifier.
To solve the problem, two isolated power supplies are used. That's one for the Raspberry Pi, and one for that amplifier (both shown above). Since both use separate transformers, they are electrically not connected to each other at source, except via the loop breaker for safety.
This allows me to use two separate grounds - one for digital, and one for analogue. They do need to be connected together somewhere for the entire circuit to work but it must only be once - this is at the DAC (PCM5102 board).
The digital ground is at the Raspberry Pi itself, with the only other digital device connected to it being the DAC via its GPIO header.
The analogue ground is a star ground at the output of the 18V psu filter, after the 2200µF capacitors. Here a header is used to connect the DAC, Tone Control board, amplifier power and signal grounds.
Since my amplifier has a bridged speaker output, there is no speaker ground to connect but if there was, then this too should connect to the same analogue star ground.
Not shown is how the case is connected to ground. It should be connected to ground for noise immunity, but again, only at one point. This is vital otherwise the ground currents will start flowing in the case too, and noise on the audio output will happen again.
I tied the digital ground to the case, which helps avoid any noise appear on the audio out from touching the case with your fingers. This connection is done via the tab of the LM2940 regulator, which is tied to pin 2 (GND).
The tab of the TDA7391 amplifier is also connected to ground electrically, which means if you fix the amplifier chip to the case for heatsinking, you will get a second path to ground, and a clicking/squealing noise occurs from interference with the digital ground. Trust me, because I found out!
Isolating the tab of the TDA7391 via a mica washer/pad or Kapton tape and plastic bush. Search for insulating kits for TO-3P/TO-218 - picture from Farnell for reference:
When connecting the tabs of the regulator or amplifier to the case or their own heatsinks, use non-conductive thermal paste too. If using a mica washer, paste should go on both sides.
With grounding done right, you should hear barely any noise at all with your ear to the speaker when the amplifier is on, but no audio is playing. You might get a little hiss (white noise), especially at high volume, but this is quite normal. There should be none, or very little, buzz, hum, clicks or squeals throughout the volume range.
Software
I used the Raspberry Imager to do both the OS and moOde install, selecting the latest Raspberry Pi OS (bookworm). The imager can apply customisations after writing the image to the SD card, such as hostname to connect to after, and username to connect with via ssh.
After installing the image, the rest of the configuration is done via the web UI. If you didn't plug in a network cable, moOde should use the Pi to create a Wi-Fi hotspot for configuration.
Over ssh, I only did a small amount of configuration to reduce SD card writes by installing busybox-syslogd, purging rsyslog and adjusting journald.conf. Details of these are in my Raspberry Pi OS Tweaks page.
In moOde, support for the PCM5102 DAC can be enable via the Configure screen. Audiophonics PCM5102 DAC option seems to work for my generic Chinese one (purple PCB).
I won't go through details set up of moOde since it will all be down to personal preference. In my setup, I have radio favourites configured, a library of my mp3 and ogg file rips of the CD collection which sits on my server (via SMB/Samba) and the Spotify Connect renderer is for my wife who uses a Spotify Premium subscription for her music. I have no display, and no EQ DSP enabled.
Tip: To use the Pi to be a tone generator, ffplay is already present and you can generate a 1kHz tone by connecting via ssh and typing:
ffplay -nodisp -f lavfi -i "sine=f=1000"
It'll be at max volume, but it's useful if diagnosing connections with an oscilloscope. Press CTRL+C to stop the tone.
Conclusion
The Raspberry Pi and accessories are a great way that isn't too expensive to build your own projects. There are potential improvements to my implementation if you want to use a touchscreen or display, or you may want to EQ with DSP to improve audio for a better sound fit to your speakers and room.
Overall, though, this has been an interesting way to merge modern mini computers and open source software with good old fashioned linear PSUs and Class AB amplifiers with tone controls - many of these inventions pre-dating the former by 40 to 60 years, but still are very interesting DIY electronic projects!
As usual, buying a dedicated streamer is easier and quicker, and may even be superior overall. For me though, building my own is always something I consider if I can. It's a hobby after all and I enjoy the satisfaction at the end of having made something myself, and almost everything I make is or has been useful at some point.
References and more reading: