RPi 2B GPIO 测试

时间:2023-03-08 18:36:40
RPi 2B GPIO 测试
/**************************************************************************************
* RPi 2B GPIO 测试
* 声明:
* 本文主要记录RPi 2B GPIO口的使用,理解什么是GPIO的BOARD编号和BCM编号。
*
* 2016-2-24 深圳 南山平山村 曾剑锋
************************************************************************************/ 一、参考文档:
. RPi.GPIO 0.3.1a
https://pypi.python.org/pypi/RPi.GPIO/0.3.1a#downloads
. Raspberry PI上操作GPIO(GPIO编程)
http://www.cnblogs.com/rainduck/archive/2012/09/22/2694568.html
. # GPIO: channel is already in use
https://sourceforge.net/p/raspberry-gpio-python/tickets/16/ 二、error:
. 现象:
#pi@raspberrypi:~/programe/python $ ./ledGPIO.py
#./ledGPIO.py:: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
# GPIO.setup(, GPIO.OUT)
. 解决方法:
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(, GPIO.OUT) while times > :
if == times%:
GPIO.output(, GPIO.HIGH) # or output(, GPIO.True)
else:
GPIO.output(, GPIO.LOW) # or output(, GPIO.True)
time.sleep(delay)
times -= return if __name__ == '__main__':
blink(, )
GPIO.cleanup()