Skip to content

Latest commit

 

History

History
71 lines (36 loc) · 5.49 KB

Adding Basic Audio Ouput to Raspberry Pi Zero.md

File metadata and controls

71 lines (36 loc) · 5.49 KB

Adding Basic Audio Ouput to Raspberry Pi Zero

Captured: 2015-12-04 at 23:45 from learn.adafruit.com

raspberry_pi_2885-06.jpg

To keep the Raspberry Pi Zero as low cost and small as possible, the Pi foundation didn't include a 3.5mm audio jack. There's also no breakout pads for the audio output. This made us a little :( at first but then we thought "hey you know, we can probably figure out how to get audio out with a little hacking!

The Broadcom chipset used for the Pi does not have a true analog output. Instead, two pins are PWM (pulse-width-modulated) at very high speeds, and filtered. The PWM frequency has to be at least10x as high as the highest frequency we want to replicate in audio. Then, by adjusting the duty cycle of the PWM, we can 'fake' an audio signal.

Audio is 20Hz to 20KHz, and the PWM output from the Pi is 50MHz so we can easily filter the high 50MHz out (and anyways it cant be heard).

Looking at the Pi B schematic, we can see PWM0_OUT and PWM1_OUT are the left and right channels. R21 and R20 are voltage dividers to get the 3.3V signal down to about 1.1V max (that's the max peak-to-peak voltage you want for audio line level.

C20/C26 works with R21/R27 to create an "RC low-pass filter". You can calculate the cut-off frequency with 1/(2piRC) = 1/(2pi2703310-9) = 17865 Hz which is pretty close to 20KHz!

C48/C34 acts as a DC-filter capacitor, it only allows AC through - speakers and headphones don't like DC voltage!

Finally 8AV99 are ESD protection diodes. That's to protect the Pi from static coming in and zapping the PWM pins..

raspberry_pi_audiofilter.png

raspberry_pi_couldntreadall.png

raspberry_pi_wiringpisnapshot.png

In case its not available, you can download it by clicking this button:

raspberry_pi_copytgz.png

Re-boot your Pi Zero up, and get back to the command line. Then mv the file over and un-tar it

raspberry_pi_mvuntar.png

then go into the uncompressed directory and run the compile/install script with

raspberry_pi_wiringcompile.png

raspberry_pi_compiled.png

OK now you can run the updated version of gpio to read the states of all the pins:

raspberry_pi_gpiov.png

raspberry_pi_readall.png

The table has a ton of information going on. What you want to look for is BCM pins #18 and #13

raspberry_pi_nonalts.png

raspberry_pi_pastegpioalt.png

raspberry_pi_saveit.png

raspberry_pi_alted.png

Yep! You can see the new ALT settings.

raspberry_pi_IMG_0074.jpg

I'm using a 3.5mm audio jack terminal block to wire up the left & right channels + ground.

raspberry_pi_audio.png

Finally Force 3.5mm (Headphone)

raspberry_pi_force.png

You only have to do this once, you can hit return and then Finish to exit