Giter Site home page Giter Site logo

circuitpython_lcd's Introduction

Introduction

CircuitPython library for HD77480 LCD character displays with an I2C backpack. Currently PCF8574 is supported.

The original code started with the RPLCD library by Danilo Bargen, in https://github.com/dbrgn/RPLCD, but it has been reworked considerably.

On SAMD21 (M0) boards, lcd/lcd.py is too big to use as .py. Use mpy-cross to convert the .py files into .mpy. Also, use the minimal branch, to save space, if you don't need all the features in the main branch.

Usage Example

The LCD supports character LCDs using the HD77480 chip.

The interface to the LCD is separated into an Interface class. Currently there is only one such class: I2CPCF8574Interface.

import board

from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface

from lcd.lcd import CursorMode

# Talk to the LCD at I2C address 0x27.
# The number of rows and columns defaults to 4x20, so those
# arguments could be omitted in this case.
lcd = LCD(I2CPCF8574Interface(board.I2C(), 0x27), num_rows=4, num_cols=20)

lcd.print("abc ")
lcd.print("This is quite long and will wrap onto the next line automatically.")

lcd.clear()

# Start at the second line, fifth column (numbering from zero).
lcd.set_cursor_pos(1, 4)
lcd.print("Here I am")

# Make the cursor visible as a line.
lcd.set_cursor_mode(CursorMode.LINE)

circuitpython_lcd's People

Contributors

dhalbert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

circuitpython_lcd's Issues

Running lcd.clear() gives random chars

Whenever I run the command lcd.clear() in my code my LCD gets all messed up and I can't print anything else to it. I'm running on a Feather m4 express (Adafruit CircuitPython 3.1.2 on 2019-01-07; Adafruit Feather M4 Express with samd51j19) and using a PCF8574 backpack with a HD44780 lcd. Here's my code:

from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface

from lcd.lcd import CursorMode
from time import sleep

lcd = LCD(I2CPCF8574Interface(0x27), num_rows=2, num_cols=16)

counter = 0
lcd.print('Hello World')

while True:
    lcd.print(str(round(counter, 2)))
    counter += 1
    sleep(1)
    lcd.clear()

I'm import your packages from this commit here

P.S.
This module is fantastic for those who don't buy the specific adafruit backpacks

backlight control doesn't work

Thanks for this library- I'm finding it easy to use!

I'm just playing with my new toy (Pi Pico) + pcf8574 i2c module, using the latest stable CircuitPython.

I tried to turn off/on the back light but got _BACKLIGHT_VALUES undefined erro in i2c_pcf8574_interface.py.

I modified it to:

    @backlight.setter
    def backlight(self, value):
        self._backlight_pin_state = I2CPCF8574Interface._BACKLIGHT_VALUES[value]
        self._i2c_write(self._backlight_pin_state)

but now get:

  File "/lib/lcd/lcd.py", line 158, in set_backlight
  File "/lib/lcd/i2c_pcf8574_interface.py", line 71, in backlight
  File "/lib/lcd/i2c_pcf8574_interface.py", line 96, in _i2c_write
RuntimeError: Function requires lock

My code:

lcd.set_backlight(False)

I'm new to i2c via CircuitPython, so not sure what to try next.

Custom characters not working

Hi, Im running pi pico with this library to drive my 20x4 char lcd with PCF8574 bit expander on board and im having problems with displaying custom characters. The REPL console returns "can't convert 'int' object to str implicitly" every time i pass bytearray to the function

time.sleep not accurate, i2c writes not working on ARM M4

The library, specifically in the _write4bits() function, uses time.sleep() to create sub-millisecond delays, however (at least in CircuitPython 4), the time.sleep() is a wrapper around a function that accepts integer milliseconds (with some issues at that), and thus can't produce shorter delays (except an immediate return). On a 120 MHz M4, the minimal delay the function creates (about 10 usec, I estimate) is not long enough for successful I2C transfers. Some alternative delay for <1 msec perhaps should be swapped in.

Unable to lcd.print variables

Your work has allowed me to use a LCD with PCF8547 I2C backpack - Thank you.

I'm new to CircuitPython so please forgive me if this is a silly question. Although I am able to print characters such as, lcd.print("Hello World!"), I am unable to print a variable. For example, in the following I am unable to print the 'test' variable (line numbers added for reference):

1 import board
2 from lcd.lcd import LCD
3 from lcd.i2c_pcf8574_interface import I2CPCF8574Interface
4 from lcd.lcd import CursorMode
5 lcd = LCD(I2CPCF8574Interface(board.I2C(), 0x27), num_rows=4, num_cols=20)
6 lcd.clear()
7
8 test = 1975
9 lcd.set_cursor_pos(1, 4)
10 lcd.print("Hello World!")
11 lcd.set_cursor_pos(3, 4)
12 lcd.print(test)

The LCD writes "Hello World!" but an error shows on Mu REPL. The error reads:

File "cope.py", line 12, in
File "/lib/lcd/lcd.py", line 195, in print
TypeError: 'int' object is not iterable

Any insight is gratefully received, many thanks.

Pi PICO support

The Pico has configurable SPI pins.

Adafruit has a straight forward explanation: https://learn.adafruit.com/getting-started-with-raspberry-pi-pico-circuitpython/pinouts - scroll down the the i2c section.

Easy hack-fix is to change i2c_pcf8574_interface.py:

        #  self.i2c = busio.I2C(board.SCL, board.SDA)
        # Pi PICO Hack
        self.i2c = busio.I2C(scl=board.GP1, sda=board.GP0)

A better/simple fix is probably to add scl and sda parameters to __init__ with default values of board.SCL and board.SDA respectively.

/lib/lcd/lcd.py: IndexError: index out of range

i have circuitpython 9 and yd-rp2040, there is a full text of error:
Traceback (most recent call last):
File "", line 13, in
File "/lib/lcd/lcd.py", line 199, in print
File "/lib/lcd/lcd.py", line 288, in write
File "/lib/lcd/lcd.py", line 181, in set_cursor_pos
IndexError: index out of range

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.