Arduino Library for DF Robot 16×2 LCD Keypad Shield

A few years ago, I purchased one of these 16×2 LCD and Keypad Arduino shields. There are quite a few of them around (including some clones?), but they are similar to this one from DF Robot:

IMG_8063I think I bought this one from eBay a few years ago, but nonetheless, the different ones around  are all based on the same circuit. I wrote my own Arduino Library for the keypad operation, and just wanted to share it with those who might find it useful.

There are some jumper wires soldered onto it. This isn’t how it came from the shop, but something I had to modify on the board due to compatibility issues with another shield. I don’t remember exactly what this was for, it was many years ago!

The buttons on the keypad, except for the reset switch, are all connected via a resistor divider to a single analog input pin. You can read what the key state is by reading the analog value at the pin, and comparing it to a set of known expected values.

Download Arduino Library

You can download the library over here:

To install, it simply copy the DFR_LCD_Keypad directory into the libraries directory in your Arduino installation. There is an example sketch to help you get started.

A note about the Pin 10 bug

Just one thing to mention, they all happen to have a flaw in the design, so don’t use pin 10 when using this shield. The library has functions to enable and disable the backlight. But in the design, a flaw exists, that when pin 10 is set to output, and set high, it could cause the IO pin of the MCU (the main Atmel chip) to deliver too much current (over the datasheet’s maximum rating) to the backlight LED. This may cause the over stressing of the MCU and may reduce its life, or maybe even blow it up.

  • To set the backlight on, set pin 10 as input.
  • To set the backlight off, set pin 10 as output, and immediately set output low (never high!)

For more information, there is discussion on the Arduino forums about this.

6 thoughts to “Arduino Library for DF Robot 16×2 LCD Keypad Shield”

  1. Hi there I am trying to use this library as I need to make use of the buttons on the shield but I am getting the following errors please help:

    Arduino: 1.6.5 (Windows 7), Board: “Arduino/Genuino Uno”

    C:\Users\User\Documents\Arduino\libraries\DFR_LCD_Keypad-master\DFR_LCD_Keypad.cpp: In constructor ‘DFR_LCD_Keypad::DFR_LCD_Keypad()’:
    C:\Users\User\Documents\Arduino\libraries\DFR_LCD_Keypad-master\DFR_LCD_Keypad.cpp:10:55: error: cannot call constructor ‘DFR_LCD_Keypad::DFR_LCD_Keypad’ directly [-fpermissive]
    DFR_LCD_Keypad::DFR_LCD_Keypad(DFR_LCD_KEYPAD_KEY_PIN);
    ^
    C:\Users\User\Documents\Arduino\libraries\DFR_LCD_Keypad-master\DFR_LCD_Keypad.cpp:10:55: error: for a function-style cast, remove the redundant ‘::DFR_LCD_Keypad’ [-fpermissive]
    C:\Users\User\Documents\Arduino\libraries\DFR_LCD_Keypad-master\DFR_LCD_Keypad.cpp: In constructor ‘DFR_LCD_Keypad::DFR_LCD_Keypad(uint8_t, LiquidCrystal*)’:
    C:\Users\User\Documents\Arduino\libraries\DFR_LCD_Keypad-master\DFR_LCD_Keypad.cpp:27:35: error: cannot call constructor ‘DFR_LCD_Keypad::DFR_LCD_Keypad’ directly [-fpermissive]
    DFR_LCD_Keypad::DFR_LCD_Keypad(A0);
    ^
    C:\Users\User\Documents\Arduino\libraries\DFR_LCD_Keypad-master\DFR_LCD_Keypad.cpp:27:35: error: for a function-style cast, remove the redundant ‘::DFR_LCD_Keypad’ [-fpermissive]
    Error compiling.

    1. DFR_LCD_Keypad::DFR_LCD_Keypad():DFR_LCD_Keypad(DFR_LCD_KEYPAD_KEY_PIN)
      {
      //DFR_LCD_Keypad::DFR_LCD_Keypad(DFR_LCD_KEYPAD_KEY_PIN);
      }

      DFR_LCD_Keypad::DFR_LCD_Keypad(const uint8_t key_pin, LiquidCrystal *lcd):DFR_LCD_Keypad(A0)
      {
      _lcd = lcd;
      //DFR_LCD_Keypad::DFR_LCD_Keypad(A0);
      }

  2. No compila:

    DFR_LCD_Keypad.cpp:10:55: error: cannot call constructor ‘DFR_LCD_Keypad::DFR_LCD_Keypad’ directly [-fpermissive]

Leave a Reply

Your email address will not be published. Required fields are marked *