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()         
  • 相关阅读:
    centos6.5 mysql配置整理
    第四章 Web表单
    第三章 模板
    第二章 程序的基本结构
    第一章 安装
    常见网络错误代码(转)
    微软消息队列MessageQueue(MQ)
    基于.NET平台常用的框架整理(转)
    Sqlserver更新数据表xml类型字段内容某个节点值的脚本
    正则表达式_基础知识集合
  • 原文地址:https://www.cnblogs.com/zengjfgit/p/5215194.html
Copyright © 2011-2022 走看看