DavidRobertson
Posts: 2
Joined: Tue Jul 24, 2012 8:49 pm

Possible to detect analog audio jack insertion?

Thu Jul 26, 2012 4:04 pm

Hi,
I was wondering if it was possible to programmatically detect if there is something connected to the analog audio output jack. I know it's possible on some other hardware but not sure about on the Raspberry Pi.

TIA
David.

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: Possible to detect analog audio jack insertion?

Thu Jul 26, 2012 4:24 pm

No, not without any modifications to the board to include the GPIO.

For detection you need a circuit which can accurately measure the resistance between the jack pin (above C34 and D12 or D13 and C48) without compromising the audio output levels.
When the resistance between the 2 points is low then the jack is empty, if higher (not open circuit) then the jack is in use.

Richard S.

Daverj
Posts: 28
Joined: Tue Mar 06, 2012 2:23 am
Contact: Website

Re: Possible to detect analog audio jack insertion?

Thu Jul 26, 2012 4:54 pm

The way most devices detect a plug insertion on a 3.5mm jack is they use a special jack that has an isolated switch built into the jack. That switch connects to a port, like a GPIO pin. So simply reading that port tells you if something is plugged in. That type of jack is readily available, but has different PCB footprints than the more common jacks that don't have the switch. So there's not much chance of swapping the jack on the Pi. However, if it was being mounted into a case, it might be possible to mount one of those jacks and have a short cable that plugs into the jack on the Pi for audio and a pair of wires going to the GPIO for the detection.


User avatar
Burngate
Posts: 6224
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Possible to detect analog audio jack insertion?

Fri Jul 27, 2012 9:17 am

Actually there might be a way to do it.
The socket has built-in two switches, and five connections (2, 3, 1, 4, 5 on the schematic). With a jack inserted, audio is connected through the outer pins 2 & 5 to the jack, with ground to the centre, 1. The other two 3 & 4 are unused.
Remove the jack, and 3 & 4 are connected by the switches to 2 & 5, and audio would appear on 3 & 4.
The audio passes through capacitors (C34 & C48), which remove DC from the signal. It would be trivial to bias the signals with resistors to ground, and connect the switch outputs to a GPIO input to detect the loss of that bias. Unfortunately there are two pairs of diodes D12 & D13 which together make sure the audio is kept within 0 - 3v3. This means that for any large signal the average DC will be about 1v6 (and will distort at the onset of the signal, until C34 & C48 are charged up)
So to do this successfully, D12 & D13 would have to be removed, and be replaced with, say 1k resistors. Pin 3 or 4 (not both) is then wired to a GPIO, with a 10k pull-up. There would have to be a low-pass filter to remove the audio, and a diode pair to protect the GPIO.

User avatar
vicary
Posts: 28
Joined: Tue Jul 17, 2012 4:37 am
Location: Hong Kong

Re: Possible to detect analog audio jack insertion?

Fri Aug 31, 2012 5:31 am

Burngate wrote: So to do this successfully, D12 & D13 would have to be removed, and be replaced with, say 1k resistors. Pin 3 or 4 (not both) is then wired to a GPIO, with a 10k pull-up. There would have to be a low-pass filter to remove the audio, and a diode pair to protect the GPIO.
So far this can be done with some easy soldering, would this affect the audio quality?

User avatar
Burngate
Posts: 6224
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Possible to detect analog audio jack insertion?

Fri Aug 31, 2012 9:54 am

vicary wrote:So far this can be done with some easy soldering, would this affect the audio quality?
In theory, no. But I haven't actually done it, so I can't be absolute.

Return to “Troubleshooting”