Skip to main content

A Raspberry Pi LCD library for the widely used Hitachi HD44780 controller.

Project description

A Python 2/3 Raspberry PI Character LCD library for the Hitachi HD44780 controller.

Tested with the 20x4 LCD that is sold for example by adafruit.com or mikroshop.ch.

This library is inspired by Adafruit Industries’ CharLCD library as well as by Arduino’s LiquidCrystal library.

The GPIO access is provided by the great RPIO library.

Goals

  • Simple to use API

  • Support for both 4 bit and 8 bit modes

  • Python 2/3 compatible

Example

>>> from RPLCD import CharLCD
>>> lcd = CharLCD()
>>> lcd.write_string('Raspberry Pi HD44780')
>>> lcd.cursor_pos = (2, 0)
>>> lcd.write_string('http://github.com/\n\rdbrgn/RPLCD')
Photo of 20x4 LCD in action

Installing

(TLDR: Use pip install RPLCD)

Prerequisites

As prerequisite to build the RPIO dependency, you need the python-dev package. And to install the package itself, you’ll want to use pip. Both should already be installed on a regular Raspbian image. Otherwise, install them:

$ sudo apt-get install python-dev python-pip

Virtualenv Installation

I would recommend you to always use virtualenv and virtualenvwrapper when developing Python applications. This way, you have an isolated environment for each project, which prevents package version conflicts.

To install virtualenv and virtualenvwrapper:

$ sudo apt-get install virtualenvwrapper

Log out and back in to activate the virtualenvwrapper scripts. Then create a new virtualenv:

$ mkvirtualenv myproject

To enable the virtualenv, use workon myproject and to disable it use deactivate.

Then install the RPLCD library with its dependencies:

$ pip install RPLCD

Systemwide Installation

If you want you can also skip the virtualenv part and install the library system-wide. In that case just run pip as root:

$ sudo pip install RPLCD

Manual Installation

You can also install the library manually without pip. Either just copy the scripts to your working directory and import them, or download the repository and run python setup.py install to install it into your Python package directory.

Wiring

The standard wiring configuration uses the following pins (BOARD numbering scheme):

  • RS: 15

  • RW: 18

  • E: 16

  • Data 4-7: 21, 22, 23, 24

API

Init, Setup, Teardown

import RPIO
from RPLCD import CharLCD

# Initialize display. All values have default values and are therefore
# optional.
lcd = CharLCD(pin_rs=15, pin_e=16, pins_data=[21, 22, 23, 24],
              numbering_mode=RPIO.BOARD,
              cols=20, rows=4, dotsize=8)

...

# If desired, reset the GPIO configuration and optionally clear the screen.
# Note that this can lead to undesired effects on the LCD, because the GPIO
# pins are not configured as input or output anymore.
lcd.close(clear=True)

Properties

  • display_enabled -> True / False

  • cursor_pos -> (row, col)

  • text_align_mode -> Alignment.left / Alignment.right

  • write_shift_mode -> ShiftMode.cursor / ShiftMode.display

  • cursor_mode -> CursorMode.hide / CursorMode.line / CursorMode.blink

High Level Functions

  • write_string(value): Write the specified string to the display. You can use newline (\n) and carriage return (\n) characters.

  • clear(): Overwrite display with blank characters and reset cursor position.

  • home(): Set cursor to initial position and reset any shifting.

  • shift_display(amount): Shift the display. Use negative amounts to shift left and positive amounts to shift right.

Mid Level Functions

  • write(value): Send a raw command to the LCD.

  • command(value): Write a raw byte to the LCD.

Testing

To test your display, please run the test.py script and confirm/verify each step with the enter key. If you don’t use the standard wiring, make sure to add your pin numbers to the CharLCD constructor in test.py.

Resources

License

This code is licensed under the MIT license, see the LICENSE file or tldrlegal for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

RPLCD-0.1.tar.gz (9.1 kB view details)

Uploaded Source

File details

Details for the file RPLCD-0.1.tar.gz.

File metadata

  • Download URL: RPLCD-0.1.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for RPLCD-0.1.tar.gz
Algorithm Hash digest
SHA256 1fc19be5ee86a08486f4f4f19c1a8314556ef11790fe8278b8b2933d17b8b351
MD5 b0110182675608007ab2d68f10cc4a32
BLAKE2b-256 e57b1c0be177c3477ba6b1db0e5d584aba2f173840c25b4fc8c9de46f24591b7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page