Skip to content

PoEPi Speaker Amp Playing .mp3 from a speaker wired to the PoEPi board

julien8 edited this page Feb 23, 2016 · 1 revision

For the three different PoEPi boards this is probably the most complex in regards to its software functionality. However don’t be scared, if you follow the command step by step you should have any problems at all.

Currently the pins used on the Raspberry Pi (not header pins but actual BGA pins... or balls I guess) that are routed to the Audio on the other Pi models are not routed to the GPIO. So we cant just go about business as usual with the audio. Fortunately thanks to device tree data we can remap things pretty easily. For those who where around in the early days of getting PWM on the BBB you will be pretty familiar with this process. This means that we will tell the Raspberry Pi to use different pins for the Audio output while disabling the original pins. There are only certain pins we can use but luckily there are a bunch already on the GPIO header.

Installing Required Software Packages

We don’t need to many bulky packages for this application. mpg321 is a common audio player for linux machines and it has been compiled for ARM. the device tree compiler will take our human readable device tree 'file' and turn it into something the Pi can use.

sudo apt-get install device_tree_compiler mpg321

Compiling and Implementing a New Device Tree

First we need to get a device tree file. There is one provided on the Raspberry Pi Foundations website that is pretty up to date. Be aware that if you are using an older Raspbian this may not work.

wget https://www.raspberrypi.org/documentation/configuration/images/dt-blob.dts

Now we need to change the pins around to match the schematic of the PoEPi board. If we take a look at the schematic we can see that the Audio circuit is tied to GPIO12 (or pin 32).

Open up the device tree with Nano

nano dt-blob.dts

In this file you will notice that there are a bunch of pin definitions. Each pin is described with comments on the side. You may notice some fun pin definitions you didn’t know you could change... have fun with that later. If you scroll down to line 21 you will see the audio pins defined. We want to change these to the pins we need.

Change either of these to 12 and close and save the file

pin@p12 { function = "pwm";    termination = "no_pulling"; drive_strength_mA = < 16 >; }; // Left audio

Now we want to compile this device tree into something it can use. We also want to place this into the boot directory so that the Pi can read it on startup.

dtc -O dtb -o dt-blob.bin dt-blob.dts
sudo cp dt-blob.bin /boot/dt-blob.bin
sudo reboot

Playing Some Music

Once you have done all the device tree work you should be good to play some audio! Connect a speaker to the PoEPi, just make sure it isn’t to high powered or you wont get very much. You will need your own .mp3 file for this part.

mpg321 -g 20 tronlegacy.mp3

You should hear some lovely tron beats coming from your speaker. You may need to look at equalizer applications in order to get the best quality out of your speaker.