在树莓派Raspberry Pi启动阶段改变GPIO的状态(上拉,下拉等)

本文介绍了如何在树莓派系统启动时改变GPIO为上拉或下拉状态。通过安装wiringpi和device-tree-compiler,创建并编辑mygpio-overlay.dts文件,设置GPIO的输入输出及上拉下拉状态,最后重启验证效果。
摘要由CSDN通过智能技术生成

有网友问我怎样在树莓派系统启动时,就改变某一个GPIO为上拉或者下拉,现在我就来举例说明。

我有一个树莓派2B,安装的Raspbian系统。

首先确保安装了wiringpi和device-tree-compiler。

pi@raspberrypi:~ $ sudo apt-get install wiringpi device-tree-compiler
Reading package lists... Done
Building dependency tree
Reading state information... Done
device-tree-compiler is already the newest version (1.4.7-3+rpt1).
wiringpi is already the newest version (2.50).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

然后查看wringpi的版本,以及系统硬件的情况。

pi@raspberrypi:~ $ gpio -v
gpio version: 2.50
Copyright (c) 2012-2018 Gordon Henderson
This is free software with ABSOLUTELY NO WARRANTY.
For details type: gpio -warranty

Raspberry Pi Details:
  Type: Pi 2, Revision: 01, Memory: 1024MB, Maker: Embest
  * Device tree is enabled.
  *--> Raspberry Pi 2 Model B Rev 1.1
  * This Raspberry Pi supports user-level GPIO access.

使用gpio readall可以读出所有GPIO的状态。

pi@raspberrypi:~ $ gpio readall
 +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 |   IN | 1 |  3 || 4  |   |      | 5v      |     |     |
 |   3 |   9 |   SCL.1 |   IN | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 1 | ALT0 | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | ALT0 | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |   IN | 0 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |
  • 1
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值