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.

How to get ICC profiles working with TimThumb

I was working on a web site that used TimThumb, and ran into an issue.

TimThumb uses the PHP GD library, which does not support color profiles. It is a very common library used in WordPress themes. This can be an issue with web sites which are for photographers, as sometimes, it may be desired to have embedded color profiles in thumbnails. But when timthumb processes an images, it strips the embedded color profile and all metadata.

The metadata I am not too fussed about, but I need to have the sRGB profile embedded in the displayed profile. For visitors using a wide gamut monitor, untagged sRGB images are not displayed properly in Firefox, as color management by default is set such that color management only works on tagged images (see this link on how to enable it for all images). This is really only an issue for visitors on wide gamut monitors.

Here is how to fix this problem.

We modify timthumb so when it writes images to the cache, it adds the ICC profile back in. I used the PHP JPEG ICC profile manipulator by Richard Toth

Download this and place class.jpeg_icc.php into the same directory as timthumb.php

Now download this file in-srgb.jpg (right click and “Save link as…” or “Save target as…”) and place it in the same directory as timthumb.php as well.

Add the following at the start of timthumb.php:

require_once('class.jpeg_icc.php');

Look for the processImageAndWriteToCache() method and look for the following snippet:

		if(preg_match('/^image\/(?:jpg|jpeg)$/i', $mimeType)){
			$imgType = 'jpg';
			imagejpeg($canvas, $tempfile, $quality);
		} else if(preg_match('/^image\/png$/i', $mimeType)){

And replace it with the following:

		$tempfile = tempnam($this->cacheDirectory, 'timthumb_tmpimg_');
		if(preg_match('/^image\/(?:jpg|jpeg)$/i', $mimeType)){
			$imgType = 'jpg';
			imagejpeg($canvas, $tempfile, $quality);

			// Add sRGB ICC profile
			$icc = new JPEG_ICC();
			$icc->LoadFromJPEG('in-srgb.jpg');
			$icc->SaveToJPEG($tempfile);

		} else if(preg_match('/^image\/png$/i', $mimeType)){

Now it would be a good idea to clear the timthumb cache, just go into the cache directory and delete its contents.

That is all.

Now whenever timthumb generates a thumbnail, the thumbnail will have an embedded sRGB ICC profile.

Added avr-uart, an interrupt driven UART library for AVR

Please visit the GitHub project page for the most up to date information, and sample code.

https://github.com/andygock/avr-uart

Lately I’ve been working on some projects on AVR which requires the use of multiple hardware UARTs. I’ve made some modifications to the GPL licensed library by Peter Fluery and Tim Sharpe and have uploaded my version to this site and GitHub. It is an interrupt driven library with circular transmit and receive buffers. You can visit avr-uart here.