Friday, 26 February 2016

Music player: The case

Over the past few weeks, I've been building a music player using a Raspberry Pi and a number of components to power and amplify the project.

In my last post, I completed the soldering I needed to do, and completed the circuit. There are still improvements that can be made to the system overall, but for now I've got a complete, working system. I just need to fit it into a case.

I've always liked the combination of old fashioned style and modern technology, and while browsing a vintage shop I came across an old Bush radio from the late 1950's.

The Bush DAC70

The model is a Bush DAC70 which was built in London around 1957. It only picks up Long-wave and Medium-wave transmissions, so in working condition would be fairly limited in what can be picked up with today's radio broadcasts, especially since I don't listen to LW or MW.

The inspection card found inside the case
This unit was not functional, but was only used to make a nice display in the shop. The light inside the dial worked, but the radio itself didn't work.
This wasn't a problem for me, since I only needed the case, and I know that to radio enthusiasts that destroying a perfectly functional radio would be a crime.
Since this unit isn't working, and I'm planning on restoring it in a fashion, so it can be used again, it feels a better use for the radio than just being sat unused on a display.


The case needed a bit of a clean, so I removed the back, and unscrewed the side-knobs so they could be removed. I removed the screws holding the central panel in the case in position, but found that it couldn't be removed easily. The front dial was connected to the tuner inside the case, so I'd have to disconnect this before I could take the components out.

The inside of the radio
I didn't want to break the front dial as the plastic seemed that it would be quite brittle, but with some gentle twisting and pulling I eventually managed to remove the dial in it's entirety from the tuning mechanism. With the dial removed, the rest of the components came out easily and I gave the case and the controls a good clean.

I used an old toothbrush and some soapy water to clean the dials I'd removed from the radio, and they looked much better. For the case itself, I just wiped this down with a damp cloth, there were quire a few cobwebs inside the case before I started cleaning so clearly it hadn't been cleaned in a while.

Case with dials removed and cleaned
With the parts of the case clean and dry, I first installed my speakers into the case. The existing speaker was a single, larger speaker which was fitted inside the left side of the case. I managed to use some of the existing mountings to attach my own speakers.

Inside of the case with new speakers fitted
I then needed something to attach my components to inside the case. I found a piece of old wooden shelf which was lying around and seemed to be about the right size. I had to trim and shape it slightly to make it fit properly in place of the previous metal centre panel.

With this fitted, I screwed my components to the inside of this to stop them moving around inside the case. I'd managed to pick up some small 2.5mm screws which were the right size to fit through the mounting holes of the Raspberry Pi and the other circuits.

The Raspberry Pi and components inside the case
With all the components installed, I checked the connections were fitted correctly, and powered up the radio. I'm still using the simple On/Off switch.

I connected to the Pi MusicBox browser interface from my phone. I also connected to the Pi using SSH from my pc, to check everything was running correctly.

Since the project is using a Raspberry Pi and it's built inside a Bush radio. I've decided to call it The Raspberry Bush.

The Raspberry Bush playing music using Pi MusicBox
I played some radio stations via the TuneIn radio feature of the software, and this seemed to work with no problems.
The volume is loud enough even with the relatively small speakers I used. The sound quality is also great, it might not be as good as a full Hi-Fi system, but for the size of the speakers I don't think it could really sound any better.
If I was to build a system with large speakers, then I expect the built in audio direct from the Pi wouldn't be good enough and I'd need an external DAC add-on, but for this setup it's perfect.


Using the Pi MusicBox software from a mobile phone

There's a number of improvements I plan to make, but for now the project is essentially complete.  It's a fully working system.

The original radio's dial was illuminated with a bulb, which looks really nice when it's working, so i'd like to recreate that by adding some LED's inside the dial. The LED's can be powered and controlled directly from the Pi, so they should be fairly straightforward to add.

I also want to restore the function of the volume control dial and create a better power switch. I'm planning on using a rotary encoder behind one of the dials to allow it to instruct the software to increase or decrease the volume, rather than using something like a variable resistor or potentiometer. This way the system only has a single volume which can be controlled via the software or the dial.
I plan to somehow mount the second dial so it can be used as a simple push switch to turn the system on. I don't have any plans for the front tuning dial currently.

I've mounted the charging circuit in a position where it cannot be very easily accessed at the moment, so I'd have to remove the back to charge it, or feed a micro USB cable through one of the gaps in the rear of the case. It's not a problem for now, but I'd like to improve this.

I also want to try out some different variations and configurations of software. I plan to try those out on my old Raspberry Pi until I've got a setup I'm happy with.

Overall, I'm very happy with the outcome of the project. It's the first project I've done of this type. I've not built any circuits since school, and not used the Raspberry Pi for anything more complicated than a simple media player connected to a TV.

I'd say that most people would be able to tackle a project like this, just be sure to do your research and take your time.

Sunday, 21 February 2016

Music player: Finalising the hardware

I'd tested out my breadboard prototype of the whole music player, and everything worked well. So I needed to do some final soldering to make the connections more permanent.

I didn't want to solder directly onto the Pi and I wanted the other components to be easy to remove in the event I wanted to make any changes to the setup of the hardware.


Making the connectors


I opted to use some of the breadboard jumpers I already had along with some AdaFriut Pig-Tail cables to make the pluggable wires I needed.

The power cable to the Raspberry Pi needed to be stable so it didn't come loose, to make this, I decided to use three female breadboard jumper connectors to make a three-pin connector. Only the first and third pin actually needed wires, the middle pin is just for stability.

Three breadboard jumper connectors
I super-glued the three connectors together to make one, more stable connector, and plugged it into some spare headers to allow it to dry.

The glued power connector
I also needed a two-pin power connection from the PowerBoost to the amplifier. For this I used one of the pig-tail connectors, and soldered this directly to the output USB connections on the PowerBoost so this could plug into the amplifier.

The PowerBoost and pig-tail cable
I needed a better way to connect the audio pig-tail cable to the amplifier. The audio cable connects to four pins on the amplifier board, so for this I created a four-pin cable, soldering the inner two pins to the ground of the audio cable, and the outer two pins separately to the L and R connections of the audio cable.

Soldering the audio cable


Raspberry Pi model A+


I decided to pick up a new Raspberry Pi model A+. I'd previously looked into the power consumption on the different models, and since I only had the old original B model I knew I could reduce the power consumption a reasonable amount by simply swapping to the model A+.

Since the model A+ doesn't have a network connection, and the project was intended to be wireless anyway, I ordered one of the official Raspberry Pi WiFi dongles. I know smaller dongles are available, but I selected this one hoping the larger size would give better WiFi reception. The physical size of the project wasn't my main concern, and since the official dongles are a good price and I know they are fully compatible, it seemed like a good option.

Raspberry Pi model B and model A+ (with WiFi dongle) side-by-side
I knew the model A+ would be smaller than the model B, but seeing the two side-by-side, it's still impressive to see how small these devices are.


Putting it all together


So with all the pieces built, I put the project back together without the breadboard.

Completed hardware. Battery disconnected
I plan to look into which software I want to use with the music player properly later on. I know there are a number of options available, but for now I'm using a basic install of Pi MusicBox.
Since this is easy to set up out of the box and the configuration can be done by changing a few settings in a text file on the SD card before you put it into the Pi, this seemed an easy way to get the WiFi working and music playing with minimal effort.

The completed project, playing music
The PiMusicBox software supports playing of music via multiple methods, but I tested it out with some music playing from an iPod over AirPlay.




For now, I am using a simple SPDT slide switch to control the power on and off, but I am working on a better solution for when the music player is installed into a case.

So that's the main soldering and circuit completed. Next, I plan to build the circuit into a suitable case.

Monday, 1 February 2016

Music player: First prototype

After purchasing the parts I needed from my previous post, my next task was to start building a prototype to test if they would all work together.

The PowerBoost and amplifier circuits would need some soldering before I could use them with my breadboard. I purchased a soldering iron in a starter kit from Amazon, which included a soldering iron stand and some helping hands to hold the component while it is being soldered. The kit also included pliers, solder and some tweezers. Everything I needed to get started.

I soldered the headers and jumpers into the amplifier, and the terminal blocks for the speakers.

MAX98306 Amplifier with soldered headers

I also soldered the headers onto the PowerBoost and some wires onto the power output to power the amplifier.

PowerBoost 500c with soldered headers and power wires

I also needed to solder some lengths of wire onto the speakers.

Speakers with soldered wires

I've not soldered since school, but it didn't take me long to get back into it. Some of the headers weren't perfectly straight, but the connection seemed solid enough.

With an the soldering complete, I assembled the prototype on the breadboard. I aligned a switch with the BAT, EN and GND pins of the PowerBoost on the breadboard, so I could turn the whole circuit on and off more easily. I connected the battery to the PowerBoost using the JST connector and tested that it powered on and off with the switch.

I then added the amplifier to the breadboard and connected the speakers. I temporarily connected the red, black and ground wires from the audio pigtail cable to some male-female breadboard wires, and plugged the red into the R+ pin on the amp and the black into the L+ pin. The ground needed connecting to both the R- and L- pins, so to achieve this I connected the ground from the pigtail to L- and bridged the L- and R- connections with another breadboard wire.

Completed amplifier prototype circuit
I set the amplifier jumper; then connected the two power wires from the PowerBoost to the amp. I initially tested the circuit by connecting the audio cable to a phone to play music. This will eventually connect to the Raspberry Pi, but the principle is the same with any audio device. I powered on the circuit and played some music on the phone.

It worked!

Prototype circuit playing amplified music from phone

The sound quality was impressive and at a reasonable volume. It sounded like it should be loud enough to work as a small music player in the corner of a room, like a small radio. It wouldn't replace a full HiFi system, but that wasn't my intention.

I then tested the circuit powering the Raspberry Pi as well as the as amp, by connecting a wire from the 5V pin on the PowerBoost to GPIO pin 2 on the Pi and from the GND pin on the PowerBoost to GPIO pin 6.

I also plugged the audio cable into the Pi, though I'm not testing the Pi audio here, just the power.

Raspberry Pi and amp powered from the PowerBoost and battery

I also connected the Pi to a monitor to check it was working. Turning the circuit on, the Pi booted normally, and displayed the Desktop on the monitor.

Raspberry Pi fully booted running on battery

Overall this was a successful test of all the parts required. I'd tested that the PowerBoost worked well running on battery, that the PowerBoost could power the amp and the Raspberry Pi, and that the amp played audio at a reasonable volume through the speakers.

The next stage is to make the wiring a little more permanent, removing the need for the breadboard. I'd still like to keep the circuit relatively modular, in case I decide to swap out any parts. I'm going to investigate a number of different options for semi-permanent connections, something like the battery's JST connector or the speaker terminal blocks would be good, but I'll see what I can find.

I'm also keeping in mind that I'd like to make the shutdown friendlier. Currently turning the circuit on is fine, but when it comes to turning off, the Pi ideally needs to be shutdown first, otherwise I'd risk corrupting the SD card. I'm not planning on storing any music on the SD card, so it would only be the OS I'd risk corrupting, which could easily be restored, but still it's not ideal.

So, some sort of method for safely shutting down the Pi before turning off the power would be ideal. If I could also detect a low battery and shutdown the Pi safely that would be even better.

I'll investigate these options and write about my findings in a future post.