https://diyprojects.io/orange-pi-onelite-tutorial-use-gpio-python-pinouts/#.WZR4hVzo6Ts
Orange Pi One/Lite (Tutorial): use the GPIO in Python, pinouts
Orange Pi has a 40-pin extension connector (GPIO) compatible with the Raspberry Pi (model B +). In this tutorial, we will install python as well as the pyA20 library adapted to the GPIO of Orange Pi. On paper, the connector is compatible, only flat the call of the pins is different which requires to resume Python programs developed for The Raspberry. This is a bit of a shame but the very attractive price of the Orange Pi range remains a weighty argument.
For this tutorial, I used Armbian installed on an Orange Pi Lite (Wi-Fi version). The GPIO is the same throughout the Orange Pi range except the Orange Pi Zero which has a 26-pin GPIO.
Installing Python and Libraries
Let’s start by preparing the environment by installing Python
1
|
sudo apt-get install python-dev
|
1
|
sudo pip install pyA20
|
1
2
|
cd /home/pi
git clone https://github.com/duxingkei33/orangepi_PC_gpio_pyH3
|
1
|
cd orangepi_PC_gpio_pyH3
|
1
|
sudo python setup.py install
|
Correspondence of pins between Orange Pi and Raspberry Pi (model B+)
As I mentioned in the introduction, the expansion slot is compatible with the Raspberry B + (40-pin). However, the location is different.Raspberry Pi | Orange Pi | Pin (Left column) | Broche (Right column) | Orange Pi | Raspberry Pi |
3V3 | 1 | 2 | +5V | +5V | |
GPIO2 SDA1 I2C | PA12 | 3 | 4 | +5V | +5V |
GPIO3 SCL I2C | PA11 | 5 | 6 | GND | GND |
GPIO4 | PA6 | 7 | 8 | PA13 | GPIO14 UART_TXD |
GND | GND | 9 | 10 | PA14 | GPIO15 UART_RXD |
GPIO17 | PA1 | 11 | 12 | PD14 | GPIO18 PCM_CLK |
GPIO27 | PA0 | 13 | 14 | GND | GND |
GPIO22 | PA3 | 15 | 16 | PC4 | GPIO23 |
3V3 | 3V3 | 17 | 18 | PC7 | GPIO24 |
GPIO10 SPI0_MOSI | PC0 | 19 | 20 | GND | GND |
GPIO9 SPI0_MISO | PC1 | 21 | 22 | PA2 | GPIO25 |
GPIO11 SPI0_SCLK | PC2 | 23 | 24 | PC3 | GPIO8 SPI0_CE0_N |
GND | GND | 25 | 26 | PA21 | GPIO7 SPI0_CE1_N |
ID_SD I2C ID EEPROM | PA19 | 27 | 28 | PA18 | ID_SC I2C ID EEPROM |
GPIO5 | PA7 | 29 | 30 | GND | GND |
GPIO6 | PA8 | 31 | 32 | PG8 | GPIO12 |
GPIO13 | PA9 | 33 | 34 | GND | GND |
GPIO19 | PA10 | 35 | 36 | PG9 | GPIO16 |
GPIO26 | PA20 | 37 | 38 | PG6 | GPIO20 |
GND | GND | 39 | 40 | PG7 | GPIO21 |
Finally the last difference (and not least!), The connector is turned 180 degrees compared to that of the Raspberry. Needless to say that it will be necessary to use a connection for breadboard with a flexible cable if you want to connect the Orange to a breadboard (breakout) connection.
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
|
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)
|
1
|
chmod +x test.py
|
1
|
sudo python test.py
|
Now you have everything you need to use the Orange Pi GPIO. It’s a shame the calls are different. Existing programs will not be directly usable. Other regret, the rotation of the connector makes the use of HAT cards much less convenient (and compact!)
No hay comentarios:
Publicar un comentario