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.

Custom avrdude with auto DTR reset and custom baud rate

I’ve been working on a project where I have been using a ATmega2560 with a custom bootloader (based on the Arduino Mega bootloader using the stk500v2 protocol). As I was using a 8MHz crystal, it was best that I used a baud rate of 38400 for programming.

By default with avrdude, when using the -c stk500v2 programmer switch, it does not pull down the DTR line prior to programming, however for my custom application, I was needing this auto reset feature as for my product it was not possible to keep pressing the reset button for a firmware update.

As a result, I have recompiled the avrdude source under MinGW, for a custom build where the -c stk500v2 option now performs a DTR/RTS pulldown.

You can download the custom binary here (includes USB support via libusb):

This should have the same functionality as the original avrdude, but with just the autoreset feature added to the stk500v2 programming selection. This autoreset is not selectable, so if you might want to switch between DTR reset and the original behaviour, it might be best to keep two copies of the binary with different file names.

If you have a similar application where this might be useful, please feel free to download and use it.