【安信可BW16-Kit开发板】DHT11应用
<div class='showpostmsg'><p align="center"><b>【安信可BW16-Kit开发板】DHT11应用</b></p><p > </p>
<p >按照安信可BW16-Kit开发板官方介绍,此款开发版支持Linux、Arduino IDE、Python开发环境。Linux、Arduino IDE开发环境搭建已经有很多文章介绍,这里就不在赘述。本文重点介绍Python开发环境搭建及程序烧录。</p>
<p ><b>一、DHT11介绍</b></p>
<p >DHT11 数字温湿度传感器是一款含有已校准数字信号输出的温湿度复合传感器,内部由一个 8 位单片机控制一个电阻式感湿元件和一个 NTC 测温元件。其温度测量范围为 0~50℃,误差在±2℃;湿度的测量范围为 20%~90%RH,误差在±5%RH。DHT11 电路很简单,只需要将 DATA 引脚连接单片机的一个 I/O 即可,不过该引脚需要上拉一个 5K 的电阻,DHT11 的供电电压为 3~5.5V。</p>
<p align="center" > </p>
<p >1、DHT11引脚说明</p>
<table align="center" style="border-collapse:collapse; border:none">
<tbody>
<tr>
<td style="border-bottom:1px solid black; border-top:1px solid black; border-right:1px solid black; border-left:1px solid black" valign="top">
<p >pin</p>
</td>
<td style="border-bottom:1px solid black; border-top:1px solid black; border-right:1px solid black; border-left:none" valign="top">
<p >名称</p>
</td>
<td style="border-bottom:1px solid black; border-top:1px solid black; border-right:1px solid black; border-left:none" valign="top">
<p >注释</p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top">
<p >1</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >VDD</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >供电3~5V</p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top">
<p >2</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >DATA</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >串行数据,单总线</p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top">
<p >3</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >NC</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >空脚</p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top">
<p >4</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >GND</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >接地,电源负极</p>
</td>
</tr>
</tbody>
</table>
<p >2、传感器性能参数</p>
<p > </p>
<table align="center" style="border-collapse:collapse; border:none">
<tbody>
<tr>
<td style="border-bottom:1px solid black; border-top:1px solid black; border-right:1px solid black; border-left:1px solid black" valign="top">
<p >参数</p>
</td>
<td style="border-bottom:1px solid black; border-top:1px solid black; border-right:1px solid black; border-left:none" valign="top">
<p >条件</p>
</td>
<td style="border-bottom:1px solid black; border-top:1px solid black; border-right:1px solid black; border-left:none" valign="top">
<p >Min</p>
</td>
<td style="border-bottom:1px solid black; border-top:1px solid black; border-right:1px solid black; border-left:none" valign="top">
<p >Type</p>
</td>
<td style="border-bottom:1px solid black; border-top:1px solid black; border-right:1px solid black; border-left:none" valign="top">
<p >Max</p>
</td>
<td style="border-bottom:1px solid black; border-top:1px solid black; border-right:1px solid black; border-left:none" valign="top">
<p >单位</p>
</td>
</tr>
<tr>
<td colspan="6" style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top">
<p >湿度</p>
</td>
</tr>
<tr>
<td rowspan="2" style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top">
<p >分辨率</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >1</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >1</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >1</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >%RH</p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >8</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >Bit</p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top">
<p >重复性</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >±1</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >%RH</p>
</td>
</tr>
<tr>
<td rowspan="2" style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top">
<p >精度</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >25℃</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >±4</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >%RH</p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >0~25℃</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >±5</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >%RH</p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top">
<p >互换性</p>
</td>
<td colspan="5" style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p align="center" >可完全互换</p>
</td>
</tr>
<tr>
<td rowspan="3" style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top">
<p >量程范围</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >0℃</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >30</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >90</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >%RH</p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >25℃</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >20</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >90</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >%RH</p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >50℃</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >20</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >80</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >%RH</p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top">
<p >响应时间</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >1/e(63%)25℃,</p>
<p >1m/s空气</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >6</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >10</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >15</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >S</p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top">
<p >迟滞</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >±1</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >%RH</p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top">
<p >长期稳定性</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >典型值</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >±1</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >%RH/yr</p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top">
<p >温度</p>
</td>
<td colspan="5" style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
</tr>
<tr>
<td rowspan="2" style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top">
<p >分辨率</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >1</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >1</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >1</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >℃</p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >8</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >8</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >8</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >Bit</p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top">
<p >重复性</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >±1</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >℃</p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top">
<p >精度</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >±1</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >±2</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >℃</p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top">
<p >量程范围</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >0</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >50</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >℃</p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top">
<p >响应时间</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >1/e(63%)</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >6</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p > </p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >30</p>
</td>
<td style="border-bottom:1px solid black; border-top:none; border-right:1px solid black; border-left:none" valign="top">
<p >S</p>
</td>
</tr>
</tbody>
</table>
<p > </p>
<p >3、接口说明</p>
<p >建议连接线长度短于20米时用5K上拉电阻,大于20米时根据实际情况使用合适的上拉电阻。DHT11的供电电压为3-5.5V。传感器上电后,要等待1s以越过不稳定状态在此期间无需发送任何指令。电源引脚(VDD,GND)之间可增加一个100nF的电容,用以去耦滤波。</p>
<p >4、MCU连接示意图</p>
<p > </p>
<p >5、串行接口(单线双向)</p>
<p >DATA用于微处理器与DHT11之间的通讯和同步,采用单总线数据格式,一次通讯时间4ms左右,数据分小数部分和整数部分,具体格式在下面说明,当前小数部分用于以后扩展,现读出为零。操作流程如下:</p>
<p >一次完整的数据传输为40bit,高位先出。</p>
<p ><b>数据格式</b>:8bit湿度整数数据+8bit湿度小数数据+8bi温度整数数据+8bit温度小数数据+8bit校验和</p>
<p >数据传送正确时校验和数据等于“8bit湿度整数数据+8bit湿度小数数据+8bi温度整数数据+8bit温度小数数据”所得结果的末8位。</p>
<p >用户MCU发送一次开始信号后,DHT11从低功耗模式转换到高速模式,等待主机开始信号结束后,DHT11发送响应信号,送出40bit的数据,并触发一次信号采集,用户可选择读取部分数据。从模式下,DHT11接收到开始信号触发一次温湿度采集,如果没有接收到主机发送开始信号,DHT11不会主动进行温湿度采集。采集数据后转换到低速模式。</p>
<p > </p>
<p >总线空闲状态为高电平,主机把总线拉低等待DHT11响应,主机把总线拉低必须大于18毫秒,保证DHT11能检测到起始信号。DHT11接收到主机的开始信号后,等待主机开始信号结束,然后发送80us低电平响应信号。主机发送开始信号结束后,延时等待20-40us后,读取DHT11的响应信号,主机发送开始信号后,可以切换到输入模式,或者输出高电平均可,总线由上拉电阻拉高。</p>
<p align="center" > </p>
<p ><b>二、运行范例</b></p>
<p >1、Arduino环境下程序如下</p>
<p align="center" > </p>
<p align="left" >#include "DHT.h"</p>
<p align="left" >#define DHTPIN 8</p>
<p align="left" >#define DHTTYPE DHT11 // DHT 11</p>
<p align="left" >DHT dht(DHTPIN, DHTTYPE);</p>
<p align="left" > </p>
<p align="left" >void setup() {</p>
<p align="left" > Serial.begin(115200);</p>
<p align="left" > Serial.println(F("DHTxx test!"));</p>
<p align="left" > dht.begin();</p>
<p align="left" >}</p>
<p align="left" > </p>
<p align="left" >void loop() {</p>
<p align="left" > // Wait a few seconds between measurements.</p>
<p align="left" > delay(2000);</p>
<p align="left" > </p>
<p align="left" > float h = dht.readHumidity();</p>
<p align="left" > // Read temperature as Celsius (the default)</p>
<p align="left" > float t = dht.readTemperature();</p>
<p align="left" > // Read temperature as Fahrenheit (isFahrenheit = true)</p>
<p align="left" > float f = dht.readTemperature(true);</p>
<p align="left" > </p>
<p align="left" > if (isnan(h) || isnan(t) || isnan(f)) {</p>
<p align="left" > Serial.println(F("Failed to read from DHT sensor!"));</p>
<p align="left" > return;</p>
<p align="left" > }</p>
<p align="left" > </p>
<p align="left" > float hif = dht.computeHeatIndex(f, h);</p>
<p align="left" > float hic = dht.computeHeatIndex(t, h, false);</p>
<p align="left" > Serial.print(F("Temperature: "));</p>
<p align="left" > Serial.print(hic);</p>
<p align="left" > Serial.print(F(" ℃ "));</p>
<p align="left" > Serial.print(F("Humidity: "));</p>
<p align="left" > Serial.print(hif);</p>
<p align="left" > Serial.println(F(" ℉"));</p>
<p align="left" > </p>
<p align="left" >}</p>
<p > </p>
<p ><b>2、运行结果</b></p>
<p >显示运行结果如下:</p>
<p align="center" > </p>
<p ><b>三、总结</b></p>
<p >从上面示例我们可以看出,在Arduino环境下可以很容易对安可信BW16-Kit进行二次开发。</p>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> <p>Arduino环境下对安可信BW16-Kit进行二次开发,看来确实很容易</p>
<p>在Example中,DHTPIN 8是連接到PA26嗎?</p>
页:
[1]