====== Using Python Program Control GPIOs ====== //__About this Article__// * **Author**: allen --- allen@cubietech.com --- 2014/07/12 11:29 * **Copyrights**: [[http://creativecommons.org/licenses/by-sa/3.0/|CC Attribution-Share Alike 3.0 Unported]] * **Contributors**: [[http://cubieboard.org/|Cubieboard Community]] : ... ===== 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. {{:tutorials:common:193929q19liwbpuod9r4d9.png|}} {{:tutorials:common:193953xb82b8224t8qncle.png|}} {{ :tutorials:common:194336oftr8p1wouubpojz.png |}} ==== 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 === {{tag>Cubieboard Cubietruck}}