Blink LEDs using Orange Pi Zero GPIO and Python

I have been covering quiet a few tutorials on using Orange Pi Zero and now we will see how to control GPIO pins and run a helloworld blink LED program using python.  The Orange Pi Zero comes with a 2 X 13 pins slot, very similar to Raspberry Pi style pinout. It does not come pre-soldered and we need to solder it ourselves.

Hardware required :

The below links are part of my affiliate links

Banggood links

Orange Pi Zero

Female header connector

and a soldering iron if you dont have one.

Amazon Links

Orange Pi Zero

Female header connector

Connection :

I soldered the female header  instead of a male header pin since its very easy to handle with prototyping just like Arduino.


I have drawn the pinout just similar to the above pic.


I have listed the GPIO Pins out of these pinout.

Log on to your Orange Pi Zero as root user using Putty or SSH client and then run the below command to fetch and install the code.

git clone
cd orangepi_PC_gpio_pyH3
python install

Now I will show you how to control the RGB LED using Orange Pi Zero. For that you need an RGB Led, or bunch of single colored LEDs or a breakout board like this will also do.

If you are building your own RGB led circuit you will need three 220 Ohms resistor and an RGB LED.


I am going to use Pin 6 for GND, Pin 3 (PA12), Pin 5(PA11), Pin 7(PA06) for GPIO pin to control the individual colors.


I modified the from the repository.

#!/usr/bin/env python
"""Basic blinking led example.


import os
import sys

if not os.getegid() == 0:
sys.exit('Script must be run as root')

from time import sleep
from pyA20.gpio import gpio
from pyA20.gpio import port

__author__ = "Stefan Mavrodiev"
__copyright__ = "Copyright 2014, Olimex LTD"
__credits__ = ["Stefan Mavrodiev"]
__license__ = "GPL"
__version__ = "2.0"
__maintainer__ = __author__
__email__ = ""

led = port.PA12
led1 = port.PA11
led2 = port.PA6

gpio.setcfg(led, gpio.OUTPUT)
gpio.setcfg(led1, gpio.OUTPUT)
gpio.setcfg(led2, gpio.OUTPUT)

    print ("Press CTRL+C to exit")
    while True:
        gpio.output(led, 1)
        gpio.output(led, 0)

        gpio.output(led1, 1)
        gpio.output(led1, 0)

        gpio.output(led2, 1)
        gpio.output(led2, 0)

except KeyboardInterrupt:
    print ("Goodbye.")


Check out my other Orange Pi Tutorials for more information.

10 thoughts on “Blink LEDs using Orange Pi Zero GPIO and Python

  • Pingback: How to setup 2 Axis analog joystick with Orange Pi Zero – Codelectron

  • November 1, 2017 at 2:45 pm

    Great! It works as shown. I think that now I have a new brain for my robot with webcam, webserving, wifi and motor and sensor control for very little money. Thanks again.

    • November 3, 2017 at 8:32 pm

      Thank you 🙂

  • December 21, 2017 at 2:05 pm

    Thank you! Works like charm! Can you guys give me a clue how am I supposed to store data in database. I want to use MongoDB particularly. Thanks again! 🙂

  • March 27, 2018 at 7:09 pm

    NameError: name ‘port’ is not defined

  • May 9, 2018 at 1:09 am

    Hello how make FM transmitter with gpio orange pi zero h2+ please ? , cordially 🙂 .

    • May 11, 2018 at 10:19 am

      Hi sxlo,

      Thanks for you comment. I have once implemented a FM transmitter using Raspberry Pi. I am not sure about the Orange Pi, Rpi has inbuilt hardware support for operating the gpio at a higher speed which may not be there in Orange Pi but I will give a try to get this up running.

      • May 11, 2018 at 11:17 am

        Hello, thanks so much for your reply, thanks so mush for that too. Ok, I’ll wait for your test, Cordialy ☺️.

  • July 21, 2018 at 10:57 am

    pyA20/gpio/gpio.c:25:20: fatal error: Python.h: No such file or directory
    compilation terminated.
    error: command ‘arm-linux-gnueabihf-gcc’ failed with exit status 1

    this error is coming can plz help me out

    • July 21, 2018 at 1:40 pm

      The python dev package is missing, try after sudo apt-get install python-dev


Leave a Reply

Your email address will not be published. Required fields are marked *