Maker.io main logo

Using Digilent Pmod Keypad and LCD with Arduino Uno

275

2020-08-27 | By Digilent Inc

License: None

 

Digilent Pmod KYPD is a 16-button keypad arranged in a hexidecimal format (0-F). The PmodKYPD utilizes 4 rows and columns to create an array of 16 momentary pushbuttons. When a button is not pressed, a large pull-up resistor maintains a logic level high voltage on each of the row pins. By driving the column lines to a logic level low voltage one at a time, users may read the corresponding logic level voltage on each of the rows to determine which button, if any, is currently being pressed. Simultaneous button presses can also be recorded, although it is still required to step through each row and column separately in order to ensure that the pressed buttons do not interfere with each measurement. By design, multiple simultaneous button presses within the same row cannot be individually detected.

The Pmod CLS is a character LCD module driven by the Atmel ATmega48 microcontroller. With a display size of 16x2 characters, users may display any information on the screen by communicating via SPI, I2C, or UART. Through these protocol standards, users are able to set the cursor location and send other instructions by sending escape sequences. An escape sequence is specified by first sending the escape character (0x1B) followed by a left square bracket ‘[‘ (0x5B), and then one or more numeric parameters followed by the command character for the specific command. Check out our user guide for a complete list of instruction commands. 

Both of Pmod KYPD and Pmod CLS are powered by Arduino Uno. So, users need to connect Vcc and GND pins of Pmods to 5V and GND of Arduino Uno. Then, row and column pins of Pmod KYPD are connected to digital pins of Arduino Uno. RX of Pmod LCD is connected to pin 13 of Arduino Uno. Pmod CLS has multiple options when recieving data, so both I2C or SPI communication protocols could have been used, but using UART enabels the user to connect it with only one wire (RX). You can set the boards communication method by setting the mode jumpers MD0, MD1, and MD2 on the board. 

Pmod KYPD and Pmod LDC Arduino Project

The Keypad.h library is used to retrieve pressed keys. SoftwareSerial.h library is used to communicate the Pmod CLS with Arduino. Keys pressed on the keypad will be showwn on the LCD. After the LCD is full (32 characters) and a key is pressed, the display is cleared and the character is displayed in the first position of the screen. 

Copy Code
/************************************************************************

  Test of the Pmods KYPD and CLS

*************************************************************************

  Description: Pmod_KYPD_CLS
  Buttons pressed will be shown on the LCD

  Material
  1. Arduino Uno
  2. Pmod KYPD
  3. Pmod CLS
  http://playground.arduino.cc/Code/Keypad

  Wiring
  KYPD<----------> Arduino <--------> CLS
  VCC        to                5V        to      VCC
  GND       to               GND      to      GND
  -              to               13         to      RX
  COL4      to               9           to       -
  COL3      to               8           to       -
  COL2      to               7           to       -
  COL1      to               6           to       -
  ROW4    to               5           to       -
  ROW3    to               4           to       -
  ROW2    to               3           to       -
  ROW1    to               2           to       -

************************************************************************/

#include <SoftwareSerial.h> //include libraries
#include <Keypad.h>

SoftwareSerial lcd(12, 13); //define object for LCD.  RX is pin 12 and TX is pin 13. We don't need to connect RX pin 12 from Arduino Uno to Pmod CLS. 

byte row_pins[] = {2, 3, 4, 5}; //row pins of the keypad
byte column_pins[] = {6, 7, 8, 9}; //column pins of the keypad

//Declaration of the keys of the keypad
char hexaKeys[sizeof(row_pins) / sizeof(byte)][sizeof(column_pins) / sizeof(byte)] =
{
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'0', 'F', 'E', 'D'}
};

Keypad kypd = Keypad( makeKeymap(hexaKeys), row_pins, column_pins, sizeof(row_pins) / sizeof(byte), sizeof(column_pins) / sizeof(byte)); //define object for the keypad

int counter = 0;  //variable to count keypresses

void setup()
{
  lcd.begin(9600); // initialization of serial communication of LCD display
  lcd.write("\x1b[j"); // Erase display. Use the command in Pmod CLS
  lcd.write("\x1b[0h"); // configuration of the display (write on 2 lines). Use the command in Pmod CLS
  lcd.write("\x1b[0;0H"); // cursor is on line 1 and columm 1. Use the command in Pmod CLS
}

void loop()
{
  char current_key = kypd.getKey();  //get keypad state
  if (current_key != 0) { //if a key is pressed
    counter++;  //increment counter
    if (counter == 33) { //if the LCD is full
      counter = 1;  //reset counter
      lcd.write("\x1b[j"); // Erase display
      lcd.write("\x1b[0;0H"); // cursor is on line 1 and columm 1
    }
    lcd.print(current_key); //display key
  }
}
Mfr Part # 410-092
PMODCLS 16X2 CHARACTER LCD
Digilent, Inc.
Mfr Part # 410-195
PMODKYPD 16-BUTTON KEYPAD
Digilent, Inc.
Mfr Part # A000073
ARDUINO UNO SMD R3 ATMEGA328
Arduino
Add all DigiKey Parts to Cart
Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.