Posted by Graham Titman on 11/02/2017 13:57:23:
Hi thanks to the help from forum members i got my dfrobot keypad to work running a r/t but i then bought a sainsmart one for another project and in the house in the warm it seems to work ok but take it down to the cold workshop and make it work hard driving a small Emco milling head up an down in the run mode and it does what Roger Williams 2 does.Graham
Graham,
This sounds as if your key values aren't quite right.
The Arduino works out which key is pressed by measuring a voltage. The voltage varies: not only with the make and version of the board, but also with the tolerances of the resistors used. If the voltage measured is near a boundary, you may get inconsistent results.
Gary Limings wrote this helpful comment in his code:
// average values for my board were: 0, 144, 324, 505, 742
// add approx 100 to those values to set range
But he didn't explain how to measure those 'average values'.
I've knocked up this short program to do just that. It should be compiled and loaded into the Arduino just to find out what your key values actually are. It can be done with the motor connected; the program doesn't use any of the pins.
Once the key values are known, Gary's program can be modified to match your LCD board and reloaded.
In use, the program displays "Push a Button"

After a key has been pressed, it's actual measurement will be displayed for 1.5 seconds. Write the results down for each key (apart from RST!).

From my DFRobot I got: RIGHT 0, UP 100, DOWN 255, LEFT 409 and SELECT 638.
Open Gary's program in the Arduino IDE and scroll to the very end. The last few lines of his code look something like this:
if (key_in > 850) return NO_KEY;
if (key_in < 70) return RIGHT_KEY;
if (key_in < 230) return UP_KEY;
if (key_in < 350) return DOWN_KEY;
if (key_in < 450) return LEFT_KEY;
if (key_in < 850) return SELECT_KEY;
It's the numbers that need to be right. Using Gary's 'add 100 rule' and the measured numbers, the code should be amended to read.
if (key_in > 738) return NO_KEY;
if (key_in < 100) return RIGHT_KEY;
if (key_in < 200) return UP_KEY;
if (key_in < 355) return DOWN_KEY;
if (key_in < 509) return LEFT_KEY;
if (key_in < 738) return SELECT_KEY;
Hope this removes some of the mystery!
Dave
Edited By SillyOldDuffer on 14/02/2017 17:25:08