简体   繁体   中英

Special characters are displaying on LCD Instead of numbers - Arduino

I want to print the number pressed from the 4x3 matrix keypad to my 20x4 lcd but instead I got aw and arrow as a result. The error looks like this. Here is my code.

#include <LiquidCrystal.h>
#include <Keypad.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);//RS,EN,D4,D5,D6,D7

const byte Rows= 4; //number of rows on the keypad i.e. 4
const byte Cols= 3; //number of columns on the keypad i,e, 3

//we will definne the key map as on the key pad:

char keymap[Rows][Cols]={
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};

byte rPins[Rows]= {9, 8, 7, 6}; //Rows 0 to 3
byte cPins[Cols]= {5, 4, 3}; //Columns 0 to 2

Keypad kpd= Keypad(makeKeymap(keymap), rPins, cPins, Rows, Cols);

void setup() {
  lcd.begin(20, 4);//initializing LCD
}

void loop() {
  char keypressed = kpd.getKey();
  if (keypressed != NO_KEY) {
    lcd.print(keypressed);
  }
}

Please help me out.

Your two modules share some of the same pins and that's at the root of the issue:

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);//RS,EN,D4,D5,D6,D7
byte cPins[Cols]= {5, 4, 3}; //Columns 0 to 2

From these declarations, pins 5, 4 and 3 appear to be shared. All sorts of weird things happen when pins are shared between peripheral devices. Then when you say that each device seems to work well on its own, without the other... well I'd say the overlapping pins are your culprit.

See if there's a way to remap one or the other devices so as not to have shared pins.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM