One wire keypad.

bfgstew

Senior Member
#1
Finally got round to getting this solution in its hardware state.
4 x 3 keypad and 4 x 4 keypad fitted with unique resistor matrix to give a near perfect linear voltage spread across each key press. 0.39v across each key on the 4 x 3 keypad.
0.29v across each key on the 4 x 4 keypad.
Now the hard part, to get the coding done.
Got to dig out my testing station and start to play. 20181104_225329.jpg
A shot of the back of the 4 x 3 keypad showing the resistors in place, the 4 x 4 keypad is done in the same manner.
 

bfgstew

Senior Member
#2
Some headway with the coding, so far gives consistant results in PE6 simulation, shall try for real later today.

main:
let b0 = 0 ; clears b0
let b1 = 0 ; clears b1
let b2 = 0 ; clears b2
serout C.0,N2400,(254,1) ; initialize LCD
pause 30

keypad:
do
readadc 4,b0 ; reads ADC value into b0 from keypad
b1= b0*10/150 ; converts value of b0 to keypad number
loop until b0 > 10 ; loops until keypress is seen


screen:
do
lookup b2,("123A456B789C*0#D"),b3 ; lookup table to map keypad layout
inc b2
if b2 = b1 then print ; if the value of b2 = b1 exit loop
loop

print:
serout C.0,N2400,(254,128,b3) ; print value of b3 to LCD
pause 50
 

hippy

Technical Support
Staff member
#3
It looks like your code could be considerably reduced -

Code:
keypad:
  Do
    ReadAdc 4,b0
  Loop Until b0 > 10
  b1 = b0 * 10 / 150
  LookUp b1, ( "123A456B789C*0#D" ), b3
  SerOut C.0, N2400,( 254,128, b3 )
  Pause 50
 

bfgstew

Senior Member
#4
Hooked up the 4 x3 keypad to an 08M2 and an LCD and after a little bit of tweaking of the maths part of the code to allow for the resistance of the keys, and it works.
Next is the 4 x 4 and then maybe expand the coding to do alpha characters and even a calculator, who knows and all on a little old 08M2.
Cheers to Hippy for the code reduction...👍
 

bfgstew

Senior Member
#5
Well the 4 x 4 keypad works as well so pretty pleased so far. The only thing with these keypads is the resistance through each button, it does mess the matrix up a bit that cannot be accounted for. So I shall make a new keypad with positive contact buttons to reduce the rogue resistances and give that a whirl, see if it works any better.
 

bfgstew

Senior Member
#6
Made a bit of a feux pais with the resistor values and therefore the maths doesn't quite work correctly.
Yes the keypad works but I didn't work out the correct division of each key.
5 (volts) ÷ 16 (keys) = 0.3125 (volts/key).
I shifted it back half that value to give (mistakingly) the correct average position for each key, so key 1 = 0.156v, then 2 = 0.469v, then 3 = 0.781v and so on until key D = 4.84v. It should have been key 1 = 0.3125v up to key D = 5v (each key = 0.3125v).
I have now reworked the resistor values and the maths and now it does (in theory) have a true linear step across each key of 0.312v.
Need to order up a new batch of 1% resistors and have another crack at this
 

bfgstew

Senior Member
#7
Further work has given me a true 1 wire keypad, graduated resistor values have resulted in a near perfect linear step on each key press with minimal coding to read keypress......perfect for the 08M2 and other pin hungry projects.
 

Attachments

Top