View: 9065|Reply: 21

Getting started with GPIO on Orange Pi Zero 2 in Python

[Copy link]

1

threads

2

posts

13

credits

Novice

Rank: 1

credits
13
Published in 2022-9-8 09:15:58 | Show all floors |Read mode
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.

1

threads

2

posts

13

credits

Novice

Rank: 1

credits
13
 Author| Published in 2022-9-23 05:29:49 | Show all floors
Narly9999Published in 2022-9-18 10:07
Saw this on ARMBIAN.  Links to a how to section.

Yes I tried Armbian when I ran into difficulties getting started with the Orange Pi Zero 2.  My motivation for installing Armbian was to get the O Pi Zero 2 running with the Adafruit Blinka library.  This looks like a good approach to getting non Raspberry Pi board working with a number of peripherals. However I ran into a number of issues.  Here is what I learnt.

First, the latest version of Armbian listed on the Armbian website for the O Pi Zero 2 will not boot, you have to install an older version.  This is a known issue.  Once you install an earlier version it will boot, but you are stuck with a command line interface, they don't have a GUI distro for the O Pi Zero 2.  For a newbie, having to do everything from the command line is inconvenient, but I stuck with it.


Second, despite following all the instructions on the Adafruit website faithfully, starting from my fresh install of Armbian, the installation process threw up some numeros error messages, and I was unable to get Adafruit Blinka working.

In the end I concluded that getting the Orange Pi Zero 2 working with GPIO was best done with the wiringpi library.  Once I got over the issues with Python3 not being able to find the wiringpi instalation, and realising the any program using wiringpi has to be run as root, I was able to access GPIO.





1

threads

3

posts

15

credits

Novice

Rank: 1

credits
15
Published in 2023-7-17 16:28:51 | Show all floors

0

threads

4

posts

12

credits

Novice

Rank: 1

credits
12
Published in 2023-8-3 10:28:45 | Show all floors
To use GPIO on Orange Pi Zero 2 you can use the "RPi.GPIO" library. This is a popular slope and widely supported library for controlling GPIOs on Orange Pi boards, including the Orange Pi Zero 2.

0

threads

9

posts

36

credits

Novice

Rank: 1

credits
36
Published in 2023-8-7 11:31:41 | Show all floors
Sharing workarounds, garten of banban 4 like appending the sys.path to find the WiringOP-Python module or running the programs with sudo, can indeed help users overcome such challenges and continue their development process.

0

threads

6

posts

18

credits

Novice

Rank: 1

credits
18
Published in 2023-8-8 09:45:39 | Show all floors
Your tips on addressing the path issue pizza tower and the need for root privileges when using WiringOP-Python will likely save others a lot of time and frustration.

0

threads

7

posts

86

credits

Registered member

Rank: 2

credits
86
Published in 2023-8-12 22:09:10 | Show all floors
Consider the site Date and Time https://diveintopython.org/learn/date   your destination if Python and IT call to you. You should definitely invest the time because I know because I studied there myself. Great classes on Python and other technologies are offered there. The chance is also an excellent one to acknowledge the significance of the IT industry in today's society. Join

0

threads

18

posts

62

credits

Registered member

Rank: 2

credits
62
Published in 2023-8-15 15:15:47 | Show all floors
The information you share is very good and interesting, thanks to that, I know more useful things. Keep posting interesting things slope and I will keep an eye on your posts.

0

threads

10

posts

134

credits

Registered member

Rank: 2

credits
134
Published in 2023-8-25 01:37:16 | Show all floors
Der Kauf eines eigenen Autos kann teuer sein. Neben dem Kaufpreis fallen laufende Kosten wie Treibstoff, Versicherung, Wartung und Parkgebühren an. Mit SimpCar zahlen Sie nur für die tatsächliche Nutzung des Fahrzeugs. Dies kann langfristig kostengünstiger sein, insbesondere wenn Sie das Auto nur gelegentlich benötigen. https://jobboard.militarytimes.com/employers/1873045-simpcar
https://jobs.beanhunter.com/employers/1873046-simpcar
https://email-support.hellobox.c ... ind-am-meisten-wert
https://wiki.mgpu.ru/index.php/% ... D0%B8%D0%BA:Simpcar
https://machineintelligence.mn.c ... titel-in-new-jersey
https://jobs.oanj.org/employers/1873105-simpcar

0

threads

3

posts

10

credits

Novice

Rank: 1

credits
10
Published in 2023-8-25 09:29:44 | Show all floors
With this basic recipe, you can get up and running with GPIO control quite quickly using Python on the dino game Orange Pi Zero 2. The possibilities for DIY projects are endless!
You need to log in before you can reply login | Register

Points Rule

Quick reply Top Return list