Giter VIP home page Giter VIP logo

adafruit_circuitpython_charlcd's Introduction

Introduction

Documentation Status

Discord

Build Status

Code Style: Black

This library is compatible with standard Character LCDs such as:

Installing from PyPI

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:

pip3 install adafruit-circuitpython-charlcd

To install system-wide (this may be required in some cases):

sudo pip3 install adafruit-circuitpython-charlcd

To install in a virtual environment in your current project:

mkdir project-name && cd project-name
python3 -m venv .venv
source .venv/bin/activate
pip3 install adafruit-circuitpython-charlcd

Dependencies

This driver depends on:

I2C & SPI displays also depend on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.

Usage Example

The Character_LCD class interfaces a predefined Character LCD display with CircuitPython.

import board
import digitalio
import adafruit_character_lcd.character_lcd as character_lcd

You must define the data pins (RS, EN, D4, D5, D6, D7) in your code before using the Character_LCD class. If you want to have on/off backlight functionality, you can also define your backlight as lcd_backlight. Otherwise, the backlight will always remain on. The following is an example setup.

lcd_rs = digitalio.DigitalInOut(board.D7)
lcd_en = digitalio.DigitalInOut(board.D8)
lcd_d7 = digitalio.DigitalInOut(board.D12)
lcd_d6 = digitalio.DigitalInOut(board.D11)
lcd_d5 = digitalio.DigitalInOut(board.D10)
lcd_d4 = digitalio.DigitalInOut(board.D9)
lcd_backlight = digitalio.DigitalInOut(board.D13)

You must also define the size of the CharLCD by specifying its lcd_columns and lcd_rows:

lcd_columns = 16
lcd_rows = 2

After you have set up your LCD, we can make the device by calling it

lcd = character_lcd.Character_LCD_Mono(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_backlight)

To verify that your pins are correct, print a hello message to the CharLCD:

lcd.message = "Hello\nCircuitPython"

Custom character example with create_char() is provided within /examples/

Documentation

API documentation for this library can be found on Read the Docs.

For information on building library documentation, please check out this guide.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

adafruit_circuitpython_charlcd's People

Contributors

asherlie avatar brennen avatar brentru avatar caternuson avatar chadkuester avatar dhalbert avatar evaherrada avatar foamyguy avatar jepler avatar jposada202020 avatar kattni avatar khavik avatar ladyada avatar lesamouraipourpre avatar makermelissa avatar mrmcwethy avatar neradoc avatar profbrady avatar siddacious avatar sommersoft avatar tannewt avatar taotien avatar tdicola avatar tekktrik avatar tim-jackins 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_circuitpython_charlcd's Issues

MemoryError on Metro M0 Express

Re:
https://forums.adafruit.com/viewtopic.php?f=63&t=149682

Can recreate with following:

Adafruit CircuitPython 3.1.2 on 2019-01-07; Adafruit Metro M0 Express with samd21g18
>>> import board, busio
>>> import adafruit_character_lcd.character_lcd_i2c as character_lcd
>>> i2c = busio.I2C(board.SCL, board.SDA)
>>> lcd = character_lcd.Character_LCD_I2C(i2c, 20, 4)
>>> lcd.message = "Hello\nCircuitPython"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "adafruit_character_lcd/character_lcd.py", line 338, in message
MemoryError: memory allocation failed, allocating 160 bytes
>>> 

But seems to work on M4:

Adafruit CircuitPython 3.1.2 on 2019-01-07; Adafruit Metro M4 Express with samd51j19
>>> import board, busio
>>> import adafruit_character_lcd.character_lcd_i2c as character_lcd
>>> i2c = busio.I2C(board.SCL, board.SDA)
>>> lcd = character_lcd.Character_LCD_I2C(i2c, 20, 4)
>>> lcd.message = "Hello\nCircuitPython"
>>> 

LCD with i2c backpack blinks but no text

Hello

I am having issues getting a 16x2 LCD display with an i2c backpack to work. When I power/start up, the LCD backlight blinks for about one second displaying no text, it then turns off for the 5 second sleep command, and then quickly blinks again for a fraction of a second.

The LCD works perfectly with my Arduino but not the M4. I have replaced the wiring. I have substituted for a different Metro M4 express board (I have a few on hand). No success.

I am using CircuitPython 6.1.0 and a freshly downloaded CircuitPython library bundle 6.x 20210303 with an Adafruit Metro M4 express board (ie: the purple ones).

My test code follows.

import board
import busio
import time
import adafruit_character_lcd.character_lcd_i2c as character_lcd

i2c = busio.I2C(board.SCL, board.SDA)
lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2, address=0x27)
lcd.display = True
lcd.backlight = True
lcd.message = "Hello\nCircuitPython!"
time.sleep(5)
lcd.clear()

Any advice is appreciated.

Row Offsets for 16x4 display.

Hello,

I am trying to use this library with a 16x4 character display. Looking at the code (snippet below) there are hardcoded offsets for the third and fourth rows, with the third row starting at 0x14 (20) and the fourth at 0x54 (84, 20 addresses along from the start of row 2).

# Offset for up to 4 rows.
_LCD_ROW_OFFSETS = (0x00, 0x40, 0x14, 0x54)

This would make sense for a 20x4 LCD. However, for my particular display, row 3 starts at 0x10 (16) and row 4 at 0x50 (80, 64+16). I imagine this would be the case with almost all displays, with the offsets equal to the number of characters in each row.

I had expected the columns and lines arguments to Character_LCD_Mono to automatically handle the offsets for me. My workaround is to modify the class level _LCD_ROW_OFFSETS at runtime:

import adafruit_character_lcd.character_lcd as characterlcd
characterlcd._LCD_ROW_OFFSETS = (0x00, 0x40, 0x14-4, 0x54-4)

If there a better way to go about this? If not, would it be possible to add proper support? Perhaps the calculated offsets could be exposed as a property that can be changed for screens that work differently?

While using the i2c/SPI LCD Backpack Maximum recursion depth exceeded

While using the i2c/SPI LCD Backpack Maximum recursion depth exceeded.

Adafruit CircuitPython 7.0.0 on 2021-09-20; Adafruit Metro M0 Express with samd21g18

Traceback (most recent call last):
File "main.py", line 1, in
File "adafruit_character_lcd/character_lcd_i2c.py", line 31, in
File "adafruit_mcp230xx/mcp23008.py", line 16, in
File "adafruit_mcp230xx/mcp230xx.py", line 16, in
File "adafruit_mcp230xx/mcp23xxx.py", line 14, in
File "adafruit_bus_device/i2c_device.py", line 14, in
RuntimeError: maximum recursion depth exceeded

import time
import board
import busio
import adafruit_character_lcd.character_lcd_i2c as character_lcd


lcd_columns = 20
lcd_rows = 4

i2c = busio.I2C(board.SCL, board.SDA)

lcd = character_lcd.Character_LCD_I2C(i2c, lcd_columns, lcd_rows)

https://github.com/adafruit/Adafruit_CircuitPython_MCP230xx
https://github.com/adafruit/Adafruit_CircuitPython_BusDevice/blob/main/adafruit_bus_device/i2c_device.py

ValueError: incompatible .mpy file

I tried using charlcd_i2c class in my circuitpython code, and all it says is just incompatible .mpy file. I tried all solutions, including rolling back to an older bundle from 6.x, and none of that seems to work.

Missing Type Annotations

There are missing type annotations for some functions in this library.

The typing module does not exist on CircuitPython devices so the import needs to be wrapped in try/except to catch the error for missing import. There is an example of how that is done here:

try:
    from typing import List, Tuple
except ImportError:
    pass

Once imported the typing annotations for the argument type(s), and return type(s) can be added to the function signature. Here is an example of a function that has had this done already:

def wrap_text_to_pixels(
    string: str, max_width: int, font=None, indent0: str = "", indent1: str = ""
) -> List[str]:

If you are new to Git or Github we have a guide about contributing to our projects here: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github

There is also a guide that covers our CI utilities and how to run them locally to ensure they will pass in Github Actions here: https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/check-your-code In particular the pages: Sharing docs on ReadTheDocs and Check your code with pre-commit contain the tools to install and commands to run locally to run the checks.

If you are attempting to resolve this issue and need help, you can post a comment on this issue and tag both @FoamyGuy and @kattni or reach out to us on Discord: https://adafru.it/discord in the #circuitpython-dev channel.

The following locations are reported by mypy to be missing type annotations:

  • adafruit_character_lcd/character_lcd_spi.py:56
  • adafruit_character_lcd/character_lcd_i2c.py:55
  • adafruit_character_lcd/character_lcd_rgb_i2c.py:65
  • adafruit_character_lcd/character_lcd.py:76
  • adafruit_character_lcd/character_lcd.py:87
  • adafruit_character_lcd/character_lcd.py:118
  • adafruit_character_lcd/character_lcd.py:196
  • adafruit_character_lcd/character_lcd.py:225
  • adafruit_character_lcd/character_lcd.py:232
  • adafruit_character_lcd/character_lcd.py:275
  • adafruit_character_lcd/character_lcd.py:305
  • adafruit_character_lcd/character_lcd.py:338
  • adafruit_character_lcd/character_lcd.py:451
  • adafruit_character_lcd/character_lcd.py:468
  • adafruit_character_lcd/character_lcd.py:486
  • adafruit_character_lcd/character_lcd.py:543
  • adafruit_character_lcd/character_lcd.py:597
  • adafruit_character_lcd/character_lcd.py:625
  • adafruit_character_lcd/character_lcd.py:693

Error in docs

This may not be the place, but I can't quickly find the source for the website online. Just beneath here in the Character LCDs docs, there is a typo regarding the wiring of an LCD with an RGB backlight (second example). It says

Pi GND to LCD pin 1, 5, 16, and the opposite side of the potentiometer.

but for the RGB backlit device, LCD pin 16 controls the red backlight.

Presumably it was just pasted from the first example ๐Ÿ˜„

Unresolved import

When trying to import this package with

import adafruit_character_lcd.character_lcd as characterlcd

I receive a pylint error saying unresolved import. I have install the package with the command

sudo pip3 install adafruit-circuitpython-charlcd

Not sure where to go from here. I would like to use an LCD with my RPi so I was hoping to make use of this package. I am using VSCode and Python 3.6.

Feature request - Begin message at cursor position

Currently, when you call lcd.message it begins the message at the beginning of the line. This is by design.

There was an issue filed on the Python library requesting the ability to "disable cursor shift". The desired result is that the cursor stay at the position set by cursor_position when message is called.

One option we can consider is adding another version of message that does not reset to the beginning of the line for each new message.

RemoteDisconnect Issue

Hi,

About four days I noticed that the library was not downloading properly through pip 3. I get the following message:

Exception:
Traceback (most recent call last):
  File "/usr/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 594, in urlopen
    chunked=chunked)
  File "/usr/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 391, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "/usr/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 387, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.5/http/client.py", line 1198, in getresponse
    response.begin()
  File "/usr/lib/python3.5/http/client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.5/http/client.py", line 266, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/lib/python3/dist-packages/pip/commands/install.py", line 353, in run
    wb.build(autobuilding=True)
  File "/usr/lib/python3/dist-packages/pip/wheel.py", line 749, in build
    self.requirement_set.prepare_files(self.finder)
  File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 620, in _prepare_file
    session=self.session, hashes=hashes)
  File "/usr/lib/python3/dist-packages/pip/download.py", line 821, in unpack_url
    hashes=hashes
  File "/usr/lib/python3/dist-packages/pip/download.py", line 659, in unpack_http_url
    hashes)
  File "/usr/lib/python3/dist-packages/pip/download.py", line 853, in _download_http_url
    stream=True,
  File "/usr/share/python-wheels/requests-2.12.4-py2.py3-none-any.whl/requests/sessions.py", line 501, in get
    return self.request('GET', url, **kwargs)
  File "/usr/lib/python3/dist-packages/pip/download.py", line 386, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
  File "/usr/share/python-wheels/requests-2.12.4-py2.py3-none-any.whl/requests/sessions.py", line 488, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/share/python-wheels/requests-2.12.4-py2.py3-none-any.whl/requests/sessions.py", line 609, in send
    r = adapter.send(request, **kwargs)
  File "/usr/share/python-wheels/CacheControl-0.11.7-py2.py3-none-any.whl/cachecontrol/adapter.py", line 47, in send
    resp = super(CacheControlAdapter, self).send(request, **kw)
  File "/usr/share/python-wheels/requests-2.12.4-py2.py3-none-any.whl/requests/adapters.py", line 423, in send
    timeout=timeout
  File "/usr/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 643, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl/urllib3/util/retry.py", line 315, in increment
    total -= 1
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'

I've tried with many Pis and different Wifi connections. Any help would be appreciated.

Character_LCD set_backlight function is backwards

If you pass True, the value is set to 0 (False) turning the backlight off and you must pass False to turn it on.

Additionally, a quick review of the init function defaults the self.backlight member to None which will cause an exception if you don't pass in the pin and attempt to call set_backlight since None has no 'value' member.

def set_backlight(self, lighton):
      """ Set lighton to turn the charLCD backlight on.
            :param lighton: True to turn backlight on, False to turn off
      """
      if lighton:
        self.backlight.value = 0
      else:
        self.backlight.value = 1

Could not display degree sign properly

I tried to use your driver to display a string with degree sign in it. The string I tried to display is

uString = 'Temp: 30' + u'\N{DEGREE SIGN}' + 'C'
print (uString) shows: Temp: 30ยฐC
However, the following code only shows: Temp: 30-C
lcd.message = uString

It is run on a Raspberry PI4 with latest Raspbian and python 3.7.3.

Rasberry pico

It does not work on Rasberry pico.
I am using
i2c = busio.I2C(board.GP1,board.GP0)

Doesn't work with PCF8574?

I haven't been able to get this library working with the PCF8574 backpack. I assume it's designed to work with the Adafruit backpack and that's why it's not working? Anyways it might be nice to add support or point to this guys repo: dhalbert/CircuitPython_LCD.

Sending Digit 2 Turns Backlight Off

The following is running on Raspberry Pi Pico 2040, a 20x4 LCD display and the Adafruit I2C/SPI LCD Backpack:

import time
import board
import busio
import digitalio
import adafruit_character_lcd.character_lcd_spi as character_lcd

lcd_columns = 20
lcd_rows = 4

clk = board.GP2
data = board.GP3
latch = board.GP1

spi = busio.SPI(clk, MOSI = data, MISO = None)

latch = digitalio.DigitalInOut(latch)
lcd = character_lcd.Character_LCD_SPI(spi, latch, lcd_columns, lcd_rows)

lcd.backlight = True
# Displaying the number 1 on the display acts as expected, the backlight is on.
lcd.message = "1"
time.sleep(5)
#Sending the digit 2 will turn the backlight off and it cannot be turned back on.
lcd.message = "2"
lcd.backlight = True

I have tried various combinations of turning the backlight back on, clearing the display and nothing seems to work.

Library uses short argument names

pylint suggests using argument names with at least 3 letters. This library uses argument names of shorter length, and while these warnings have been disabled for now, they should be considered for renaming. This may require the rework of Learn Guides and other references to code snippets.

When using digitalio for RGB control on RPi, list values must be more than 1 to actually turn on corresponding LED

pip freeze
Adafruit-Blinka==5.3.2
adafruit-circuitpython-charlcd==3.3.3

Input

import adafruit_character_lcd.character_lcd as characterlcd
import board
import digitalio

lcd_rs = digitalio.DigitalInOut(board.D4)
lcd_en = digitalio.DigitalInOut(board.D19)
lcd_d7 = digitalio.DigitalInOut(board.D27)
lcd_d6 = digitalio.DigitalInOut(board.D22)
lcd_d5 = digitalio.DigitalInOut(board.D24)
lcd_d4 = digitalio.DigitalInOut(board.D25)
lcd_cols = 16
lcd_rows = 2
red = digitalio.DigitalInOut(board.D21)
green = digitalio.DigitalInOut(board.D12)
blue = digitalio.DigitalInOut(board.D18)
lcd = characterlcd.Character_LCD_RGB(
    lcd_rs,
    lcd_en,
    lcd_d4,
    lcd_d5,
    lcd_d6,
    lcd_d7,
    lcd_cols,
    lcd_rows,
    red,
    green,
    blue)

RED = [1, 0, 0]
GREEN = [0, 1, 0]
BLUE = [0, 0, 1]

lcd.color = GREEN

Expected outcome

LCD backlight is bright green

Actual outcome

LCD backlight stays dark/off

Current workaround

Set values for RED, GREEN, BLUE to anything more than 1, such as 2, or 100. The outcomes are all the same as long as it's >1.
Overall this isn't much of an issue as pulseio.PWMOut() has been patched already and works.

Name Mismatch in Circup

To install with circup use:

circup install adafruit-circuitpython-character-lcd

Would be nice if pypi and circup used the same name.

pip3 install adafruit-circuitpython-charlcd

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.