Robbi_Blechdose
Posts: 83
Joined: Sat Sep 20, 2014 6:11 pm

Pi Zero Analog Audio

Tue Jul 26, 2016 2:04 pm

Hello everyone,
I recently found the game boy nano on the interwebs and thought I needed one too. The parts have yet to be ordered, but the Pi Zero should arrive soon. The thing is that the Pi Zero doesn't have analog audio out, but my project needs it. I heard you can build a circuit and use the alt pin functions. Do you really need that circuit and what does it do?
Also, I managed to scavenge these off some old PCBs etc.:
Image
Would any of the jacks be suitable to detect if headphones are plugged in? And if so, how would I do it software-/circuit-(if possible) wise to switch from the internal speaker to the headphones?
And would the speakers work with the Pi Zero?
Thanks in advance for any answers!

Robbi Blechdose

@Mods: If this should be in the wrong topic, then please move it.

User avatar
startrek.steve
Posts: 383
Joined: Thu Aug 30, 2012 7:19 pm

Re: Pi Zero Analog Audio

Tue Jul 26, 2016 2:08 pm

USB Sound card?
Pi 2 running LibreElec Krypton, Pi 2 running Wheezy Desktop, Pi 1 headless Wheezy, downloading Radio, Pi 1 running Picore headless Media Server, Pi Zero to be an Old Time Radio Project. Pi 3 testing. Pi Zero W downloading Radio shows headless.

fruitoftheloom
Posts: 20427
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: Pi Zero Analog Audio

Tue Jul 26, 2016 2:10 pm

Robbi_Blechdose wrote:Hello everyone,
I recently found the game boy nano on the interwebs and thought I needed one too. The parts have yet to be ordered, but the Pi Zero should arrive soon. The thing is that the Pi Zero doesn't have analog audio out, but my project needs it. I heard you can build a circuit and use the alt pin functions. Do you really need that circuit and what does it do?
.
https://learn.adafruit.com/introducing- ... io-outputs


.
adieu

Asus CS10 Chromebit / HP Envy 4500 Wireless Printer / Raspberry Pi Model 2B v1.1 / RealVNC Software...

Robbi_Blechdose
Posts: 83
Joined: Sat Sep 20, 2014 6:11 pm

Re: Pi Zero Analog Audio

Tue Jul 26, 2016 2:11 pm

Well, that's
a) too big (most of them)
b) something I'd have to order
c) nothing to do build myself :)
and it doesn't provide the functionality with the headphones/internal speaker switch and has no speakers.
EDIT: Someone was faster than me again. So I'm guessing I don't need the circuit. ;) That's good. What about the rest? :D

fruitoftheloom
Posts: 20427
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: Pi Zero Analog Audio

Tue Jul 26, 2016 2:14 pm

adieu

Asus CS10 Chromebit / HP Envy 4500 Wireless Printer / Raspberry Pi Model 2B v1.1 / RealVNC Software...

User avatar
liudr
Posts: 685
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Re: Pi Zero Analog Audio

Tue Jul 26, 2016 3:43 pm

The jacks on your picture are too fuzzy to tell if they have plug insertion detection. If they only have 3 metal tabs, then no. If they have 5 tabs, then yes.

Go back to the adafruit tutorial that fruitoftheloom posted:

https://learn.adafruit.com/introducing- ... io-outputs

The circuit schematic tells you how to use the jack to auto switch between speakers and head phone. The dashed line box right above black large font "raspberry pi" is the audio jack. See 5 pins on the left? IIRC, 1 is ground. That goes to pi zero ground and negative side of both speakers. 2,5 are two channels for head set. Solder them to the output of the RC filter of the two pwm channels. 3, 4 are the speaker 2 channel pins. These two pins are spring-loaded to make contact with 2, 5 so in the absence of a head phone, they route sound to the speakers. When you plug in the head phone, these two pins are disconnected from 2, 5 so you only hear the sound through your head set.
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

Robbi_Blechdose
Posts: 83
Joined: Sat Sep 20, 2014 6:11 pm

Re: Pi Zero Analog Audio

Tue Jul 26, 2016 7:00 pm

First of all, thanks for the answer(s)!
I think the bigger jack may have 5 pins, my camera somehow didn't like the light of my workspace.
Still, is the circuit mandatory? ;)

User avatar
liudr
Posts: 685
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Re: Pi Zero Analog Audio

Tue Jul 26, 2016 7:22 pm

Yes, the circuit is needed for better sound quality. Try results without the circuit with a head phone. I didn't construct this myself so I'm thinking theoretically that it would sound awful without the circuit.
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

drgeoff
Posts: 9725
Joined: Wed Jan 25, 2012 6:39 pm

Re: Pi Zero Analog Audio

Tue Jul 26, 2016 9:18 pm

liudr wrote:Yes, the circuit is needed for better sound quality. Try results without the circuit with a head phone. I didn't construct this myself so I'm thinking theoretically that it would sound awful without the circuit.
It should sound just fine.

Apart from the AC coupling and the protection diodes the circuit (per channel) is merely an RC low pass filter. The R is somewhere between 100 and 150 ohms depending on the output resistance of the PWM drive. The C is 33 nF. Taking the R as 110 ohms gives a -3dB point of about 44 kHz. That is way above human hearing, above what the speakers will reproduce and headphones won't be very responsive above 40 kHz either. In other words, the presence or absence of the filter will make very little if any perceptible difference to what is heard by a human from the speakers or phones. However the AC coupling capacitors are advisable.

So why is the filter included in the other RPi models which provide an audio output connector?

The PWM output is a train of 1s and 0s at about 10 us intervals. (100 kHz). The short term average of those 1s and 0s is what produces the D to A conversion. The mechanical inertia of the moving diaphragm in speakers and phones is fairly effective at suppressing the 100 kHz component and responding to the short term average. However it isn't the best of ideas to feed such high frequency pulses into audio amplifiers. Hence the low pass RC filter to tame them a bit.

Robbi_Blechdose
Posts: 83
Joined: Sat Sep 20, 2014 6:11 pm

Re: Pi Zero Analog Audio

Wed Jul 27, 2016 9:33 am

Thank you!
I'm not planning on feeding the audio into an amplifier though, rather directly into the speakers. They won't be THAT loud, but it'll suffice, I think. After all the responses, I think it would be best to just build the circuit. http://sudomod.com/forum/viewtopic.php?f=22&t=480 This one doesn't include the diode part, is that bad? Because this guide seemed quite easy, I'd prefer using it. :)

drgeoff
Posts: 9725
Joined: Wed Jan 25, 2012 6:39 pm

Re: Pi Zero Analog Audio

Wed Jul 27, 2016 10:11 am

If you are only connecting to those speakers, the protection diodes are unnecessary. You can also omit the 0.033uF capacitors and the 150 ohm resistors.

Robbi_Blechdose
Posts: 83
Joined: Sat Sep 20, 2014 6:11 pm

Re: Pi Zero Analog Audio

Wed Jul 27, 2016 1:17 pm

Hm. I think it's easier for me to just use the schematic of that page. ;)
But it's of course also supposed to be used with headphones. Thanks a lot again!

Return to “Beginners”