User Tools

Site Tools


tutorials:common:using_python_program_control_gpios

Using Python Program Control GPIOs

About this Article

Abstract

Here is the guide to show that how to use python program control GPIOs .More others way to control can refer to http://docs.cubieboard.org/tutorials/common/gpio_on_lubuntu

Install python and lib

$sudo apt-get update
$sudo apt-get install python-dev
$wget http://dl.cubieboard.org/software/libs/pySUNXI-0.1.12.tar.gz
$tar zxf pySUNXI-0.1.12.tar.gz
$sudo python setup.py install

Connect the GPIO

Using the PD0 and VCC-5V for test.

Write a sample program

#!/usr/bin/env python

import SUNXI_GPIO as GPIO
import time

RED_LED = GPIO.PD0

GPIO.init()
GPIO.setcfg(RED_LED, GPIO.OUT)

while True:
        GPIO.output(RED_LED, GPIO.HIGH)
        time.sleep(1)
        GPIO.output(RED_LED, GPIO.LOW)
        time.sleep(1)

Run program

$chmod +x blink.py
$sudo ./blink.py

The red led is blinking in cycle time.

See Also

tutorials/common/using_python_program_control_gpios.txt · Last modified: 2014/07/15 10:35 by allen