项目作者: AllanGallop

项目描述 :
A simple module for working with the HD44780 LCD over I²C using the PCF8574 Backpack
高级语言: Python
项目地址: git://github.com/AllanGallop/RPi_GPIO_i2c_LCD.git
创建时间: 2019-06-23T10:36:56Z
项目社区:https://github.com/AllanGallop/RPi_GPIO_i2c_LCD

开源协议:GNU General Public License v3.0

下载


RPi_GPIO_i2c_LCD

HD44780 / PCF8574 LCD Module

View on PyPi.org

Sections

  • Description
  • Features
  • Install
  • Usage

Description

A simple module for working with the HD44780 LCD over I²C using the PCF8574 Backpack

Features

  • Non-Blocking update loop
  • Supports 2x16 and 4x20 Displays
  • Easy to use
  • Callback loop for updating display directly

Install

Make sure i2c is enabled! sudo raspi-config

Using PyPi:

  1. pip3 install RPi-GPIO-I2C-LCD

Usage

set(string,line)

Sets string to given line

get(line)

Returns string of given line from buffer

backlight(on|off)

Turns backlight on or off (default is on)

clear()

Clears display buffers

Examples

Simple
  1. from RPi_GPIO_i2c_LCD import lcd
  2. from time import sleep
  3. ## Address of backpack
  4. i2c_address = 0x27
  5. ## Initalize display
  6. lcdDisplay = lcd.HD44780(i2c_address)
  7. ## Set string value to buffer
  8. lcdDisplay.set("Hello",1)
  9. lcdDisplay.set("World",2)
  10. sleep(1)

Callback Loop

  1. from RPi_GPIO_i2c_LCD import lcd
  2. from time import sleep, strftime
  3. ## Callback function that will run on every display loop
  4. def MyFunction(self):
  5. ## Show current time on line 2
  6. self.lcd.display_string(str(strftime("%d/%m %H:%M:%S").center(20,' ')),2)
  7. ## Initalize display with callback
  8. lcdDisplay = lcd.HD44780(0x27,MyFunction)
  9. ## Set string value to buffer
  10. lcdDisplay.set("The time is:",1)
  11. sleep(6)

Backlight

  1. from RPi_GPIO_i2c_LCD import lcd
  2. from time import sleep
  3. ## Address of backpack
  4. i2c_address = 0x27
  5. ## Initalize display
  6. lcdDisplay = lcd.HD44780(i2c_address)
  7. ## Set string value to buffer
  8. lcdDisplay.set("Hello",1)
  9. lcdDisplay.set("World",2)
  10. while(True):
  11. lcdDisplay.backlight("off")
  12. sleep(1)
  13. lcdDisplay.backlight("on")
  14. sleep(1)