zoukankan      html  css  js  c++  java
  • RPi 2B GPIO 测试

    /**************************************************************************************
     *                             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. 现象:
            #pi@raspberrypi:~/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()         
  • 相关阅读:
    bzoj 1210 [HNOI2004] 邮递员 插头dp
    与非 乱搞233
    USACO JAN14 奶牛冰壶运动 凸包+判定
    bzoj 2829 计算几何
    R
    bzoj 1592 dp
    [Usaco2007 Open]Fliptile 翻格子游戏 状压dp
    拯救莫莉斯 状压dp
    大暑假集训 第一阶段总结 233
    hdu 1693 Eat the Trees 插头dp
  • 原文地址:https://www.cnblogs.com/zengjfgit/p/5215194.html
Copyright © 2011-2022 走看看