查看: 2575|回复: 1

【Tigerboard】之GPIO的输入输出控制

[复制链接]
  • TA的每日心情
    奋斗
    2022-10-13 10:27
  • 签到天数: 216 天

    连续签到: 1 天

    [LV.7]常住居民III

    发表于 2016-3-19 01:48:49 | 显示全部楼层 |阅读模式
    分享到:
      要利用TigerBoard实现外围设备的控制,首先的学会如果去控制TigerBoard的GPIO口,由于板子Gobian系统中已经封装了RPi.GPIO库,并且兼容Raspberry Pi的管脚,所以我们可以参考树莓派GPIO的控制方法,首先看下J3这两排管脚。

    7.jpg


    一.GPIO的输出控制

      了解了GPIO的原理图后,我们可以参考官方提供的技术文档和Demo选33PIN这一管脚进行测试,这里我们采用Python来实现这一功能,通过观察LED的状态来验证程序
    1. import RPi.GPIO as gpio  # Include the RPi.GPIO library as gpio.
    2. import time                    # Include the Python time functions.
    3. gpio.setmode(gpio.BOARD) # Set mod as BOARD, which means to use the numbering from the physical layout.
    4. while True:
    5.     gpio.setup(33, gpio.OUT)          # Set pin 33 on J3 to be an output.
    6.     gpio.output(33, gpio.HIGH)        # Set pin 33 on J3 as high.
    7.     time.sleep(1)                     # Wait for one second.
    8.     gpio.output(33, gpio.LOW)             # Set pin 33 on J3 as low.
    9.     time.sleep(1)                     # Wait for one second.
    复制代码
    说明:
      程序开始导入了要用到的库和包,然后设置了GPIO的模式--gpio.BOARD,最后通过一个while循环来实现了灯的亮灭控制,并且亮灭之间延时时间为1S
    360截图20160319014645392.jpg
    学会了如果控制GPIO的控制,我们可以轻松的操作继电器开关、人体红外检测等简单的模块


    二.GPIO的输入控制

      这里只需要改变GPIO的配置,并进行检测即可基本同GPIO输入
    1. import RPi.GPIO as gpio  
    2. import time
    3. gpio.setmode(gpio.BOARD)
    4. while True:
    5.     gpio.setup(33, gpio.IN)             # Set up pin 33 on header J3 to be used as an input.
    6.     if gpio.input(33):                       # Read the value of pin 33; and execute the indented if it’s high.
    7.       print “Button pressed!”           # Print a message to the terminal.
    8.     time.sleep(3)                             # Wait for 3second.
    复制代码
    8.jpg

      这里gpio.input(33)输入你可以再33管脚通过接地和接3.3V电压来模拟验证程序,会了这个便知道如果操作按键和其他的一些输入识别的GPIO控制了。

    回复

    使用道具 举报

  • TA的每日心情
    开心
    2020-1-18 09:06
  • 签到天数: 7 天

    连续签到: 1 天

    [LV.3]偶尔看看II

    发表于 2016-4-10 16:09:16 | 显示全部楼层
    使用RPi.GPIO会出现以下错误:
    RuntimeError: This module can only be run on a Raspberry Pi!
    怎么解决??????????


    你遇到这种问题了吗?这个问题怎么解决?
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /2 下一条



    手机版|小黑屋|与非网

    GMT+8, 2024-4-19 09:24 , Processed in 0.115906 second(s), 18 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.