Contents
|
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.
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.
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:
A/a/@ Toggle auxiliary pin. Capital “A” sets AUX high, small “a” sets to ground.
@ sets aux to input (high impedance mode) and reads the pin value.
D/d Measure voltage on the ADC pin (v1+ hardware only).
W/w Capital ‘W’ enables the on-board power supplies. Small ‘w’ disables them. (v1+ hardware only).
{ or [ RS low. Next read/write is a COMMAND.
] or } RS high. Next read/write is TEXT/DATA.
r Read one byte (r:1…255 for bulk reads).
0b Write this binary value. Format is 0b00000000 for a byte, but partial bytes are also fine: 0b1001.
0x Write this HEX value. Format is 0×01. Partial bytes are fine: 0xA. A-F can be lower-case or capital letters.
0-255 Write this decimal value. Any number not preceded by 0x or 0b is interpreted as a decimal value.
"xxx" Write the ASCII text xxx to the LCD.
, Value delimiter. Use a coma or space to separate numbers. Any combination is fine,
no delimiter is required between non-number values: {0xa6,0, 0 16 5 0b111 0xaF}.
& Delay 1uS. (&:1…255 for multiple delays)
(#) Run macro, (0) for macro list
Macros
- (0) Macro menu
- (1) LCD reset.
- (2) Init LCD.
- (3) Clear LCD.
- (4) Cursor position ex:(4:0).
- (5) Write test text. (deprecated)
- (6) Write :number test numbers ex:(6:80).
- (7) Write :number test characters ex:(7:80).
Links
List of pages in this category:
-- RudolfReuter 2014-02-07 09:37:38
Gehe zurück zu CategoryAVR oder StartSeite ; KontaktEmail (ContactEmail)