public class Lcd extends Object
Part of wiringPi is a library to allow access to parallel interface LCD displays (Those that use the popular Hitachi HD44780U or compatible controllers)
The library is simple to use in your own programs, however wiring the displays up may be challenging, so do take care. It is possible to wire up more than one display! In 8-bit mode, the first display needs 10 GPIO pins and each additional display needs just one more pin, so with a maximum of 17 GPIO pins, that's 8 displays. If you move to using a 4-bit interface (trivial in the code), then it's 4 more displays and 12 LCDs! However I suspect the rest of the wiring might be somewhat challenging. Wiring is described at the end of the this page.
The LCD display can be either a 5V display or a 3,3v display, however if we are using a 5V display then we must make absolutely sure the display can never write data back to the Raspberry Pi, otherwise it will present 5V on the Pi's GPIO pins which will not be good. At best you'll destroy the pin drivers, at worst you'll destroy your Pi.
So make sure you always connect the R/W pin on the display to ground to force the display to be read-only to the host.
Before using the Pi4J library, you need to ensure that the Java VM in configured with access to the following system libraries:
This library depends on the wiringPi native system library. (developed by Gordon Henderson @ http://wiringpi.com/)
Modifier and Type | Method and Description |
---|---|
static void |
lcdCharDef(int handle,
int index,
byte[] data)
This allows you to re-define one of the 8 user-definable chanracters in the display.
|
static void |
lcdClear(int handle)
Clears the LCD screen.
|
static void |
lcdCursor(int handle,
int state)
Turns the LCD cursor ON (1) / OFF (0)
|
static void |
lcdCursorBlink(int handle,
int state)
Turns the LCD cursor blinking behavior ON (1) / OFF (0)
|
static void |
lcdDisplay(int handle,
int state)
Turns the LCD display ON (1) / OFF (0)
|
static void |
lcdHome(int handle)
Set the cursor to the home position.
|
static int |
lcdInit(int rows,
int cols,
int bits,
int rs,
int strb,
int d0,
int d1,
int d2,
int d3,
int d4,
int d5,
int d6,
int d7)
First, you need to initialize wiringPi in the way you want to.
|
static void |
lcdPosition(int handle,
int x,
int y)
Set the position of the cursor for subsequent text entry.
|
static void |
lcdPutchar(int handle,
byte data)
Write a single character of data to the LCD display.
|
static void |
lcdPuts(int handle,
String data)
Write string of data to the LCD display.
|
static void |
lcdPuts(int handle,
String data,
String... args)
Write formatted string of data to the LCD display.
|
public static int lcdInit(int rows, int cols, int bits, int rs, int strb, int d0, int d1, int d2, int d3, int d4, int d5, int d6, int d7)
First, you need to initialize wiringPi in the way you want to. The LCD library will call pinMode functions, but these are ignored if you have already set the modes using the gpio program and want to use the wiringPiSetupSys() mechanism.
int lcdInit(int rows, int cols, int bits, int rs, int strb, int d0, int d1, int d2, int d3, int d4, int d5, int d6, int d7);
This is the main initialization function and must be called before you use any other LCD functions.
Rows and cols are the rows and columns on the display (e.g. 2, 16 or 4,20). Bits is the number of bits wide on the interface (4 or 8). The rs and strb represent the pin numbers of the displays RS pin and Strobe (E) pin. The parameters d0 through d7 are the pin numbers of the 8 data pins connected from the Pi to the display. Only the first 4 are used if you are running the display in 4-bit mode.
The pin numbers will be either wiringPi pin numbers of GPIO pin numbers depending on which wiringPiSetup function you used.
The return value is the handle to be used for all subsequent calls to the lcd library when dealing with that LCD, or -1 to indicate a fault. (Usually incorrect parameters)
rows
- number of rowscols
- number of columnsbits
- number of bits wide on the interface (4 or 8)rs
- pin number of the RS pinstrb
- pin number of the strobe (E) pind0
- pin number for driving bit 1d1
- pin number for driving bit 2d2
- pin number for driving bit 3d3
- pin number for driving bit 4d4
- pin number for driving bit 5 (only used in 8-bit mode)d5
- pin number for driving bit 6 (only used in 8-bit mode)d6
- pin number for driving bit 7 (only used in 8-bit mode)d7
- pin number for driving bit 8 (only used in 8-bit mode)public static void lcdHome(int handle)
Set the cursor to the home position.
handle
- file handlepublic static void lcdClear(int handle)
Clears the LCD screen.
handle
- file handlepublic static void lcdDisplay(int handle, int state)
Turns the LCD display ON (1) / OFF (0)
handle
- file handlepublic static void lcdCursor(int handle, int state)
Turns the LCD cursor ON (1) / OFF (0)
handle
- file handlepublic static void lcdCursorBlink(int handle, int state)
Turns the LCD cursor blinking behavior ON (1) / OFF (0)
handle
- file handlepublic static void lcdPosition(int handle, int x, int y)
Set the position of the cursor for subsequent text entry.
handle
- file handlex
- column position staring at 0 (left)y
- row position starting at 0 (top)public static void lcdCharDef(int handle, int index, byte[] data)
This allows you to re-define one of the 8 user-definable chanracters in the display. The data array is 8 bytes which represent the character from the top-line to the bottom line. Note that the characters are actually 5×8, so only the lower 5 bits are used. The index is from 0 to 7 and you can subsequently print the character defined using the lcdPutchar() call.
handle
- file handleindex
- index value from 0 to 7data
- 8 bytes which represent the character from the top-line to the bottom linepublic static void lcdPutchar(int handle, byte data)
Write a single character of data to the LCD display.
handle
- file handledata
- character data to writepublic static void lcdPuts(int handle, String data)
Write string of data to the LCD display.
(ATTENTION: the 'data' argument can only be a maximum of 512 characters.)
handle
- file handledata
- string data to writepublic static void lcdPuts(int handle, String data, String... args)
Write formatted string of data to the LCD display.
(ATTENTION: the 'data' argument can only be a maximum of 512 characters.)
handle
- file handledata
- format string to writeargs
- string arguments to use in formatted stringCopyright © 2012–2019 Pi4J. All rights reserved.