OnionGpio for Python3
New user, and apologies if this question has been asked before (must have been).
Python3 has been out for years, and there's no reason anyone should use Python2... and yet... I've installed python3-light but struggle to find a Python3 version of the Onion basic package for controlling gpio ? Don't want a Python2 version, when I'm using Python3. Could someone help me please ? Got some technical knowledge but not a lot, and get annoyed when I go through Omega documentation and find numerous inconsistencies and non-working code...
Douglas Kryder last edited by
@Neil-Stelling if i remember correctly you need to uncomment some of the repos in the /etc/opkg/distfeeds.conf repo file. maybe one of the lede repos but you might search on it.
@Neil-Stelling is there any update on how to get GPIO to work for python3?
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:
I know this is old. However, still needed as I cannot find a python3 module.
Thanks for this post which solved my problem.
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).
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:
@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
I found gpio-sysfs from https://pypi.org/project/onion-gpio-sysfs/ to work.