当前位置:网站首页>烟雾传感器(mq-2)使用详细教程(基于树莓派3b+实现)
烟雾传感器(mq-2)使用详细教程(基于树莓派3b+实现)
2022-04-23 14:02:00 【1029179954】
经验:
网上大部分关于mq-2的代码,实现的功能判断是否有烟雾值,而具体的烟雾值无法读取。由于树莓派无法直接读取模拟信号A0值,所以得借助PCF8591(读取烟雾值关键adc)读取,这个PCF8591相当关键,必须使用。
硬件准备:
树莓派3b+、mq-2、PCF8591(读取烟雾值关键adc)和杜邦线
PCF8591如下图:
实物连接:
PCF8591与树莓派相连接:
mq-2与树莓派和PCF8591相连接
mq-2 PCF8591 树莓派
vcc------------------------3.3v
gnd-----------------------gnd
AOUT–A0
关键连接如图:
设置树莓派:
打开I2C接口
打开树莓派终端,输入以下指令进入配置界面
sudo raspi-config
选择 Interfacing Options -> I2C ->yes 启动 i2C 内核驱动
上代码:
import time
from smbus import SMBus
address = 0x48
MODE0 = 0x00 #Channel0 = AIN0
#Channel1 = AIN1
#Channel2 = AIN2
#Channel3 = AIN3
MODE1 = 0x10 #Channel0 = AIN3-AIN0
#Channel1 = AIN3-AIN1
#Channel2 = AIN3-AIN2
MODE2 = 0x20 #Channel0 = AIN0
#Channel1 = AIN1
#Channel2 = AIN3-AIN2
MODE3 = 0x30 #Channel0 = AIN1-AIN0
#Channel1 = AIN3-AIN2
CHNL0 = 0x40 #Using Channel0
CHNL1 = 0x41 #Using Channel1
CHNL2 = 0x42 #Using Channel2
CHNL3 = 0x43 #Using Channel3
DAouputEn = 0x40
PCF8591 = SMBus(1)
while True:
value0 = PCF8591.read_byte(address)
PCF8591.write_byte(address, CHNL0)
time.sleep(2)
运行结果
具体实现效果和具体资料可到微信公众号查看:
版权声明
本文为[1029179954]所创,转载请带上原文链接,感谢
https://blog.csdn.net/baidu_38978508/article/details/122012224
边栏推荐
- Analysis and understanding of atomicintegerarray source code
- Reading notes: fedgnn: Federated graph neural network for privacy preserving recommendation
- Record a strange bug: component copy after cache component jump
- try --finally
- The art of automation
- New关键字的学习和总结
- 关于pthread多线程一些好文章
- Express中间件③(自定义中间件)
- [code analysis (3)] communication efficient learning of deep networks from decentralized data
- 关于stream流,浅记一下------
猜你喜欢
基于Ocelot的gRpc网关
freeCodeCamp----arithmetic_ Arranger exercise
第一章 电商秒杀商品回顾
PATH环境变量
Interesting talk about network protocol
Choreographer full resolution
记录一个奇怪的bug:缓存组件跳转之后出现组件复制
JMeter pressure test tool
As a junior college student, I studied hard in closed doors for 56 days, won Ali offer with tears, five rounds of interviews and six hours of soul torture
cnpm的诡异bug
随机推荐
STM32学习记录0007——新建工程(基于寄存器版)
_模_板_
Choreographer全解析
AtomicIntegerArray源码分析与感悟
美联储数字货币最新进展
nodejs通过require读取本地json文件出现Unexpected token / in JSON at position
Android篇:2019初中级Android开发社招面试解答(中
Function executes only the once function for the first time
The latest development of fed digital currency
Basic knowledge learning record
读了一篇博客,重新理解闭包整理一下
STM32 learning record 0007 - new project (based on register version)
try --finally
[code analysis (5)] communication efficient learning of deep networks from decentralized data
go 语言 数组,字符串,切片
腾讯根据ip解析地址
Strange bug of cnpm
Quartus Prime硬件实验开发(DE2-115板)实验二功能可调综合计时器设计
JS 力扣刷题 102. 二叉树的层序遍历
Go语言 RPC通讯