For the past two months or so I’ve been working on a silly audio solution for the team robot – Dasher. Initially I wanted to play sounds on button press – but that lagged/stalled the button process, and didn’t sound silly enough.
So I had the idea of playing a series of audio tracks from Dasher at random intervals. I could have easily hooked up a mini speaker with a built in amplifier – as per the Pringle one – I had lying around. It is loud and flashy. But I wanted an option to power the speakers from the GPIO pins.
following some research on ‘tinterweb, I discovered that the guys that were cleverly hacking old Gamboy cases to house a Rpi + Retropie set up, were using tiny amps to power tiny speakers! A link to an Ebay page and a simple wiring diagram set me on the path to audio stupidity. The tiny (postage stamp sized) PAM 8403 Amp’ cost anything from 50p (bulk) to £2:00. And wiring it up only meant splicing an existing audio lead + some leas/pins soldering on the board.
So one side of the board is wired up to 3 leads of the speaker cable, and a 5V power supply (GPIO pin). Then the other is wired up to some small 8ohm.0.5 W speakers – scavenged from old portable radios. Yes ,they’re small – but two of these wired up to one of these amps is plenty loud – ya hear.
I configured the Pi to force audio thro’ the 3.5 mm audio jack, and used the ALSAmixer to control volume (from LX terminal). Once I have the amp’ soldered and hooked up to some old toy speakers I then used VLC media player to play back some tunage.
The image below shows the first iteration of a speaker from an old electronics kit + a piezo speaker from a toy doll. Worked a treat!
The image below shows the amp’ fitted with all connecting wires. It’s so small, that it can be easily tucked into a chassis.
The image below shows the amp hooked up to GND & 5V GPIO pins to power it – even from a portable power bank.
You can just about see the proof of concept, two free speakers, an old 3.5 mm headphone lead, and a few jumper cables + a £1:00 amp = glorious loud audio – all powered from the Pi.
The next part of the solution took some faffing around with various media players i.e. OMXplayer, mp123. But I plumped for VLC, as it can play a whole directory/folder of files – with the click of a mouse. So, essentially, I wanted to created a simple Mp3 player to play any file, at random in a stipulated folder.
VLC media player offered this option, but also to be able to run it from the command line! So all I needed (after a few days of looking) was a very simple LX command:
cvlc -LZ /home/pi/audio-fx/
It worked as expected, i.e. randomly played all the files in one folder (at a suitably loud volume)! The next option was to ensure this started up every time RPi booted. The solution came within only one hour of searching this time! via a blog telling me that VLC needed SU permissions to start! Thanks V much : pi.bek.no/internetRadio/ . The advice was to:
- edit /etc/rc.local
sudo nano /etc/rc.local
2. before (final) line: exit 0, type:
(sleep 5; su - pi -c "cvlc -LZ /home/pi/audio-fx/") &
3. reboot your Pi – & it’s done :OD.
p.s. you can use the solution above to auto play a m3u playlist or an internet radio stream URL, etc..
The last thing I did was to buy some useless speakers from a charidy shoppe to use the cases, which now housed some much better cones (from old radios, etc). Total cost of mp3 player = < £5:00 (about the same cost as the free Pringles speaker!). We’ll be adding this to Dasher this week -following a master class on creating a simples mp3 player.