Mobile device, detecting a contact closure...
Mickster
Posts: 2,693
My app, simply needs to detect a contact closure.
In code, I have this available:
And I found this info:
Not sure how to interpret this; do I connect a 2K resistor between the mic pin and ground, via my contact-closure, to give me a mic/no-mic condition?
In code, I have this available:
Headset <state_nvar>, <type_svar>, <mic_nvar>
Reports if there is a headset plugged into your device, and returns data about the headset. The parameters are all names of variables that receive the data:
<state_nvar>: 1.0 if a headset is plugged in, 0.0 if no headset is plugged in, and -1.0 if unknown.
<type_svar>: A string describing the device type of the last headset known to your device.
<mic_nvar>: 1.0 if the headset has a microphone, 0.0 if the headset does not have a microphone, and -1.0 if unknown.
And I found this info:
On Android phones, on iOS devices, and on HD Audio PCs, no mechanical switches in the socket are used. Instead, the headphone socket has 4 contacts instead of 3, and accepts both 4-contact headsets and 3-contact headphones. The sleeve of the 3-contact headphone audio jack connects two of the socket contacts together.
One of the contacts is responsible for microphone and usually feeds 1.5-3.3v of voltage through a current limiting resistor (2-10 kOhm), which is necessary to bias a JFET transistor in the microphone capsule of a headset. DC resistance measurement between the microphone pin and the ground pin of the socket can be used to detect the kind of device plugged in - it will be 0 Ohm for a headphone, infinitely high for no device connected, and about 2 kOhm thereabouts for a headset with microphone.
The bias current limiting resistor forms a part of voltage divider network, with the other part being the above mentioned DC resistance. Voltage measurement on the microphone pin is taken to both determine the sound pressure on the microphone (through a 100hz high pass filter thereabouts) and the kind of jack or device inserted (through a low pass filter or noise rejection logic), allowing this design to be implemented without extra parts, if the filters are implemented digitally. Corresponding to the above DC resistances, you will measure about 0V on the microphone pin if headphone is connected, the full mic bias voltage in case nothing is connected, and something in between in case a headset is connected.
Switches in the audio jack like in the answer above were common in older electronics, but are incompatible with headsets and are just too bulky for a high-tech handset.
Not sure how to interpret this; do I connect a 2K resistor between the mic pin and ground, via my contact-closure, to give me a mic/no-mic condition?
Comments
If a
3 pole plug is inserted, the mic line is pulled to GND and the comparator outputs a Low to the baseband.
When a 4 pole plug is connected, the mic line is typically 1.8V with no Send/End key press. When the
Send/End key is pressed, it shorts the mic line to ground and the comparator outputs a Low to the
baseband.
So apparently a simple pullup resistor (your article says 2K is fine) wired from mic to ground should do it, with a N.O. momentary switch in parallel.
But note the caveat on that page:
This causes a fundamental issue- if a 4 pole headset is connected while pushing the
Send/End key, the baseband registers a 3 pole jack, and the system may never recover.
Hopefully the caveat won't apply because this will be a permanent connection inside my tablet enclosure.
This is my machine-operator interface and I want to eliminate a bunch of hardware push-buttons by using touch-screen soft buttons. To avoid accidental triggering of machine movements, I am incorporating a "dead-man" button as found on robot teach-pendants. A half depression closes the contact but a full depression or release, opens the contact (apparently, some people tend to squeeze, rather than let-go when panicked).
I just hacked-off the connector from a headphone/mic headset but these are strange conductors; extremely light-gauge and I can't read continuity to any of the plug contacts(???).
Ordered a single 4-pole plug to test.
Cheers!
If you're a gamblin' man with 77 cents to burn, nab one of these and measure the resistances. https://www.ebay.com/itm/391181381554
Be aware, the photos show a mix of 3 and 4 conductor types. And there's a cutaway view that says there's a chip inside, and an app. More likely a switch and maybe a resistor and/or cap.
I got excited about the NXP Quick-Jack. I can find the product in stock but the app is nowhere to be found.