-
Notifications
You must be signed in to change notification settings - Fork 87
LiquidCrystal
The LiquidCrystal library provides the LiquidCrystal class, which provides an API similar to the Arduino's LiquidCrystal library for controlling standard character LCD displays, which use the HD44780 protocol. It supports 8, 16 and 20 character wide displays with 1, 2 and 4 rows.
LCDs can be connected in 4-bit or 8-bit parallel data modes, with or without the R/W pin. This means a minimum or 6 GPIO pins is required to controll an LCD, and 10 pin (or 11 with the R/W pin connected) can be used to send data in 8-bit mode for a faster frame rate.
##Examples
- LiquidCrystal_clock.py - Display the date and time
- LiquidCrystal_fps.py - Measure and display the approximate frame rate
- LiquidCrystal_glyphs.py - Create and display custom glyphs
##API
####LiquidCrystal(rs, enable, d4, d5, d6, d7) Creates an instance of the LiquidCrystal object using the given GPIO pins connected to the corresponding pins on the LCD. This will use 4-bit parallel data mode. The LCD's R/W pin will need to be tied to GND to force the LCD into write mode.
####LiquidCrystal(rs, rw, enable, d4, d5, d6, d7) Same as previous, but with the R/W pin connected instead of tied straight to GND.
####LiquidCrystal(rs, enable, d0, d1, d2, d3, d4, d5, d6, d7) This will create an instance of the LiquidCrystal object using 8-bit parallel data mode. The LCD's R/W pin will need to be tied to GND to force the LCD into write mode.
####LiquidCrystal(rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7) Same as previous, but with the R/W pin connected instead of tied straight to GND.
#####LiquidCrystal.begin(rows, cols)
Initializes the LCD. 'rows' should be equal to the number of rows the LCD has, and 'cols' the number of columns, or characters per row. e.g. for a 2x12 LCD you would call 'LiquidCrystal.begin(2, 12)'.
This method must be called on a LiquidCrystal instance before any of the below methods.
#####LiquidCrystal.clear() Clears all the characters on the LCD.
#####LiquidCrystal.home() Sets the cursor position to 0,0.
#####LiquidCrystal.goto(col, row) Sets the cursor position to the given column (character) of the given row.
#####LiquidCrystal.prints(str) Prints the given string to the display, starting at the current cursor location.
#####LiquidCrystal.createGlyph(glyph_num, glyph) Puts the given glyph into the the display's custom glyph RAM at location glyph_num, which can be 0-7. The LCD controller will store up to eight glyphs in these locations. See the LiquidCrystal_glyphs.py example.
#####LiquidCrystal.displayGlyph(glyph_num) Display the glyph saved in the given location in the display's custom glyph RAM at the current cursor location.
#####LiquidCrystal.scrollDisplay(amount) Scrolls the whole display the given amount. Positive numbers scroll the display to the right, negative to the left.
#####LiquidCrystal.scrollCursor(amount) Moves the cursor the given amount. Positive numbers move it right, negative left.
#####LiquidCrystal.setDisplay(state)
Turns the display on if state is LiquidCrystal.ON, off if state is LiquidCrystal.OFF.
Turning off the display will preserve the characters currently in the display's RAM.
#####LiquidCrystal.setCursor(state)
Set cursor visibility with state = LiquidCrystal.ON or LiquidCrystal.OFF
Set cursor blinking with blink = LiquidCrystal.BLINK or LiquidCrystal.NOBLINK
#####LiquidCrystal.leftToRight() Set string writing from left to right (default).
#####LiquidCrystal.rightToLeft() Set string writing from right to left.
#####LiquidCrystal.autoscroll(state)
If state = LiquidCrystal.ON then writing characters will shift the entire display instead of just the cursor.
Call with LiquidCrystal.OFF to disable.
Disabled by default.