/************************************************************************************** * RPi 2B GPIO 测试 * 声明: * 本文主要记录RPi 2B GPIO口的使用,理解什么是GPIO的BOARD编号和BCM编号。 * * 2016-2-24 深圳 南山平山村 曾剑锋 ************************************************************************************/ 一、参考文档: 1. RPi.GPIO 0.3.1a https://pypi.python.org/pypi/RPi.GPIO/0.3.1a#downloads 2. Raspberry PI上操作GPIO(GPIO编程) http://www.cnblogs.com/rainduck/archive/2012/09/22/2694568.html 3. #16 GPIO: channel is already in use https://sourceforge.net/p/raspberry-gpio-python/tickets/16/ 二、error: 1. 现象: #[email protected]:~/programe/python $ ./ledGPIO.py #./ledGPIO.py:8: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings. # GPIO.setup(11, GPIO.OUT) 2. 解决方法: add GPIO.cleanup() at the end of your program. 三、demo: #!/usr/bin/python import RPi.GPIO as GPIO import time def blink(times, delay): # 选择采用树莓派的引脚编号,也就是那个1到40的引脚编号。 GPIO.setmode(GPIO.BOARD) # 我的led灯,一端接树莓派的1号脚,也就是最左上角的3.3V的引脚, # 另一端接在树莓派的11号引脚。 GPIO.setup(11, GPIO.OUT) while times > 0 : if 0 == times%2: GPIO.output(11, GPIO.HIGH) # or output(11, GPIO.True) else: GPIO.output(11, GPIO.LOW) # or output(11, GPIO.True) time.sleep(delay) times -= 1 return if __name__ == ‘__main__‘: blink(20, 1) GPIO.cleanup()
时间: 2024-08-11 03:37:25