I've got my LCD Keypad Shield two days ago. I bought it for 8 € in dx.com
Here is the link if you are interested to buy one.
LCD Keypad Shield
I was not sure if this Shield would fit in my Arduino Mega. Fortunately it did. Now, I tried to use some of the examples from the Arduino but they did not work properly.
Since I don't know even which model is this shield and I don't have any documentation, I took a code from freetronic and checked how this thing works. By the way there is nice explanation about how the buttons are connected to a single analog input (A0).
Check the article here
I ran the example and it did not work because this code is for freetronic not for this one. so I went through the code and I noticed that Arduino reads the A0 to figure out which button was pressed. There is a range of voltages for each button. Now, what I did was to show in the display the voltage of the pressed button down on the right corner of the display.
As you can see in the image, pressing the Down button generates 308mV. These are the values I got.
ADC voltages for the 5 buttons on analog input pin A0:
RIGHT: 0.00V : 0 @ 10 bit
UP: 0.71V : 133 @ 10 bit
DOWN: 1.61V : 308 @ 10 bit
LEFT: 2.47V : 481 @ 10 bit
SELECT: 3.62V : 722 @ 10 bit
I adapted those values in the code and now it works!
#define RIGHT_10BIT_ADC 0 // right
#define UP_10BIT_ADC 133 // up
#define DOWN_10BIT_ADC 308 // down
#define LEFT_10BIT_ADC 481 // left
#define SELECT_10BIT_ADC 722 // right
This are the lines you can uncomment to see the voltage of each button:
//debug/test display of the adc reading for the button input voltage pin.
lcd.setCursor(12, 1);
lcd.print( " " ); //quick hack to blank over default left-justification from lcd.print()
lcd.setCursor(12, 1); //note the value will be flickering/faint on the LCD
lcd.print( analogRead( BUTTON_ADC_PIN ) );
delay(500);
Notice that I change the location of the message for the second row and also put a delay.
Thanks for that, my shield works perfectly now too!
ReplyDelete