Comments (11)
This repository and tutorial is 6 years old @Kyuchumimo, and Python 2.7 support was the norm, especially for the other libraries this is built upon. If you would like to write and support a Python 3 setup then we would be more than happy to incorporate those changes into the repo, as long as it maintains full backwards-compatibility.
from lcd.
from lcd.
what's your python version? will take a look at it tomorrow.
Python 3.7.3, using Thonny IDE
from lcd.
Python 3.7.3
the driver was written for (and tested with) Python 2.7, as in the original (Youtube) tutorial and scripts. it may work with Python 3.x but in this particular case, it will raise an error because Python 3 makes a distinction between bytes and strings, whereas Python 2 does not.
This should fix the problem:
62 ... try: 63 ... self.addr = int('0x{}'.format( 64 ... findall("[0-9a-z]{2}(?!:)", check_output(['/usr/sbin/i2cdetect', '-y', str(BUS_NUMBER), encoding='utf8']))[0]), base=16) \ 65 ... if exists('/usr/sbin/i2cdetect') else addr_default
the use of encoding='utf8'
in check_output
is a good one for Python 3 but it should be outside the square brackets:
check_output(['/usr/sbin/i2cdetect', '-y', str(BUS_NUMBER)], encoding='utf8')
I'd be happy to push such changes but the problem now is that encoding='utf8'
is not supported in the Python 2 version of check_output
.
can you think of an alternative that is compatible with both Python 2 and 3?
from lcd.
Sorry to put the encoding inside the brackets, it was a typo.
I can think of a solution, but that will be in a few hours, since I am not where I have my Raspberry Pi.
It occurs to me to use a separate function that changes the encoding.
from lcd.
Why would you still use python 2.7? Python 2 is deprecated. The latest version to date is Python 3.10
from lcd.
Are we still considering this a bug if this is a Python 3 compatibility issue @cgomesu ? Best to close this issue, or should we leave it open to clearly sign post?
from lcd.
It has more to do with compatibility than a bug
from lcd.
Done, this should fix the problem.
Works in both Python 2.7 and Python 3.7.3:
addr = int('0x{}'.format(
findall("[0-9a-z]{2}(?!:)", check_output(['/usr/sbin/i2cdetect', '-y', str(BUS_NUMBER)]).decode())[0]), base=16)
from lcd.
Are we still considering this a bug if this is a Python 3 compatibility issue @cgomesu ?
It has more to do with compatibility than a bug
I agree with you both. I added the bug label for quick reference because we do not have custom labels in this repo. I'll take care of that.
Best to close this issue, or should we leave it open to clearly sign post?
Let's wait for a fix from @Kyuchumimo. (See below.)
Done, this should fix the problem.
Works in both Python 2.7 and Python 3.7.3:addr = int('0x{}'.format( findall("[0-9a-z]{2}(?!:)", check_output(['/usr/sbin/i2cdetect', '-y', str(BUS_NUMBER)]).decode())[0]), base=16)
Thanks, @Kyuchumimo. I'll test the implementation when I get back home tomorrow. In the meantime, could you please submit a PR including only this change and linking to this issue?
from lcd.
check_output(['/usr/sbin/i2cdetect', '-y', str(BUS_NUMBER)]).decode())[0]
this change is compatible with both Python3 (3.7.3
) and Python2 (2.7.16
). tested on the following host:
Operating System: Raspbian GNU/Linux 10 (buster)
Kernel: Linux 5.10.63-v7+
Architecture: arm
waiting until the end of the week for @Kyuchumimo to submit a PR to the the-raspberry-pi-guy:master
branch. otherwise, I'll submit one on my own, credit them in the commit message, and close this issue (#33) upon merge. please let me know about any objections until then.
from lcd.
Related Issues (20)
- Flashing cursor HOT 2
- lcd/demo_lcd.py no longer exists, it has been renamed to lcd/demo_lcd_simple_string.py HOT 1
- smbus not reconized??? HOT 1
- smbus is not recognized HOT 20
- No module named smbus HOT 1
- No module named smbus HOT 4
- No module named smbus (sorry if not correct label..)
- Maintaining Python 2.7 compatibility moving forward HOT 1
- Favourite HOT 1
- Removal of the default 'pi' user
- turn off the lcd screen HOT 6
- > ```python
- module not imported running python script at startup raspberry pi /etc/profiles HOT 2
- Cannot run install.sh HOT 5
- would like the cpu/gpu temp display code HOT 3
- Display IP adress HOT 2
- Displaying the IP address shows a b' in front of IP address HOT 2
- demo_tiny_dashboard is broken as Theysaidso api is no longer public
- demo_forex.py is broken because requests is blocked by cloudflare HOT 1
- Omision on README about quotable.io quote length restrictions HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lcd.