Orange PI Zero GPIO vezérléshez pythonból az alábbi linek találtam telepítési leírást:
https://diyprojects.io/orange-pi-onelite-tutorial-use-gpio-python-pinouts/#.Wfzw-bynFhE
Zero alatt a pyA20 telepítésénél a processzort nem ismerte fel erre a setup.py-ben az alábbi sorokat ki rem-eltem, és tovább lépett:
- letöltöttem innen a pyA20-at: https://pypi.python.org/pypi/pyA20
wget https://pypi.python.org/packages/8e/a5/8169ac07290b7d7dfff96dbf68707a2154171e48294e78eb7623758a299f/pyA20-0.2.1.tar.gz - kiremeltem:
def print_warning(): """ Print confirmation dialog :return: """ print (print_color("Warning! ") + "Detected and target processor mismatch. ") # var = input("Do you want to continue [Y/n]? ") # if var == 'Y' or var == 'y': # return # else: # print ("Abort.") # sys.exit(1)
3. majd python setup.py install kiadásával telepítettem.
Let’s start by preparing the environment by installing Python
1
|
sudo apt–get install python–dev
|
Then install the pyA20 library
1
|
sudo pip install pyA20
|
Now we need to install the library to manage the Orange Pi GPIO. Place yourself in your home folder (eg /home/ft) and then clone the pyH3 library (https://github.com/duxingkei33/orangepi_PC_gpio_pyH3). This is an adaptation made by Duxingkei Chow of the library “python control orangepi_PC ext GPIO ALLwinner H3” based on the “pyA20 0.2.1” library.
1
2
|
cd /home/pi
git clone https://github.com/duxingkei33/orangepi_PC_gpio_pyH3
|
Enter the library directory
1
|
cd orangepi_PC_gpio_pyH3
|
And run the installation (it is better to do the previous command with a sudo if you are not logged in as root).
1
|
sudo python setup.py install
|
A Program:
Lighting a Python Led
For this first tutorial on the GPIO of Orange Pi, we will not go far. Either way it’s exactly the same as Raspberry. There is only the call of the pins that differs.
Create a new file. For example test.py
1
|
nano test.py
|
Paste the following code and save with Ctrl + X then Y. This code is very simple, it lights for 2 seconds a LED connected to the PG7 pin (equivalent to the Raspberry GPIO21). Connect a LED on pin PG7 (the last one in the right column) to a GND via a 220Ω resistor.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
#import the library / Import des librairies
from pyA20.gpio import gpio
from pyA20.gpio import port
from time import sleep
#initialize the gpio module / initialise le GPIO
gpio.init()
#setup the port (same as raspberry pi’s gpio.setup() function)
#Configure la broche PG7 (equivalent au GPIO21 du Raspberry) comme une sortie
gpio.setcfg(port.PG7, gpio.OUTPUT)
#now we do something (light up the LED)
#Maintenant, on allume la LED
gpio.output(port.PG7, gpio.HIGH)
#turn off the LED after 2 seconds
#Et on eteint après 2 secondes
sleep(2)
gpio.output(port.PG7, gpio.LOW)
|
We make the script executable
1
|
chmod +x test.py
|
If you are not logged in as root, you must preface the python command with a sudo (you will be prompted for the password).
1
|
sudo python test.py
|
If the wiring is correct, the LED must illuminate for 2 seconds.