5

Hello fellow Stackers,

Is there a way to detect when a 3.5mm jack is placed into\ removed from the audio out that is on board for use in a script?

I also have one of these:

https://www.element14.com/community/community/raspberry-pi/raspberry-pi-accessories/cirrus_logic_audio_card

Mounted on a pi2 that I would like to be able to do the same with in the way of detection on its 3.5mm jacks.

I know that most modern computers are capable of this. Are our Pi's able to do this to?

Long version:

This will be so that I can use the Cirrus/Wolfson card outputs to play content from the Pi but pick up when an external source is plugged in (say my phone) and have a script. Be it bash or python etc. Mute the playing content to allow the connected device to play either directly to the speakers or be routed through the pi to the speakers somehow, presumable in the software, without having to use a manual toggle switch somewhere.

EDIT: Raspbian will be my go to distro but if anyone wants to suggest other distros more suited to this task feel free to suggest them. I will probably start out trying the distro listed on the element 14 site and work out form there.

2 Answers 2

2

To the best of my knowledge, no models of the Pi or the Cirrus audio card offer this functionality.

Jack detection is generally done using additional contacts/switches in the jack socket which are closed when an object is inserted. The image below shows how this is achieved in the Fairchild FSA8049 switch. Without these contacts it will be complicated, if not impossible, to detect a jack insertion.

Fairchild FSA8049 audio jack detection switch

3
  • This is as much as I found when searching for answers before asking the question here. Question is that contact and circuit must tell the OS what port to shove audio out of and to not bother if nothing is connected. This must then must be stored as a flag or something somewhere and I am wondering if that can be found and watched by a script to act as a trigger for an event?
    – Lime
    Commented Jun 8, 2016 at 13:53
  • Sadly, barring some exceptional electronics mojo on your part, I think that might be as far as you'll get. There may be some aftermarket jiggery pokery that you could pull off, somehow soldering contacts to the inside of a jack barrel, but it sounds implausible to me. I suppose, if you really really really wanted to you could de-solder the existing jack plug and replace it with one that has contact sensors, then solder up those sensors to GPIOs.
    – goobering
    Commented Jun 8, 2016 at 13:56
  • Make a jack extension of some sort. where you plug a 3.5 into the pi, and on the other end have a female 3.5 that has these contacts and rig it up to the GPIO. No internal mods needed on the pi's board that way and fully removable. Then code against the GPIO pin states.
    – Dan V
    Commented Jun 10, 2016 at 4:47
0

For the Cirrus audio card, i think they DO offer this functionality (at least on hardware). I am not sure on the software side, but i think you can hack the driver?

According to the schematic of the Cirrus card, at page 6, line in (mic in) jack have a detection pin goes to GPIO2, this applies to line out and headphone out as whell which goes to GPIO1 and JACKDET respectively. These 3 pins are all connected to the main WM5102 audio codec IC.

For RPi2, the 4-POLE A/V JACK did not provide jack detection functionality on hardware.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.