当前位置:网站首页>烟雾传感器(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
边栏推荐
- leetcode--977. Squares of a Sorted Array
- 收藏博客贴
- Interesting talk about network protocol
- Elmo (bilstm-crf + Elmo) (conll-2003 named entity recognition NER)
- Problems encountered in the project (V) understanding of operating excel interface poi
- 多线程 @Async 线程池
- 大专的我,闭关苦学 56 天,含泪拿下阿里 offer,五轮面试,六个小时灵魂拷问
- Android interview theme collection
- 关于stream流,浅记一下------
- Taobao released the baby prompt "your consumer protection deposit is insufficient, and the expiration protection has been started"
猜你喜欢
linux安装mysql后修改密码
Nacos+AspnetCore+Ocelot实战编码
2021年秋招,薪资排行NO
JMeter pressure test tool
Un modèle universel pour la construction d'un modèle d'apprentissage scikit
Decentralized Collaborative Learning Framework for Next POI Recommendation
About note 1
基础知识学习记录
freeCodeCamp----arithmetic_ Arranger exercise
How does redis solve the problems of cache avalanche, cache breakdown and cache penetration
随机推荐
PySide2
PATH环境变量
Un modèle universel pour la construction d'un modèle d'apprentissage scikit
[code analysis (2)] communication efficient learning of deep networks from decentralized data
2022年江西最新建筑八大员(质量员)模拟考试题库及答案解析
Quartus prime hardware experimental development (de2-115 board) experiment 1 CPU instruction calculator design
Lin Lin, product manager of Lenovo: network failure of local network operator in Tianjin. The background server of Zui system can't work normally for the time being
Wechat applet
浅谈基于openssl的多级证书,Multi-level CA的签发和管理,以及双向认证
Nodejs安装及环境配置
Business case | how to promote the activity of sports and health app users? It is enough to do these points well
Strange bug of cnpm
【项目】小帽外卖(八)
基础知识学习记录
Multithreading
Universal template for scikit learn model construction
JMeter pressure test tool
初探 Lambda Powertools TypeScript
Express②(路由)
JS 烧脑面试题大赏