orangepi-xunlong / wiringOP-Python

GNU Lesser General Public License v3.0
63 stars 34 forks source link

Issues using wiringOP-Python with Orange Pi Zero 2 #6

Open laserwelder opened 2 years ago

laserwelder commented 2 years ago

I'm a long term Raspberry Pi User, but given the current Raspberry Pi shortage, I recently bought an Orange Pi Zero 2 to try as an alternative.

Loading and running a Linux distro from the Orange Pi website went smoothly.

Using I2C and the UART went off without a hitch too, the instructions in the user manual to edit the boot environment have to be followed but once that is done standard python libraries for I2C (smbus) and serial communication (serial) work. I am guessing that the situation would be the same for SPI but I don't have an SPI device to test with.

Where the issues arose was using wiringOP-Python to access the GPIO pins directly. The manual describes installing a command line utility called GPIO This works well But the manual doesn't go into any detail on using the GPIO pins from inside a Python program. That is what the code hosted here addresses. However, I ran into a few issues using this code which took me a while to solve, I am going to post how to solve them here to help other newbies.

The first issue is that following the install instructions here does not result in Python3 being able to find the wiringpi module. I don't know if that is an issue with pip3 or the install instructions. But any python programs which try to import from wiringpi fail. This can be solved by inserting the following code in your program before trying to import wiringpi:

import sys sys.path.append("/usr/lib/python3.9/site-packages/wiringpi-2.60-py3.9-linux-aarch64.egg/')

You should check the exact path on your own system, no doubt this will change as packages and/or python are updated.

The second issue I ran into is that wiringpi will only run under root privileges. If you try to use it as an ordinary user you will get a permission denied type error message. The work around is to run any program using wiringpi with "sudo python3 your_program_name.py" rather than "python3 your_program_name.py". Running as root is undesirable but I have not found any other solution yet. I have tried changing permissions on "/dev/mem" to allow non-root access. This is also a potentially dangerous solution but in any case does not solve this issue.

I hope these notes help any other converts from Raspberry Pi land to get started more quickly than I did with an Orange Pi.

LunarLegionnaire commented 1 year ago

This is the post that ended 4 days of true suffering for me. Also running an OrangePi Zero2 H616 and it is not adding to path/able to find the module. Had to add: sys.path.insert(0,'/usr/lib/python3.9/site-packages/wiringpi-2.60.1-py3.9-linux-aarch64.egg/') Had a slight change in version number so if anyone in the future is facing same issue, check what version .egg your item is produced and adjust the path adding line accordingly.