Here's how to get GPIO working in Python on the Orange Pi One.

Note. The GPIO pins on the Orange Pi One are flipped 180 degrees compared to the Orange Pi PC version or a Raspberry Pi!

check out my other Orange Pi tutorials:



Step 1: Download and Install Python Library

To start you will need the python headers and library installed, if you haven't or aren't sure just type:

sudo apt-get install python-dev

Then download the pyH3 library from:


extract the folder and place in '/home/pi'

from the terminal go into that directory:

cd orangepi_PC_gpio_pyH3

then install it using:

python setup.py install

The library is now installed.

Step 2: Test It!

The way the pins are referred to are slightly different to a Raspberry Pi, they are named "ports" & "connectors".

UPDATE 03/05/2016: The new armbian images no longer export the gpios to /gpio_sw. See the above image for the port names. Image Credit: http://forum.armbian.com/index.php/topic/759-tutor...

For example pin 29 (BCM05) is port 'PA7'

To test, connect an LED to pin 29 through a 300ohm resistor then to the ground. (see diagram below)

and created a file called 'test.py':

#import the library
from pyA20.gpio import gpio
from pyA20.gpio import port
from time import sleep

#initialize the gpio module

#setup the port (same as raspberry pi's gpio.setup() function)
gpio.setcfg(port.PA7, gpio.OUTPUT)

#now we do something (light up the LED)
gpio.output(port.PA7, gpio.HIGH)

#turn off the LED after 2 seconds
gpio.output(port.PA7, gpio.LOW)

Dont forget to make your test file executable:

chmod +x test.py

and run as root:

sudo su

Step 3: .

That's the basics working, more advanced stuff like i2C should work aswell but I haven't tested.

Credit goes to: Duxingkei Chow and Stefan Mavrodiev (examples in git repository)

<p>Hi there,</p><p>Ive got a problem executing the test.py file.</p><p>I always get the error &quot;cannot import name &gt;gpio&lt;&quot;</p><p>Can someone help me here? Thanks</p>
<p>Hi Fleder,<br> I had the same issue. The cause was I created the test.py file in the same directory ('home/pi' ) as the pyA20 module source. <br><br>Moving the 'test.py' file to a different directory resolved the issue. </p>
Hello dave,<br><br>thank you very much!<br>I will try it out and hope it will resolve this issue.<br>I have the .py in the same directory, too.<br><br>Thanks and have a nice day!
hi, having trouble with the tutorial. when i get to the part where i run the &quot;python setup.py intall&quot; i get an error, &quot;permission denied&quot;. i have so far followed the steps exactly but i dont know what im doing wrong?
<p>Thank you for this statement</p><p>Note. The GPIO pins on the Orange Pi One are flipped 180 degrees compared to the Orange Pi PC version or a Raspberry Pi</p><p>I've<br> been hunting everywhere for a diagram that tells me where Pin1 is in <br>relation to actual board (plenty of schematics of pins but not in <br>relation to where they are on the physical board). I thought the arrow was probably P1 but unlike RPi where P1 P2... are labelled properly, <br>OPi doesn't (and the arrow &quot;P1&quot; is flipped 180 compared to RPi thus my <br>apprehension).</p>
<p>Hello, i followed your guide but i stuck in:</p><p>from: can't read /var/mail/pyA20.gpio<br>from: can't read /var/mail/pyA20.gpio<br>from: can't read /var/mail/time<br>./test.py: line 10: syntax error near unexpected token `gpio.setcfg'<br>./test.py: line 10: `gpio.setcfg(port.PA7, gpio.OUTPUT)'</p><p>Can you help me? I'm absolutely beginner at orangepi pc.</p>
<p>I had the issue on my Orange Pi lite running Lubuntu solved it by using &quot;python test.py&quot; to execute the script!</p><p>This happens because the default shell will execute it and it will bail out at the from keyword (Incidentally, from is the name of a command line utility which prints names of those who have sent mail to the given username, so that's why it tries to access the mailboxes. </p><p>Hope this helps! :)</p>
<p>Hi Kristian,</p><p>Its difficult to tell without seeing your code (or is it just the code above?), but it looks like for some reason your code is trying to find the libraries in '/var/mail/'.</p><p>this is unusual because time is a standard library. What OS are you using?</p>
<p>I'm using the code above (the code on your tutorial), and i'm using this OS:</p><p>Linux 3.4.39-01-lobo/armv7l - Distro: Ubuntu 15.10</p>
<p>I would highly recommend installing Armbian.</p>
<p>hi. how to read data from gpio pin?</p>
<p>What is it your trying to read from?</p>
<p>Hi!</p><p>I'd like to read from a dht11 temp+humidity sensor. Can you help?</p>
<p>Hi, I think its only possible using C code as python is too slow, here's what I used:</p><p>http://uploaded.net/file/se9ffl4l</p><p>(I had it inserting the data into an sqlite database, so 'ive removed that so it just prints to the terminal)</p>
<p>great job my friend keep up the good work</p>
<p>#import the library ??????</p>
<p>Yes, the following 3 lines import the libraries. (Any line with a hash is a comment and describes what the following lines are doing).</p>
<p>You are right... I thought that you wanted to import the library in the first line, sorry.<br></p><p>One question for you. Do you know how to control a servo? Thanks in advance.</p>
<p>Hi, I haven't actually used a servo before but a quick bit of research suggests that you just send pulses. So either use PWM or just send a high signal for x miliseconds. see this post: https://www.raspberrypi.org/forums/viewtopic.php?f=37&amp;t=46771</p>
<p>Trying to drive servo PWM from script is not likely to work very well because timing will be variable and servos will jitter. Thank you anyway, this article give some clues to make it work.</p>

About This Instructable




More by DuncanW10:Orange Pi One Analog Devices using MCP3008 via SPI Orange Pi One Python GPIO (basic) Orange Pi One Setup Guide 
Add instructable to: