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 Orange Pi 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 WiringOP-Python module posted on GitHub 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 on GitHub 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 an 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 it does not solve this issue. If you want to program from a GUI IDE like Thonny then you have to start Thonny as root before running a python program using wiringpi. I.E. in a terminal, type: sudo thonny rather than starting thonny from your desktop. I hope these notes help any other converts from Raspberry Pi land to get started more quickly than I did with an Orange Pi.
|