Lcd don't display character from keypad

Hi

my lcd don't display caracter when i am typing on kepad 4*5 ,
otherwise if i use keyboard of pc and monitor arduino it s showing me what i am typing !!!

any help please !

#include <LiquidCrystal.h>
#include <Keypad.h>
const int RS = 9, EN = 8, D4 = 5, D5 = 4, D6 = 3, D7 = 2;
LiquidCrystal lcd(RS, EN, D4, D5, D6, D7);
const byte ROWS = 5; //five rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
  {'F','b','#','*'},
  {'1','2','3','*'},
  {'4','5','6','*'},
  {'7','8','9','*'},
  {'F','b','#','*'},
};
byte rowPins[ROWS] = {10,9,8,7,13}; //connect to the row pinouts of the keypad {11,10,9,8,7,6} // {10,9,8,7,6};
byte colPins[COLS] = {2, 3, 4, 12};
char key;
char a ;
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
  lcd.begin(16, 2);
  Serial.begin(9600); 
}
void loop() { 
  lcd.write("hello");
char key =  keypad.getKey();
if(key){ 
  Serial.println(key);
  lcd.clear();
  lcd.write(key);
 
}}

do you see hello on the LCD ?

yesss

you keep rewriting hello on the screen so you don't have the time to see the key

try

#include <LiquidCrystal.h>
#include <Keypad.h>
const int RS = 9, EN = 8, D4 = 5, D5 = 4, D6 = 3, D7 = 2;
LiquidCrystal lcd(RS, EN, D4, D5, D6, D7);
const byte ROWS = 5; //five rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
  {'F', 'b', '#', '*'},
  {'1', '2', '3', '*'},
  {'4', '5', '6', '*'},
  {'7', '8', '9', '*'},
  {'F', 'b', '#', '*'},
};
byte rowPins[ROWS] = {10, 9, 8, 7, 13}; //connect to the row pinouts of the keypad {11,10,9,8,7,6} // {10,9,8,7,6};
byte colPins[COLS] = {2, 3, 4, 12};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
  lcd.begin(16, 2);
  Serial.begin(9600);
  lcd.write("hello");
}

void loop() {
  char key =  keypad.getKey();
  if (key) {
    Serial.println(key);
    lcd.clear();
    lcd.print(key);
  }
}

if i delete hello to give key the time nothing change

try the code I posted

nothing change bro :frowning:

do you see the key in the Serial monitor at all ?

yes

const int RS = 9, EN = 8, D4 = 5, D5 = 4, D6 = 3, D7 = 2;
...
byte rowPins[ROWS] = {10, 9, 8, 7, 13}; //connect to the row pinouts of the keypad {11,10,9,8,7,6} // {10,9,8,7,6};
byte colPins[COLS] = {2, 3, 4, 12};

I wonder if the problem is sharing pins between the LCD and the keypad. It might work for some, but perhaps not for EN = 8 ? Try moving EN to another, unused pin.

The LCD library will set all pins as outputs, probably just once when lcd.begin() is called (I didn't check).

The keypad library sets the row pins to INPUT_PULLUP before each scan. It sets the column pins to OUTPUT and LOW as each column is scanned, then sets them to INPUT. But it assumes they will all be INPUT at the start of each scan.

So it may not be safe to share any pins between the LCD and keypad. At best, the LCD might not work correctly, as you found. At worst, there could be a short circuit between an Arduino pin set HIGH and another set LOW when a key is pressed.

You can use A0 to A5 as digital pins so that you do not need to share any pins between the LCD and keypad.

Good catch - dis not check that !

I just use pin 12 and 13 because I only need one character, one I pressed it the system start working, but now I change the Arduino to mega 25 and wires all the pins and its working :smiley:
Maybe because I use only tow pins from keypad, this is why it's not working.. thank you :heart:!

I'm glad you got it working. I could not understand most of your explanation.

if you use the keypad just as a push button then it's a waste of hardware and software... get a momentary push button...
you can't let pins floating though - they need to be wired so that the library does its work.

aah i see now , for this the lcd don't display what i am typing ... i test it first with monitor and it's working fine... the programm start working but in lcd not for this i think the problem is not wire all the pin of keypad !
basically i use the keypad to type number and other task like a push button

the code i am trying to write is about 'motorcycle detection and timing' so i use ldr sensor , keypad to enter the number of participant .. lazer etc
first i have to point the lazer on the ldr , the latter mesure the value and show it in the lcd etc .. i just write in the program that all of this start working only when i press a button .. that's it !
as i say that i use keypad for this but basically i use it to write the number of participant and the number of phone i use it in gsm modul to send data to the other system ...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.