2
\$\begingroup\$

I replaced my car stereo with a Raspberry Pi 3 and the 7" touch screen. Everything's working nicely, but now I want to hook up the volume control buttons on the steering wheel to the Pi. The buttons work by changing the resistance across two wires in the stereo wiring harness. With no buttons pressed, the resistance is 10kΩ, volume up changes that to 300Ω, and volume down is 50Ω.

I have previously used an MCP3008 ADC to read resistance values with a Pi, however in that case I just polled the ADC as needed. In this case I think polling would take up too much CPU power for the sampling rate I need.

I have also previously used the Wiring Pi library to set up GPIO interrupts to detect rising and falling edges on voltage. My current plan is to use an interrupt to detect the change in voltage when I press a button, then use that to trigger a read from the ADC to get the precise resistance value.

My question is, is this a good way to do this, or is there something better?

\$\endgroup\$
1
  • \$\begingroup\$ Better is subjective. If you could isolate the buttons from each other and connect them to separate GPIOs, that might be considered better. Or it could be considered not better at all, depending on the situation, and who you ask. \$\endgroup\$
    – Dampmaskin
    Commented Oct 4, 2017 at 14:26

2 Answers 2

1
\$\begingroup\$

If you use 3V3 as a starting point and add a 1k resistor in series with your buttons, you'll get 3V for no button pressed, 0.76V for up and 0.16V for down.

The "up" and "down" voltages are well in the "0" logic level voltage, while the "no button" is a "1" so your GPIO pin change interrupt will have no trouble detecting them.

Also the ADC should have no trouble telling the difference between "up" and "down".

Don't forget to add a few nF capacitor at the input to filter noise which an automobile produces in generous amounts...

\$\endgroup\$
2
  • \$\begingroup\$ Just to clarify, I would listen for a voltage change at a point in-between the buttons and the 1k resistor, like a voltage divider? \$\endgroup\$
    – Carlton
    Commented Oct 4, 2017 at 19:25
  • \$\begingroup\$ That's the idea ;) \$\endgroup\$
    – bobflux
    Commented Oct 4, 2017 at 21:14
1
\$\begingroup\$

Another approach: if you have a second GPIO pin available, wire it to the first with a medium value resistance.

You can turn that output off and use the difference between 10K and "low" to interrupt.

Then the handler turns it on to measure the difference between 300R and 50R, and turns it off again to possibly save power.

\$\endgroup\$

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.