Arduino LCD

Sometimes it is useful to have a Liquid Crystal Display (LCD) connected to your Arduino module. The most used type is a 2 line by 16 character display with background illumination. It can be bought for a low price via Ebay for about 2,50 EUR, including shipping. Have a look for the keywords: LCD Display Module 1602 Character HD44780 2X16 and some type of background illumination.

There is already an Arduino library available for this kind of display. The drawback is, that you need 8 I/O lines.

attachment:LCD_2x16_DSC05125.jpg

There comes into the game the I2C/TWI bus. It needs just 2 control wires. Fortunately there is also a low cost interface available from China for about 2 EUR. Search for the title IIC/I2C/TWI/SPI Serial Interface Board Module Arduino 5V 1602 LCD Display. Unfortunately the connection layout to the LCD is not the same, as in the Arduino library. So, you have to modify the library software. I will describe that later.

Another variant is a 16x2 LCD with 5 push buttons for a menu selection (left, right, up, down, Enter). In order to save I/O pins, the push buttons are switching an analog voltage with a resistor chain. So, you need just one analog pin at the Arduino module for control. This module is available from China for about 5 EUR. Search for the title HD44780 LCD Modul Anzeige 2X16 Zeichen Hintergrundslicht f. Arduino mit 6 Tasten zur Bedienung.

For the little test board Bus Pirate you can get a LCD adapter HD44780 with a shift register to interactive test such a kind of LCD module.

Beware of the price span for the same module, it can be a factor of 6!

For each type of LCD module I will give following a more detailed description.

LCD HD44780 controller

The most common model in the market is the 2 line by 16 character (2x16, or 1602) LCD module, please see the first picture.

Usually it is controlled by 4 bit data lines and 3 bit control lines. A forth bit is usually used to control the LED back light of the LCD. The normal connection is:

Pin  signal
01   GND 0V
02   +5 V
03   contrast potentiometer
04   Register select
05   Read/Write
06   Enable clock
11   Data 4
12   Data 5
13   Data 6
14   Data 7
15   LED +5 V, back light
16   LED 0V

The Arduino software library documentation can be found in the Links.

attachment:LCD_Interface_DSC05126.jpg

LCD HD44780 with push buttons

This project is described at http://www.dfrobot.com, see at Links, and the second picture. The 6th button is a Reset button for an Arduino UNO, because the Arduino LCD shield board will cover the Reset button of the Arduino UNO. The example source code is on the web page of the project.

LCD I2C/TWI Interface

This project is described on an own web page, see at Links.

Usually the port expander chip PCF8574 is used. The I2C address is 0x20-0x27 depending on the address bits A0-A2. The chip version PCF8574A has the address 0x38-0x3f.

Unfortunately the low cost Chinese board has their own connection to the LCD, the byte nibbles are swapped, the control signals Register Select and Enable clock are swapped, and the back light control is reversed in polarity. The jumper has the function to disable the back light, if removed. The address lines A0..A2 have pull up resistors connected, so the default address is 0x27.

I had to patch the library software for this case, the new parameter nibble_swap is 1 for this special case, 0 for the normal case:

File: LiquidCrystal_I2C.h 
Line 58 - added "uint8_t nibble_swap"
class LiquidCrystal_I2C : public Print {
public:
  LiquidCrystal_I2C(uint8_t lcd_Addr,uint8_t lcd_cols,uint8_t lcd_rows,uint8_t nibble_swap);

Line 120 - added "uint8_t _nibble_swap;"
  uint8_t _backlightval;
  uint8_t _nibble_swap;

File: LiquidCrystal_I2C.cpp
Line 29 - added "uint8_t nibble_swap"
LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t lcd_Addr,uint8_t lcd_cols,uint8_t lcd_rows,uint8_t nibble_swap)

Line 249
void LiquidCrystal_I2C::expanderWrite(uint8_t _data){    
    uint8_t temp1; 
    uint8_t temp2 = _data;
                                       
    Wire.beginTransmission(_Addr);
    if (_nibble_swap) {
        //Serial.print(".");
        _data = _data | 0x80; // enable back light
        // swap RS and clock E
        if (_data & 0x10) _data = _data | 0x40;
        else _data = _data & ~0x40;
        if (temp2 & 0x40) _data = _data | 0x10;
        else _data = _data & ~0x10; 
        temp1 = _data & 0x0f; 
        temp2 = _data & 0xf0; 
        temp1 = temp1 << 4;
        temp2 = temp2 >> 4; 
        _data = temp2|temp1;
        Wire.write((int)(_data));
    } 
    else Wire.write((int)(_data) | _backlightval);
    Wire.endTransmission();  

Here is the connection schematic (china special) from PCF8574 port expander to the LCD connector:

8574 pin signal  LCD pin
Bit 0..7
4        RegSel  4
5        Rd/Wrt  5
6        EnClk   6
7        Basis NPN Transistor for back light, 1 = ON
9        D4     11
10       D5     12
11       D6     13
12       D7     14

Bus Pirate LCD Adapter

You need a 10 pin flat cable to connect the LCD adapter to the Bus Pirate V3. See the 4th picture on the right (red board). The adapter connects to the standard pinout of a HD44780 controlled LCD.

How to come into the LCD menu, please have a look in the menu options guide, see at Links. You can interactive control the LCD with the following syntax:

Macros

List of pages in this category:

-- RudolfReuter 2014-02-07 09:37:38


Gehe zurück zu CategoryAVR oder StartSeite ; KontaktEmail (ContactEmail)

ArduinoLCD (last edited 2014-02-07 15:44:25 by RudolfReuter)