AndrewMascolo / OnewireKeypad

One Wire Keypad
MIT License
31 stars 14 forks source link

Analog Keypad wrong ranges #7

Open dragoblaztr opened 7 years ago

dragoblaztr commented 7 years ago

I have this keypad, it's 3x4 with analog output and it has 3k resistors for rows and 1k resistors for columns but the pulldown resistor is 10k instead of 1k as in the schematic you provide, the range of analog readings are totally diferent due this issue.

My analog values are

button 1 = 1023 button 2 = 930 button 3 = 850 button 4 = 790 button 5 = 730 button 6 = 680 button 7 = 640 button 8 = 600 button 9 = 570 button * = 540 button 0 = 510 button # = 490

How to fix this

because the range given by your default and changing resistor values is this

OnewireKeypad <Print, 12 > KP(Serial, KEYS, 4, 3, A0, 3000, 1000, MediumPrec );

V:5.00, AR: 1023.00 | V:2.50, AR: 511.50 | V:1.67, AR: 341.00 |

V:1.25, AR: 255.75 | V:1.00, AR: 204.60 | V:0.83, AR: 170.50 |

V:0.71, AR: 146.14 | V:0.63, AR: 127.87 | V:0.56, AR: 113.67 |

V:0.50, AR: 102.30 | V:0.45, AR: 93.00 | V:0.42, AR: 85.25 |

imag0191 imag0192 Regards

dragoblaztr commented 7 years ago

Solved, I look into the h file and find the constructor can add a third resistor value to do that, so I note that I tried the example and thorws a few wrong keys by bad debouncing mostly # after some keys

How to fix this

AndrewMascolo commented 7 years ago

The code assumes the pull down resistor is the same as the other column resistors (1k).

I would need to add a way to change this. Give me a few days and I should have a fix for you.

Sent from my iPhone

On Aug 30, 2017, at 2:32 PM, dragoblaztr notifications@github.com wrote:

I have this keypad, it's 3x4 with analog output and it has 3k resistors for rows and 1k resistors for columns but the pulldown resistor is 10k instead of 1k as in the schematic you provide, the range of analog readings are totally diferent due this issue.

My analog values are

button 1 = 1023 button 2 = 930 button 3 = 850 button 4 = 790 button 5 = 730 button 6 = 680 button 7 = 640 button 8 = 600 button 9 = 570 button * = 540 button 0 = 510 button # = 490

How to fix this

because the range given by your default and changing resistor values is this

OnewireKeypad <Print, 12 > KP(Serial, KEYS, 4, 3, A0, 3000, 1000, MediumPrec );

V:5.00, AR: 1023.00 | V:2.50, AR: 511.50 | V:1.67, AR: 341.00 |

V:1.25, AR: 255.75 | V:1.00, AR: 204.60 | V:0.83, AR: 170.50 |

V:0.71, AR: 146.14 | V:0.63, AR: 127.87 | V:0.56, AR: 113.67 |

V:0.50, AR: 102.30 | V:0.45, AR: 93.00 | V:0.42, AR: 85.25 |

Regards

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

dragoblaztr commented 7 years ago

@AndrewMascolo I already fix this as next (the third resistor value changes that)

OnewireKeypad <Print, 12 > mk1(Serial, KEYS, 4, 3, A0, 3000, 1000, 10000, 30 );

But sometimes it throws inacurrate values (I think poor debouncing)

Thank you in advance

PD. Can be mapped manually the key analog values? and or the tolerance for reading its value

dragoblaztr commented 7 years ago

In the function just replaced

float V = (voltage * float( R2 )) / (float(R2) + (float(R1) * float(R)) + (float(R2) * float(C)));

with this

float V = 0;
      if (R3 != 0) {
        V = (voltage * float( R3 )) / (float(R3) + (float(R1) * float(R)) + (float(R2) * float(C)));
      } else {

        V = (voltage * float( R2 )) / (float(R2) + (float(R1) * float(R)) + (float(R2) * float(C)));
      }

and here is the result


V:5.00, AR: 1023.00 | V:4.55, AR: 930.00 | V:4.17, AR: 852.50 | 
--------------------------------------------------------------------------------
V:3.85, AR: 786.92 | V:3.57, AR: 730.71 | V:3.33, AR: 682.00 | 
--------------------------------------------------------------------------------
V:3.13, AR: 639.38 | V:2.94, AR: 601.76 | V:2.78, AR: 568.33 | 
--------------------------------------------------------------------------------
V:2.63, AR: 538.42 | V:2.50, AR: 511.50 | V:2.38, AR: 487.14 | 
----------------------------------------------------------------
AndrewMascolo commented 7 years ago

The denounce is based on the precision number, so instead of 30, try 40 or 50

Sent from my iPhone

On Aug 30, 2017, at 4:54 PM, dragoblaztr notifications@github.com wrote:

In the function just replaced

float V = (voltage float( R2 )) / (float(R2) + (float(R1) float(R)) + (float(R2) * float(C)));

with this

float V = 0; if (R3 != 0) { V = (voltage float( R3 )) / (float(R3) + (float(R1) float(R)) + (float(R2) * float(C))); } else {

    V = (voltage * float( R2 )) / (float(R2) + (float(R1) * float(R)) + (float(R2) * float(C)));
  }

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.