树莓派从 DHT11 温度湿度传感器读取数据
时序图参考厂家说明书:DHT11数字湿温度传感器的原理和应用范例
四个阵脚连接:VCC接3.3伏电源,Dout接GPIO口,我接的是物理12针脚,NC留空,GND接地。
波折1:电阻被错接进了VCC,于是看了无数遍时序图,改了无数遍的驱动无论怎么改都是读不出数据。
波折2:偶然看了网上的DHT11上拉电阻电路图才发现错误,于是果断去掉电阻。但为了显示传感器工作正常在电源和VCC间接了个发光二极管进去,数据倒是读出来了,但各种错误。(原因不明)
去掉了电阻,去掉了led,优化了写的python,读数正常。再一次赞一个python。
写DHT11的驱动需要注意时序之间很紧密,python执行任何程序都要花费时间,在获取时序时需要注意所写调试用的代码也是占用时序的,在这一点上也走了一点弯路。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# -*- coding: utf-8 -*- """ Created on Sun Jan 26 14:24:43 2014 @author: pi """ import RPi.GPIO as gpio import time gpio.setwarnings( False ) gpio.setmode(gpio.BOARD) time.sleep( 1 ) data = [] def delay(i): #20*i usdelay a = 0 for j in range (i): a + 1 j = 0 #start work gpio.setup( 12 ,gpio.OUT) #gpio.output(12,gpio.HIGH) #delay(10) gpio.output( 12 ,gpio.LOW) time.sleep( 0.02 ) gpio.output( 12 ,gpio.HIGH) i = 1 i = 1 #wait to response gpio.setup( 12 ,gpio.IN) while gpio. input ( 12 ) = = 1 : continue while gpio. input ( 12 ) = = 0 : continue while gpio. input ( 12 ) = = 1 : continue #get data while j< 40 : k = 0 while gpio. input ( 12 ) = = 0 : continue while gpio. input ( 12 ) = = 1 : k + = 1 if k> 100 : break if k< 3 : data.append( 0 ) else : data.append( 1 ) j + = 1 print "Sensor is working" #get temperature humidity_bit = data[ 0 : 8 ] humidity_point_bit = data[ 8 : 16 ] temperature_bit = data[ 16 : 24 ] temperature_point_bit = data[ 24 : 32 ] check_bit = data[ 32 : 40 ] humidity = 0 humidity_point = 0 temperature = 0 temperature_point = 0 check = 0 for i in range ( 8 ): humidity + = humidity_bit[i] * 2 * * ( 7 - i) humidity_point + = humidity_point_bit[i] * 2 * * ( 7 - i) temperature + = temperature_bit[i] * 2 * * ( 7 - i) temperature_point + = temperature_point_bit[i] * 2 * * ( 7 - i) check + = check_bit[i] * 2 * * ( 7 - i) tmp = humidity + humidity_point + temperature + temperature_point if check = = tmp: print "temperature is " , temperature, "wet is " ,humidity, "%" else : print "something is worong the humidity,humidity_point,temperature,temperature_point,check is" ,humidity,humidity_point,temperature,temperature_point,check |
测试python程序时间代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# -*- coding: utf-8 -*- """ Created on Sun Jan 26 16:01:59 2014 @author: pi """ import time def delay(i): k = 0 for j in range (i): k + = 1 n = 5000 j = 0 a = time.time() i = 1 c = time.time() d = c - a print d a = time.time() for i in range (n): j + = 1 c = time.time() d = c - a print d a = time.time() delay(n) c = time.time() d = c - a print d |
树莓派从 DHT11 温度湿度传感器读取数据的更多相关文章
- 【Raspberry Pi】DHT11 温度湿度传感器数据读取
时序图参考厂家说明书:DHT11数字湿温度传感器的原理和应用范例 四个阵脚连接:VCC接3.3伏电源,Dout接GPIO口,我接的是物理12针脚,NC留空,GND接地. 波折1:电阻被错接进了VCC, ...
- Arduino IDE 开发ESP-01/ESP8266-01读取DHT11温度湿度传感器
引脚接线: DHT11---ESP8266-01 Singnal--IO2, GND----GND, VCC----VCC DHT11引脚说明: ESP8266-01/ESP8266-01S引脚说明: ...
- 【.NET 与树莓派】温度/湿度传感器——SHT30
SHT3XX 系列的传感,常见的有三种:SHT 30.SHT 31.SHT 35.其中,比较便宜性价比较愉快的是 SHT 30. DHT 11 模块也是检测温度.湿度的,但SHT 11 使用的不是我们 ...
- 【Raspberry Pi】读取DHT11温度湿度波折
从网上找到了DHT11厂家说明书,尝试用python根据时序图写数据获取驱动,但发现python的高层特性导致在做底层代码时例如控制20us时延这类需求就没什么好的办法. 还是得回到C-wiringP ...
- Arduino IDE 开发 ESP-01S/ESP-01物联网实战检测温度湿度上传MQTT服务器
一.硬件准备 USB转ESP8266两块.DHT11温度湿度传感器.ESP8266-01/ESP8266-01一块(如果学习的话多买几块,ESP-01/ESP-01S的区别) USB转ESP8266 ...
- 单片机DIY制作-基于STM32单片机甲醛二氧化碳温度湿度采集系统
基于STM32单片机甲醛二氧化碳温度湿度采集系统 实践制作DIY-GC008-甲醛二氧化碳温度湿度采集系统 一.功能说明: 基于STM32单片机设计-甲醛二氧化碳温度湿度采集系统 二.功能介绍: 1. ...
- 树莓派使用DHT11温湿度传感器
一.相关介绍 DHT11介绍: DHT11是一款比较便宜的温湿度传感器模块.读取数据只需要占用一个IO口.能够同时测量温度和相对湿度. DHT11的数据手册可以看这里:http://wenku.bai ...
- 树莓派连接DHT11温湿度传感器(python)
介绍 DHT11作为一个廉价配件,同时包含了温度.湿度传感器,而且,编码使用也非常简单. 本文介绍如果在树莓派中使用 DHT11,代码是Python.如果有任何疑问,欢迎在下面留言. 接线 VCC接5 ...
- Arduino+温度、湿度传感器
Arduino语言注解Arduino语言是建立在C/C++基础上的,其实也就是基础的C语言,Arduino语言只不过把AVR单片机(微控制器)相关的一些参数设置都函数化,不用我们去了解他的底层,让我们 ...
随机推荐
- windows 下node版管理
linux 下的node 多版本管理有nvm,windows 下同样有这样的工具gnvm 安装步骤(无node环境): 1.下载并解压缩 gnvm.exe 保存到任意文件夹,并将此文件夹加入到环境变量 ...
- Linux 进程创建二(execve和wait)
三:execve系统调用 int execve(const char *filename, char *const argv[],char *const envp[]); fork创建了一个新的进程, ...
- [浪风推荐]CURL伪造IP和来源
给“刷票”的朋友提供了很好的换IP的方案,查了下,CURL确实很强悍的可以伪造IP和来源. 1.php 请求 2.php . 1.php代码: $ch = curl_init(); curl_seto ...
- Memcached 常见的问题
memcached是怎么工作的? Memcached的奇妙来自两阶段哈希(two-stage hash).Memcached就像一个巨大的.存储了非常多<key,value>对的哈希表. ...
- awk合并两个文件并显示
问题: 答案:
- Android Studio使用百度地图问题总结
一.常见问题APP Scode码校验失败 一般出现这个问题都是ak不正确导致 可能出错的地方 1.SHA1值没有正确获取 正确获取SHA1值:在左下角打开Terminal终端,进入debug.keys ...
- 设计模式之备忘录模式(Memento)
备忘录模式(Memento) 在不破坏封装性的前提下,捕获一个对象的内部状态,并在该对象之外保存这个状态.这样以后就可将该对象恢复到原先保存的状态. Originator(发起人):负责创建一个备忘录 ...
- 排序算法 c实现
c语言实现插入排序.冒泡排序.选择排序.快速排序.堆排序.归并排序.希尔排序示例,需要的朋友可以参考下 实现以下排序 插入排序O(n^2) 冒泡排序 O(n^2) 选择排序 O(n^2) 快速 ...
- encodeURI() 函数概述
encodeURI() 函数的作用是将URI中的某些特定的字符以一位到四位的转义序列来替代,这些转义序列就是这些字符的UTF-8编码(如果说某些字符是由两个代替字符构成的,该字符也只会是四位的转义序列 ...
- Genealogical tree
Genealogical tree Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 6032 Accepted: 3973 Spec ...