Skip to content

ioClass: hd44780_pinIO

bperrybap edited this page Oct 25, 2023 · 20 revisions

hd44780_pinIO

The hd44780_I2Cexp ioClass is used to control LCDs using direct Arduino Pin connections

The hd44780 library API is API compatible with the IDE bundled LiquidCrystal library.

Initialization

The hd44780_pinIO i/o class cannot auto self configure. Therefore the sketch must initialize the library using a constructor to tell the library how the LCD is wired to the Arduino. (which Arduino pins are used) While the header file includes used are different and the name of the lcd object constructor is different, the actual constructor pin parameters are fully compatible with the IDE bundled LiquidCrystal library.

However, the hd44780_pinIO i/o class also includes support for 2 additional parameters to allow controlling an optional backlight control circuit. Note that the backlight on most LCDs uses more current than an Arduino pin can provide so an Arduino pin cannot be used to directly drive the LCD backlight.

See the included HelloWorld sketch for a minimal example of how to declare the lcd constructor and initialize the LCD.

Special Note about LCD keypad shields

Some LCD keypad shields have a broken backlight control circuit. These shields use Arduino pin D10 to control a transistor that switches the backlight on/off. Due to the circuit design if D10 is ever driven high, it creates a short through the backlight circuit transistor which can potentially damage the Arduino. See this Arduino forum thread for a detailed discussion about the issue: Warning to users of some vendors LCD keypad shields
The hd44780_PinIO ioClass contains an example, LcdKeypadCheck that will detect whether or not the LCD keypad shield has the h/w issue. When using hd44780_PinIO ioClass, there is no need to worry about the LCD keypad backlight issue.
The hd44780_PinIO ioclass contains special code to detect this h/w issue and will work around it in s/w. If the hd44780_PinIO ioClass detects this issue, it will disable PWM dimming using setBacklight() even if Arduino pin D10 supports it. The code will operate as if the pin does not support PWM. This is to protect the Arduino. setBacklight(), backlight() and noBacklight() can all be used with no worries over h/w damage since the s/w will work around the backlight h/w issue.

Examples

Using the Arduino IDE, hd44780_pinIO examples can be found here:
[File]->Examples->hd44780->ioClass->hd44780_pinIO

Using the IDE GUI to bring up the included HelloWorld sketch for a minimal example of how to declare the lcd constructor and initialize the LCD you would click on
[File]->Examples->hd44780->ioClass->hd44780_pinIO->HelloWorld

Technical Information

Arduino IDE LiquidCrystal page: https://www.arduino.cc/en/Reference/LiquidCrystal

While not all hd44780 display modules use the same pinout, here is the one that most used: pin 1 is the pin closest to the edge of the PCB

    • LCD gnd
    • VCC (5v)
    • Vo Contrast Voltage
    • RS Register Select (rs)
    • Read/Write
    • Enable (en)
    • Data 0 (db0) --------- Not used in 4 bit mode
    • Data 1 (db1) --------- Not used in 4 bit mode
    • Data 2 (db2) --------- Not used in 4 bit mode
    • Data 3 (db3) --------- Not used in 4 bit mode
    • Data 4 (db4)
    • Data 5 (db5)
    • Data 6 (db6)
    • Data 7 (db7)
    • Backlight Anode (+5v)
    • Backlight Cathode (Gnd)

hd44780 Datasheet can be found here: https://www.sparkfun.com/datasheets/LCD/HD44780.pdf


If you want to control the backlight, the hd44780 library provides API functions to control the backlight using an Arduino pin.

In some cases you can wire the Arduino pin directly to the LCD anode.
Many of the newer 16x2 LCDs use a low enough current that they can directly be driven by an Arduino pin on the AVR based Arduinos.

NOTE:
If you do decide to control the backlight directly with an Arduino pin without using a backlight control circuit, make sure to verify the amount of current the backlight consumes is less than the drive capability of the Arduino you are using.
i.e. measure the current when directly connected to power and verifying that the current is lower than the maximum a pin can provide before you try to control it directly with a pin.
For an AVR based Arduino this should definitely be under the max pin current of 40ma but a better target would be under the 20ma-30ma range.

If the LCD backlight needs more current than your Arduino can drive from a pin, you will need a backlight control circuit. LCD keypad shields typically include a backlight control circuit and it is usually wired to Arduino pin #10 If you are not using an LCD keypad shield and need a backlight control circuit, here are a couple of examples of backlight control circuits.
Both of these use active HIGH backlight control.

The (BL input) in the circuit diagrams is wired to the Arduino pin used for backlight control.


(LCD BL anode)----(VCC)

(LCD BL cathode)---------------+
                               |
                               C
                               |
(BL input)--[ Resistor ]---B-|> (NPN)
                 1k            |
                               E
                               |
                             (GND)

NOTE: The Base resistor is needed because the NPN is current fed. For lower power draw, try a 10k resistor.


N-CH Mosfet version: (less power draw and lower part count)

(LCD BL anode)----(VCC)

(LCD BL cathode)---------------+
                               |
                               D
                               |
(BL input)----------------G-|-< (2N7000 FET)
                               |
                               S
                               |
                             (GND)