当前位置:网站首页>树莓派入门(3)树莓派GPIO学习
树莓派入门(3)树莓派GPIO学习
2022-08-10 05:25:00 【jualay】
目录
一、安装RPi.GPIO
sudo apt-get update
sudo apt-get install python3-rpi.gpio
二、树莓派4B引脚图

GPIO:就是一些可以改变的引脚,输入或输出为高低电平
三、RPi.GPIO
1.导入它,并用GPIO这个名字来代替
import RPi.GPIO as GPIO
2.检查是否导入成功
try:
import RPi.GPIO as GPIO
except RuntimeError:
print("import RPi.GPIO error")
导入失败就会打印import RPi.GPIO error
3.GPIO编号
要按照GPIO引脚图来使用相应的编号
GPIO.setmode(GPIO.BOARD)
#或者是
GPIO.setmode(GPIO.BCM)
4.GPIO模式
在编程前要将GPIO设置为相应的工作状态
(1)输入
GPIO.setup(channel,GPIO.IN)
(2)输出
GPIO.setup(channel,GPIO.OUT)
设置初始化高电平:
GPIO.setup(channel,GPIO.OUT,initial=GPIO.HIGH)
设置初始化低电平:
GPIO.setup(channel,GPIO.OUT,initial=GPIO.LOW)
(3)多引脚输入输出
创建一个列表,将列表包含的引脚代入
PinList=[pin1,pin2,pin3]
GPIO.setup(PinList,GPIO.IN)
5.读取输入电平
GPIO.input(channel)
6.设置GPIO输出状态
(1)设置高电平(上拉)
GPIO.setup(channel,1)
#或者是
GPIO.setup(channel,GPIO.HIGH)
(2)设置高电平(下拉)
GPIO.setup(channel,0)
#或者是
GPIO.setup(channel,GPIO.LOW)
7.清理GPIO资源
将所有使用过的GPIO的状态变为输入状态,避免短路损坏
GPIO.cleanup()
边栏推荐
- 接口调试还能这么玩?
- The sword refers to Offer 033. Variation array
- Flutter development: error The following assertion was thrown resolving an image codec: Solution for Unable to...
- MySQL simple tutorial
- 剑指Offer 033.变位数组
- oracle cdc时,设置并行度2插槽数1,最终任务只有一个tm,是不是因为oracle不支持并发
- leetcode每天5题-Day10
- Hezhou ESP32C3 +1.8"tft network clock under Arduino framework
- 重要转型升级
- conda创建虚拟环境方法和pqi使用国内镜像源安装第三方库的方法教程
猜你喜欢

How to improve product quality from the code layer

Depth of carding: prevent model fitting method

Get started with the OAuth protocol easily with a case

我用这一招让团队的开发效率提升了 100%!

Talk about API Management - Open Source Edition to SaaS Edition

看了几十篇轻量化目标检测论文扫盲做的摘抄笔记

Interface documentation evolution illustration, some ancient interface documentation tools, you may not have used it

JavsSE => 多态

Read the excerpt notes made by dozens of lightweight target detection papers for literacy

canvas canvas drawing clock
随机推荐
接口调试还能这么玩?
mysql cdc (2.1.1)inital snapshot数据库的时候设置了5个并发度,se
线性模型中的高级特征选择技术——基于R
Thread.sleep, Thread.yield role explanation
Ask you guys.The FlinkCDC2.2.0 version in the CDC community has a description of the supported sqlserver version, please
【静态代理】
leetcode每天5题-Day13
重要转型升级
如何取得某月的最后一天
FPGA工程师面试试题集锦31~40
软考考生注意!2022年下半年报名详细流程来了!
Attention candidates for the soft exam! The detailed registration process for the second half of 2022 is coming!
leetcode每天5题-Day11
Become a language that hackers have to learn. Do you think it's okay after reading it?
`id` bigint(20) unsigned NOT NULL COMMENT '数据库主键',
When oracle cdc, set the parallelism to 2 and the number of slots to 1, and the final task has only one tm. Is it because oracle does not support concurrency
顺序表的删除,插入和查找操作
Get started with the OAuth protocol easily with a case
添加路由的2种方式--router
Rpc interface stress test