当前位置:网站首页>烟雾传感器(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
边栏推荐
- New关键字的学习和总结
- JS force deduction brush question 102 Sequence traversal of binary tree
- 第十五章 软件工程新技术
- China creates vast research infrastructure to support ambitious climate goals
- Crontab timing task output generates a large number of mail and runs out of file system inode problem processing
- mysql通过binlog文件恢复数据
- 商家案例 | 运动健康APP用户促活怎么做?做好这几点足矣
- UML Unified Modeling Language
- linux安装mysql后修改密码
- Question bank and answer analysis of the 2022 simulated examination of the latest eight members of Jiangxi construction (quality control)
猜你喜欢
Express②(路由)
【项目】小帽外卖(八)
STM32 learning record 0007 - new project (based on register version)
浅谈基于openssl的多级证书,Multi-level CA的签发和管理,以及双向认证
freeCodeCamp----time_ Calculator exercise
Pytorch 经典卷积神经网络 LeNet
JS 烧脑面试题大赏
Quartus Prime硬件实验开发(DE2-115板)实验一CPU指令运算器设计
Quartus prime hardware experimental development (de2-115 board) experiment II function adjustable comprehensive timer design
crontab定时任务输出产生大量邮件耗尽文件系统inode问题处理
随机推荐
Jiannanchun understood the word game
elmo(BiLSTM-CRF+elmo)(Conll-2003 命名实体识别NER)
MySQL 修改主数据库
大专的我,闭关苦学 56 天,含泪拿下阿里 offer,五轮面试,六个小时灵魂拷问
蓝绿发布、滚动发布、灰度发布,有什么区别?
leetcode--380.O(1) 时间插入、删除和获取随机元素
scikit-learn构建模型的万能模板
New关键字的学习和总结
YARN线上动态资源调优
[code analysis (1)] communication efficient learning of deep networks from decentralized data
编程旅行之函数
SQL数据库
Express ② (routing)
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
3300万IOPS、39微秒延迟、碳足迹认证,谁在认真搞事情?
Oracle alarm log alert Chinese trace and trace files
Decentralized Collaborative Learning Framework for Next POI Recommendation
[code analysis (6)] communication efficient learning of deep networks from decentralized data
FDFS start
What is the difference between blue-green publishing, rolling publishing and gray publishing?