P2 Taqoz 2.8: Read 6 Keypad Switches with one ADC Pin
Christof Eb. Posts: 910
edited 2023-04-03 16:10 in Forth
well this should be very simple, but still it might be useful. At least I needed quiet some time to work it out.
It reads a keypad with 6 key switches.
Resistor ladder R=220
All Switches connected to keysPin=P40, which has an internal pulldown 15k combined with an ADC on the same pin.
So if no switch is closed, adc reads 0V.
If SW6 is closed, adc reads 3v3.
( Yes, 1690 - 499 + is silly. And yes, it could be done without local value. :-) )
Have fun, Christof
How would you know which switch is closed given the connection described as GND-R-SW1-R-SW2-R-SW3-R-SW4-R-SW5-R-SW6-3V3 (these are all serially connected ?) and all R being equal ? i don't quite grasp the circuit, evidently.
Oh, sorry for the unclear description.
One pin of each switch is connected to the multitap voltage divider. The other pin of each switch is connected to the port pin.
Here's a thread Chip started on doing this same thing: https://forums.parallax.com/discussion/172874/multiple-pushbuttons-on-one-pin-using-adaptive-adc
I remember reading somewhere here about how to scan a whole matrix keypad using just a single pin and maybe a 555 timer or something, but I can't seem to find it now.
Thank you, I get it now and answers my question too.
Thanks for this link!
It is interesting, because I started also with the current source and a similar circuit like Chip. But due to variing resistances of the switch contacts, I then moved to switch low current for low influence of these variations. Perhaps Chip had better quality buttons. I have short cables and do only need one button pressed at a time. I also do not have all these resistor values. My project is about audio and I don't want to have sources of clicks, so there are different solutions.
Edit: I am somewhat surprised, that Chip's solution works with such high speed. With my setup and buttons the time for stable results must be much longer although I need far less precision of voltages.
If you do not need to sense any/all combinations things can be simpler for just any-single-button press.
With 5 switches the simpler non linear approach Chip uses can decode 5 bits, to sense any/all, but it needs detection precision as good as 0.818%, and even then struggles to manage a DIP switch use where a cold start can be any combination.
With keypad buttons, you can assume they are open at power up/ calibrate phases, that also helps.
New Source File appended in post #1.