OnionGpio for Python3
-
@Neil-Stelling is there any update on how to get GPIO to work for python3?
-
@Neil-Stelling,
Hi guys!
I have solved this problem.
See please for this repository https://github.com/OnionIoT/onion-gpio-sysfs/tree/master/python
You need the onionGpio.py file. But this file for Python2.x version. You must change all code line like "print xxxxxx" for "print(xxxxxx)". For example: "print 'GPIO%d path: %s'%(self.gpio, self.path)" change to "print ('GPIO%d path: %s'%(self.gpio, self.path))".
After that put this file to your project (or in Python PATH) and use it according to the instruction:
https://docs.onion.io/omega2-docs/gpio-python-module.html
-
I know this is old. However, still needed as I cannot find a python3 module.
Thanks for this post which solved my problem.
Regds,
Dave
-
I guess there is no resolution to this? It's now nearly 2 years since python2 went end-of-life so I find it a bit strange that Onion doesn't provide a python3 version of this module.
-
@phzdw Onion published the code to their python gpio module. Open source providers like Onion release their code so developers can collaborate on improvements and updates. This model allows companies such as Onion to push forward on new products rather than be tied down maintaining older code. This is the basic principle of the commercial open source model.
-
Ok, but Python3 I would not consider to be 'older code'.
I would think, with Pi's impossible to find, and otherwise the Omega2+ looking like a good alternative, that some emphasis might be placed on a Python3 GPIO library. I do not have any (of many) Pi programs running that don't use GPIO's in some fashion.I'll try the Python2.x solution above (but I don't care for it much).
-
@Jim-W reposting response from this thread:
pyOnionGpio was written as a quick and dirty wrapper for the sysfs gpio interface. I wouldn't recommend using it for anything other than a hello world.
There are other (likely better) sysfs gpio libraries available for Python3:
https://pypi.org/project/gpio/
https://python-periphery.readthedocs.io/en/latest/gpio.html
https://github.com/vitiral/gpio
Let us know how it goes!
-
@Lazar-Demin Perhaps this could be a FAQ as it comes up a bit recently
-
@crispyoz good idea! Added FAQ post here: https://community.onion.io/topic/4834/faq-how-can-i-control-the-gpios-from-python-is-there-an-oniongpio-module-for-python3
-
Solved.
I found gpio-sysfs from https://pypi.org/project/onion-gpio-sysfs/ to work.