The pyA20 gpio library is quite famous when people start to play with gpios , spi or i2c on sunxi boards but mapping needs often adjustments to work on your own board. This situation is not really friendly for 'beginners'. pyGPIO should help to make armbian a little bit more 'IoT friendly'.
I didn't touch the 'backbone' of pyA20, so the syntax should be similar to its original (except pinname when using port instead of connector).
How can I use this library:
Cause all of this boards have (more or less) the same pinheader (sometimes other pins are deployed on the pinheader) pyGPIO tries to unify the mappings, so that code can be shared and deployed on all boards without touching the code. The mapping follows the pin naming of the RaspberryPi (it's not because I think their naming is perfect, but it should be the easiest way to port code from the 'RPi world' to Armbian.
What is done:
-Initial support for:
OrangePi Zero/PcPlus/Lite/Plus2E
NanoPi Duo(with and without Minishield)/Neo
Olimex Lime/Lime2/Micro (pins are not renamed PG10,PG11 etc. instead of GPIO2, GPIO3 etc. cause those boards doesn't have a 'RPi Pinheader'
Templates for 24,26 and 40 'RPi compatible' pin header
-Board detection (when using Armbian) to check if your board is supported
-Manual assignment when your board is not supported (yet) or automatic board detection fails
What is not done:
Testing
testing
testing!
Documentation
Meaningful examples (still the originals from olimex which wouldn't work anymore)
What do you need to test the Library:
You need python-dev and the Library which you'll find on my GitHub page. The installation should be easy, just follow the instructions...
sudo apt-get install python-dev
git clone https://github.com/chwe17/pyGPIO.git
cd pyGPIO
sudo python setup.py install
Testing is the part where I need help. I don't have most of the boards which are supported (only OPi0 and OPi Pc Plus). I tested I2C and GPIO on the OPi0, for all the rest, I need you as testers, bug hunters, and feedback.
Here are two short python snippets which should do the exact same thing (once with connector, you have to run them as root or with sudo otherwise it would not work!):
import os, sys
if not os.getegid() == 0:
sys.exit('start script as root')
from pyGPIO.gpio import gpio, connector
from time import sleep
gpio.init()
gpio.setcfg(connector.GPIOp7, 1) #pin 7 as output
n = 0
while n < 5:
gpio.output(connector.GPIOp7, 1)
sleep(1)
gpio.output(connector.GPIOp7, 0)
sleep(1)
n +=1
sys.exit('finished ;-)')
and once with port:
import os, sys
if not os.getegid() == 0:
sys.exit('start script as root')
from pyGPIO.gpio import gpio, port
from time import sleep
gpio.init()
gpio.setcfg(port.GPIO4, 1) #gpio4 as output
n = 0
while n < 5:
gpio.output(port.GPIO4, 1)
sleep(1)
gpio.output(port.GPIO4, 0)
sleep(1)
n +=1
sys.exit('finished ;-)')
Annotation: When using NanoPi Duo you've to possibilities with or without Minishield. Pin name is the same on both possibilities but when using port but pin numbering when using connector:
Minishield:
3.3V |1·| 5V
GPIO2 I2C0_SDA |3·| 5V
GPIO3 I2C_SCL |5·| GND
GPIO4 |··| GPIO14 UART1_TX
GND |··| GPIO15 UART1_RX
GPIO17 SPI1_MOSI |··| GPIO18
GPIO27 SPI1_MISO |··| GND
GPIO22 SPI1_CLK |··| GPIO23 SPI1_CS
3.3V |··| NC (on mini shield)
Without (e.g. connector.J1p7 or connector.J2p5) :
J1 J2
(UART0_RX) |1| microUSB |1| 5V
(UART0_TX) |2| |·| 5V
GND |3| |·| 3.3V
GPIO3 (TWI_SCL) |4| |·| GND
GPIO2 (TWI_SDA) |5| |·| GPIO4 (IR_RX)
GPIO23 (SPI1_CS) |6| |·| GPIO18 (IOG11)
GPIO22 (SPI1_CLK) |7| |·| DM3 D-
GPIO27 (SPI1_MISO) |·| |·| DM3 D+
GPIO17 (SPI1_MOSI) |·| |·| DM2 D-
GPIO15(UART1_RX) |·| |·| DM2 D+
GPIO14 (UART1_TX) |·| |·| RDN
(CVBS) |·| |·| RDP
(LINEOUT_L) |·| |·| TXN
(LINEOUT_R) |·| |·| TXP
(MICP) |·| |·| LED-LINK
(MICN) |·| microSD |·| LED-SPD
Buttons (bigger orange pi boards) are mapped, but I didn't test if it works (mapping here, if somebody is interested in testing them, see mapping.h of your board):
{"BUTTON",
{
{ "BUTTON", SUNXI_GPL(4), 1 },
{
{ 0, 0, 0}
},
}
},