Diablo and Python 3
Forums:
It seems like WebIOPi is using Python 3, this causes two problems when using the Diablo library:
- The old Python 2 style print statement is no longer correct
- It will not be able to import smbus as it is only available for Python 2.X by default
The first problem is easy to fix, it simply requires a version using the correct print statements
cd ~/diablo wget -O Diablo3.py http://piborg.org/downloads/diablo/Diablo3.py.txt
To use this version you will need to change the import statement to
import Diablo3 as Diablo
Then you can use it normally.
The second problem is a bit more tricky, what we can do is rebuild smbus for Python 3 by making some small changes to the source:
cd ~ sudo apt-get -y install python3-dev wget http://ftp.de.debian.org/debian/pool/main/i/i2c-tools/i2c-tools_3.1.0.orig.tar.bz2 tar xf i2c-tools_3.1.0.orig.tar.bz2 cd i2c-tools-3.1.0/py-smbus mv smbusmodule.c smbusmodule.c.orig wget -O smbusmodule.c http://piborg.org/downloads/picoborgrev/smbusmodule.c.txt wget http://lm-sensors.org/svn/lm-sensors/tags/V2-10-8/kernel/include/i2c-dev.h python3 setup.py build sudo python3 setup.py install
This should make the smbus module available to Python 3, and hopefully make everything work happily.
jasontimothyjones
Fri, 09/14/2018 - 13:22
Permalink
lm-sensors files
when running these changes, at line 8 the link to lm-sensors.org seems to time out, I have found another ver of the file on GitHub, I am at work right now so can't test it out, but I assume it will work,
file is here.
I wonder if this is also the reason I am having problems with my PS4 controller
https://github.com/Distrotech/i2c-tools/blob/distrotech-i2c-tools/includ...
jasontimothyjones
Fri, 09/14/2018 - 17:03
Permalink
Solved
After many hours of scratching everything I have, the issue was resolved with 1 line
from
http://www.linuxcircle.com/2015/05/03/how-to-install-smbus-i2c-module-fo...
piborg
Fri, 09/14/2018 - 19:41
Permalink
Great :)
Glad to hear you found a solution :)
We are planning to make our examples work with both Python 2 and 3 in the near future. When we do we will also update the install scripts to setup both Python 2 and Python 3 correctly. This should remove the need to make changes to the scripts for those who prefer to use Python 3.
jasontimothyjones
Fri, 09/14/2018 - 22:06
Permalink
brilliant, let me know if I
brilliant, let me know if I can help, im going to delete everything over the weekend and repeat what I have done to make sure I have got it right, and ill document each step for myself... remembering I have no Idea what I am doing
Redhell1000
Fri, 04/12/2019 - 20:02
Permalink
I have tried using the link
I have tried using the link to the tar file (http://ftp.de.debian.org/debian/pool/main/i/i2c-tools/i2c-tools_3.1.0.or...) however, it seems the link is broken. (404) error. Has the link been updated or is there another way to get the smbus to work with python3
piborg
Sat, 04/13/2019 - 11:26
Permalink
Have you tried python3-smbus?
Have you tried the alternative shared by jasontimothyjones above?
Redhell1000
Sat, 04/13/2019 - 15:52
Permalink
Yes I tried that and that
Yes I tried that and that threw an error as well saying something like IOError on smbus.SMbus
piborg
Sat, 04/13/2019 - 16:40
Permalink
Can you find out what the exact error is
If you have the smbus module already compiling it from source is unnecessary and will not help.
Can you re-run the script and find out what the exact error message is? A screenshot will be fine :)
Redhell1000
Tue, 04/16/2019 - 16:10
Permalink
Here is the screenshot of the
Here is the screenshot of the error we get after using the smbus module obtained from sudo apt-get install python3-smbus via the diablo3 library on this page. (We have tested with python2 and it works)
piborg
Tue, 04/16/2019 - 18:24
Permalink
Not a Diablo error (ID 00)
The problem is fairly early on in the script:
This means it can see the Diablo, but it is reading back the wrong values from the board.
I have attached a new version of the Diablo library we have been working on below that does not use the SMBus library at all. If you can download it and see if things start working correctly.
The import code will now be:
You can download the new script to your Pi directly with these commands:
Redhell1000
Tue, 04/16/2019 - 23:44
Permalink
Works Perfect
Thank you that works perfectly