Hi, I am using the lcd keypad shield with the uno board. I have come across this in the literature;
" To save the digital IO pins, the keypad interface uses only one ADC channel. The key value is read through a 5 stage voltage divider." This analog pin is A0. Is this 5 stage voltage divider installed in the lcd? In which case you need to know what the analog read is on each button press of the lcd.
If the voltage divider is not installed internally in the lcd then you have to build one externally and also know which combination of resistors relate to which button. I did see somewhere a voltage divider which appeared to do exactly that. On looking for it again I can't find it.
Does anybody know? Do I need an external voltage divider or not?
Please post a link to where you got the LCD
If it has buttons on it then it almost certainly has the voltage divider built in. How are the pins on the LCD labelled ?
for usual this "voltage divider" is already on the LCD keypad shield. If the resistors are behind the LCD you can't see them.
Just write a short demo sketch and read from analogRead(A0) in loop and print the result to Serial.
You should see different values based on what button you press.
You should get quite stable values if you press no button.
If this test brings you nowhere, you should
- post a good picture of your setup,
- a link to the lcd shield you have bought,
- a schematic of your setup,
- the code you have tried.
In other words - everything you have on your bench and we can't see from your description.
Why not look at the library code for the device?
The lcd is from Jaycar. Its called a lcd keypad shield and was supposed to fit directly on to the uno board. The pins didn't match up so I could not do that. I have used ribbon cable to make the connections. You are going to need the cables anyway if you want to use additional analog read ports for reading sensors. The way I have it now is all the analog pins are connected to the lcd. If the shield fitted this is how it would be. Apparently I only need the A0 port to connect the uno to the lcd.
The buttons on the LCD are labelled select, left, right, up, down and rst.
Yes I will write a short sketch to read the A0 port. I think it is supposed to read 5v (1023) if no buttons are pressed. Might have debounce problems on pressing the buttons. Remains to be seen.
Do you mean this LCD board ?
If so, then it should plug straight into a Uno. What stopped you doing that ?
Pins didn't line up Bob. So I bought connecting cables which you need anyway if you want to use any other analog read ports apart from AO which is used to connect uno to LCD. If the pins did line up you have all the analog pins going into the LCD which the LCD does not use apart from AO. Then you couldn't use your uno to read sensors for example. Then the only thing you could do would be to write messages on the LCD.
again:
- post a good picture of your setup - there must be a reason why your pin don't line up
- a link to the lcd shield you have bought,
demo program to read AO port. no button press=1023(5v), buttons; select=640, left=409, up=99, down=256, right=0, rst gives nothing. I know that these pins have to be programmed to do different things. What would the user of the keypad for the lcd expect on pressing the different buttons. It would be great if I could find a working example , an animation if you like, to see what happens to the display on pressing the different buttons. To give meaning to select, etc.
Here is an example that I found lurking on my PC. It is quite probably for the same LCD board that you have, but no guarantees. Even if it does not work with your shield you should be able to see the principles that it uses
/* FILE: ARD_LCD_HCARDU014_Buttons_Example.pde
DATE: 02/07/12
VERSION: 0.1
This is a simple example of how to use the buttons included on the
HobbyComponents Arduino LCD shield (HCARDU0014). The shield will work
with the standard Arduino LiquidCrystal library.
The buttons when pressed apply different offset voltages to the
Arduino ADC0. Reading the ADC will give an ADC code in the following
range depending on which button has been pressed:
Between 0 & 49 = RIGHT button pressed.
Between 50 & 194 = UP button pressed.
Between 195 & 379 = DOWN button pressed.
Between 380 & 555 = LEFT button pressed.
Between 555 & 789 = SELECT button pressed.
Above and ADC code of 790, assume no button has been pressed.
LCD Backlight considerations
By default the LiquidCrystal library does not attempt to control the backlight
and therefore the backlight will default to being permanently on. If you do not
need to change the state of the backlight you can ignore the following information:
When overriding the state of the backlight via DIO10 from your own code, you must
drive the pin in one of two modes:
Backlight DIO10
OFF OUTPUT/LOW
ON INPUT
DO NOT configure DIO to be and OUTPUT/HIGH as this can cause excessive current
to be drawn from DIO10.
You may copy, alter and reuse this code in any way you like but please leave
reference to HobbyComponents.com in your comments if you redistribute this code.
THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER
EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES,
INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
REASON WHATSOEVER.
*/
/* Include the standard LiquidCrystal library */
#include <LiquidCrystal.h>
/* DIO pin definitions */
#define LCD_DATA4 4 /* LCD data DIO pin 4 */
#define LCD_DATA5 5 /* LCD data DIO pin 5 */
#define LCD_DATA6 6 /* LCD data DIO pin 6 */
#define LCD_DATA7 7 /* LCD data DIO pin 7 */
#define LCD_RESET 8 /* LCD Reset DIO pin */
#define LCD_ENABLE 9 /* LCD Enable DIO pin */
#define LCD_BACKLIGHT 10 /*LCD backlight DIO pin */
/* Definitions for current button state */
typedef enum
{
E_LCD_BTN_RIGHT, /* LCD RIGHT button pressed */
E_LCD_BTN_UP, /* LCD UP button pressed */
E_LCD_BTN_DOWN, /* LCD DOWN button pressed */
E_LCD_BTN_LEFT, /* LCD LEFT button pressed */
E_LCD_BTN_SELECT, /* LCD SELECT button pressed */
E_LCD_BTN_NONE, /* LCD NONE button pressed */
}
teButtonState;
/* Initiliase the LiquidCrystal library with the correct DIO pins */
LiquidCrystal lcd(LCD_RESET, LCD_ENABLE, LCD_DATA4, LCD_DATA5, LCD_DATA6, LCD_DATA7);
void setup() {
/* Set the correct display size (16 character, 2 line display) */
lcd.begin(16, 2);
}
/* Main program loop */
void loop()
{
/* Put the LCD cursor on the first row and prompt the user to press a button */
lcd.setCursor(0,0);
lcd.print("Press a button...");
/* Keep checking for a button press */
while (1)
{
/* Put the LCD cursor on the second row */
lcd.setCursor(0,1);
/* Get the current state of the LCD buttons */
switch(iGetLCDButtonState())
{
/* If the RIGHT button has been pressed then display this on the LCD */
case E_LCD_BTN_RIGHT:
lcd.print("RIGHT ");
break;
/* If the LEFT button has been pressed then display this on the LCD */
case E_LCD_BTN_LEFT:
lcd.print("LEFT ");
break;
/* If the UP button has been pressed then display this on the LCD */
case E_LCD_BTN_UP:
lcd.print("UP ");
break;
/* If the DOWN button has been pressed then display this on the LCD */
case E_LCD_BTN_DOWN:
lcd.print("DOWN ");
break;
/* If the SELECT button has been pressed then display this on the LCD */
case E_LCD_BTN_SELECT:
lcd.print("SELECT");
break;
/* If no button has been pressed then display NONE on the LCD */
case E_LCD_BTN_NONE:
lcd.print("NONE ");
break;
}
}
}
/* Read the current state of the LCD buttons using the ADC */
int iGetLCDButtonState()
{
int iADC_Value;
int iADC_Button_State = E_LCD_BTN_NONE;
iADC_Value = analogRead(0); /* Read the ADC */
/* If ADC reads above 1000 then assume no buttons have been pressed */
if (iADC_Value > 1000)
{
iADC_Button_State = E_LCD_BTN_NONE;
}
else /* If it was below 1000 then a button is pressed... */
{
/* If ADC reads between 0 & 49, then the RIGHT button has been pressed */
if (iADC_Value < 50)
{
iADC_Button_State = E_LCD_BTN_RIGHT;
}
else
{
/* If ADC reads between 50 & 194, then the UP button has been pressed */
if (iADC_Value < 195)
{
iADC_Button_State = E_LCD_BTN_UP;
}
else
{
/* If ADC reads between 195 & 379, then the DOWN button has been pressed */
if (iADC_Value < 380)
{
iADC_Button_State = E_LCD_BTN_DOWN;
}
else
{
/* If ADC reads between 380 & 555, then the LEFT button has been pressed */
if (iADC_Value < 555)
{
iADC_Button_State = E_LCD_BTN_LEFT;
}
else
{
/* If ADC reads between 555 & 789, then the SELECT button has been pressed */
if (iADC_Value < 790)
iADC_Button_State = E_LCD_BTN_SELECT;
}
}
}
}
}
return iADC_Button_State;
}
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.