dbrgn / RPLCD

A Raspberry Pi LCD library for the widely used Hitachi HD44780 controller, written in Python. GPIO (parallel) and I²C modes supported.
https://rplcd.readthedocs.io/en/latest/
MIT License
262 stars 72 forks source link

feat: support smbus2 as drop-in replacement for I2C #90

Closed joscha closed 5 years ago

joscha commented 5 years ago

closes #89

joscha commented 5 years ago

changes in @dbrgn

dbrgn commented 5 years ago

Great, thank you :slightly_smiling_face:

joscha commented 5 years ago

\o/ any chance for a release with this change? Cheers!

dbrgn commented 5 years ago

Yeah, I'll try to remember to do one tonight :slightly_smiling_face:

By the way, I noticed that in the tests I'm using smbus-cffi. That might have worked too, as it seems to be a CFFI based pure-python smbus binding with the same package name. But I guess with smbus2 you're better off.

@joscha did you already test whether the smbus2 based RPLCD works on an actual LCD?

joscha commented 5 years ago

By the way, I noticed that in the tests I'm using smbus-cffi. That might have worked too

ah, I missed that, sorry.

@joscha did you already test whether the smbus2 based RPLCD works on an actual LCD?

I tried in a fork via git+https://github.com/joscha/RPLCD.git@joscha/smbus2#egg=RPLCD, but would only get:

Traceback (most recent call last):
  File "src/main.py", line 1, in <module>
    from RPLCD.i2c import CharLCD
  File "/usr/local/lib/python3.6/site-packages/RPLCD/i2c.py", line 28, in <module>
    from .lcd import BaseCharLCD
  File "/usr/local/lib/python3.6/site-packages/RPLCD/lcd.py", line 27, in <module>
    from . import codecs
ImportError: cannot import name 'codecs'

I put that down to some problem with the git-based packaging.I've successfully used Matt Hawkin's script: https://bitbucket.org/MattHawkinsUK/rpispy-misc/raw/master/python/lcd_i2c.py with smbus2 instead of smbus and that worked, so I was assuming RPLCD would do the same. If you are worried you could do a named pre-release that I can test with?

dbrgn commented 5 years ago

Hm, yeah, I would have assumed that this works...

I'll simply put out the next version, and in the unlikely event that something breaks we can always create a patch release :slightly_smiling_face:

dbrgn commented 5 years ago

Version 1.2.0 is released. Testing would be very welcome!

If everything went right, you should now also have the rplcd-tests script available when installing the package via pip.

joscha commented 5 years ago

works a charm, tried via the testsuite 👍

dbrgn commented 5 years ago

Great to hear, thanks for testing @joscha :slightly_smiling_face: