I have a small problem. I am trying to display characters on my 16x2 LCD shield with a 4x4 keypad connected to an arduino uno. When I press the keypad buttons, the corresponding character prints successfully on the serial monitor but NOT the dsplay. I should also mention that after looking up the ASCII table for characters, the incorrect characters that are being printed on the LCD correspond to repeated ASCII characters i.e pressing 1 key prints 1111 1111, and another key may print a character that corresponds to ASCII 1011 1011. Essentially the characters in the ascii table from bottom right, to top left. Also when I press a key it prints ONCE on the serial monitor but multiple times on the LCD. I will post my code below and a link to the keypad and LCD shield I am using. On a final note when I print characters/words on the display are not to do with the keypad they print fine.
Code:
#include <Keypad.h>
#include <LiquidCrystal.h> // initialize the library with the numbers of the
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'}, //define the cymbols on the buttons of the keypads
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {13, 12, 11, 10}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); //initialize an instance of class NewKeypad
void setup()
{
lcd.begin(16, 2);
Serial.begin(9600);
}
void loop()
{
char customKey = customKeypad.getKey();
if (customKey)
{
//lcd.setCursor(1,1);
lcd.print(customKey);
delay(500);
Serial.print(customKey);
}
}
LCD shield: http://www.maplin.co.uk/p/16x2-lcd-shield-for-arduino-n07dh
Keypad: https://www.coolcomponents.co.uk/sealed-membrane-4-4-button-pad-with-sticker.html
Thanks, hope someone can help.