{"id":660,"date":"2020-08-13T22:18:12","date_gmt":"2020-08-13T14:18:12","guid":{"rendered":"https:\/\/www.iotch.xyz\/?p=660"},"modified":"2020-08-13T22:18:12","modified_gmt":"2020-08-13T14:18:12","slug":"%e6%a0%91%e8%8e%93%e6%b4%be-dht11-%e6%b8%a9%e6%b9%bf%e5%ba%a6%e4%bc%a0%e6%84%9f%e5%99%a8%e8%af%bb%e5%8f%96-c-%e8%af%ad%e8%a8%80%e7%89%88-2","status":"publish","type":"post","link":"https:\/\/www.iotch.xyz\/?p=660","title":{"rendered":"\u6811\u8393\u6d3e DHT11 \u6e29\u6e7f\u5ea6\u4f20\u611f\u5668\u8bfb\u53d6 C \u8bed\u8a00\u7248"},"content":{"rendered":"\n<figure class=\"wp-block-embed-wordpress wp-block-embed is-type-wp-embed is-provider-\u6811\u8393\u6d3e\u5b9e\u9a8c\u5ba4\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/shumeipai.nxez.com\/2020\/05\/19\/raspberry-pi-read-data-from-dht11-sensor-by-c.html\n<\/div><\/figure>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/shumeipai.nxez.com\/wp-content\/uploads\/2020\/05\/20200519010915299-0.jpg\" alt=\"\" class=\"wp-image-6743\"\/><\/figure><\/div>\n\n\n\n<p>\u6211\u4eec\u4e4b\u524d\u4ecb\u7ecd\u8fc7\u4e09\u79cd\u8bfb\u53d6 DHT11 \u6e29\u6e7f\u5ea6\u4f20\u611f\u5668\u6570\u503c\u7684\u65b9\u6cd5\uff1a<a href=\"https:\/\/shumeipai.nxez.com\/2019\/10\/06\/reading-temperature-and-humidity-from-dht11-with-raspberry-pi.html\" rel=\"noreferrer noopener\" target=\"_blank\" rel=\"nofollow\" >\u7528\u7cfb\u7edf\u529f\u80fd\u76f4\u8bfb<\/a>\u3001<a href=\"https:\/\/shumeipai.nxez.com\/2018\/05\/16\/dht11-temperature-and-humidity-sensor-raspberry-pi.html\" rel=\"noreferrer noopener\" target=\"_blank\" rel=\"nofollow\" >\u7528 Adafruit \u7684\u5e93\u8bfb\u53d6<\/a>\u3001<a href=\"https:\/\/shumeipai.nxez.com\/2014\/10\/10\/raspberry-dht11-get-temperature-data.html\" rel=\"noreferrer noopener\" target=\"_blank\" rel=\"nofollow\" >\u7528 Python \u7f16\u7a0b\u8bfb\u53d6<\/a>\u3002<br>\u5c3d\u7ba1\u65b9\u6cd5\u5f88\u591a\uff0c\u4f46\u662f\u5728\u4e0d\u540c\u7684\u6811\u8393\u6d3e\u4e0a\u3001\u4f7f\u7528\u4e0d\u540c\u7684\u751f\u4ea7\u5546\u751f\u4ea7\u7684 DHT11 \u6a21\u5757\u65f6\uff0c\u53ef\u80fd\u51fa\u73b0\u8bfb\u51fa\u7684\u6570\u503c\u65e0\u6548\uff0c\u6216\u8005\u76f4\u63a5\u8bfb\u4e0d\u51fa\u7684\u60c5\u51b5\u3002<br>\u90a3\u4e48\u8fd9\u8fb9\u518d\u591a\u63d0\u4f9b\u4e00\u79cd\u4eb2\u6d4b\u53ef\u7528\u7684 C \u8bed\u8a00\u7248\u672c\u4f9b\u5927\u5bb6\u9009\u62e9\u5c1d\u8bd5\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u4f20\u611f\u5668\u8fde\u63a5<\/h4>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/shumeipai.nxez.com\/wp-content\/uploads\/2015\/03\/rpi-pins-40-0.png\" alt=\"\"\/><\/figure><\/div>\n\n\n\n<p>Vcc \u5f15\u811a\u63a5 5V<br>DATA \u5f15\u811a\u63a5 WiringPi \u7f16\u7801 7<br>GND \u5f15\u811a\u63a5\u6811\u8393\u6d3e\u7684 GND<br><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/shumeipai.nxez.com\/wp-content\/uploads\/2020\/05\/20200519010859848-0.jpg\" alt=\"\" class=\"wp-image-6742\"\/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/shumeipai.nxez.com\/wp-content\/uploads\/2020\/05\/20200519010835181-0.jpg\" alt=\"\" class=\"wp-image-6741\"\/><\/figure><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">\u5b89\u88c5 WiringPi<\/h4>\n\n\n\n<p>\u8fd9\u91cc\u4f7f\u7528\u4e86 WiringPi \u5e93\uff0c\u5982\u679c\u5df2\u7ecf\u5b89\u88c5\u8fc7\u53ef\u4ee5\u8df3\u8fc7\u8fd9\u4e00\u6b65\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>12345678<\/td><td><code>sudo<\/code> <code>apt-get update<\/code><code>#\u5982\u679c\u4e4b\u524d\u6ca1\u6709\u5b89\u88c5\u8fc7 git\uff0c\u6267\u884c\u4e0b\u9762\u7684\u547d\u4ee4\u5b89\u88c5\u4e00\u4e0b<\/code><code>sudo<\/code> <code>apt-get <\/code><code>install<\/code> <code>git-core<\/code><code>#\u4e0b\u8f7d wiringPi<\/code><code>git clone https:<\/code><code>\/\/github<\/code><code>.com<\/code><code>\/WiringPi\/WiringPi<\/code><code>#\u7f16\u8bd1 wiringPi<\/code><code>cd<\/code> <code>WiringPi<\/code><code>sudo<\/code> <code>.<\/code><code>\/build<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">\u7f16\u7a0b<\/h4>\n\n\n\n<p>\u6e90\u4ee3\u7801\u5982\u4e0b\uff0c\u4fdd\u5b58\u4e3a dht11.c\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899<\/td><td><code>#include &lt;wiringPi.h&gt;<\/code><code>#include &lt;stdio.h&gt;<\/code><code>#include &lt;stdlib.h&gt;<\/code>&nbsp;<code>typedef<\/code> <code>unsigned <\/code><code>char<\/code> <code>uint8;<\/code><code>typedef<\/code> <code>unsigned <\/code><code>int<\/code>&nbsp; <code>uint16;<\/code><code>typedef<\/code> <code>unsigned <\/code><code>long<\/code> <code>uint32;<\/code>&nbsp;<code>#define HIGH_TIME 32<\/code>&nbsp;<code>int<\/code> <code>pinNumber = 7;<\/code><code>uint32 databuf;<\/code>&nbsp;<code>uint8 readSensorData(<\/code><code>void<\/code><code>)<\/code><code>{<\/code><code>uint8 crc; <\/code><code>uint8 i;<\/code>&nbsp;<code>pinMode(pinNumber, OUTPUT); <\/code><code>\/\/ set mode to output<\/code><code>digitalWrite(pinNumber, 0); <\/code><code>\/\/ output a high level <\/code><code>delay(25);<\/code><code>digitalWrite(pinNumber, 1); <\/code><code>\/\/ output a low level <\/code><code>pinMode(pinNumber, INPUT); <\/code><code>\/\/ set mode to input<\/code><code>pullUpDnControl(pinNumber, PUD_UP);<\/code>&nbsp;<code>delayMicroseconds(27);<\/code><code>if<\/code> <code>(digitalRead(pinNumber) == 0) <\/code><code>\/\/SENSOR ANS<\/code><code>{<\/code><code>while<\/code> <code>(!digitalRead(pinNumber))<\/code><code>; <\/code><code>\/\/wait to high<\/code>&nbsp;<code>for<\/code> <code>(i = 0; i &lt; 32; i++)<\/code><code>{<\/code><code>while<\/code> <code>(digitalRead(pinNumber))<\/code><code>; <\/code><code>\/\/data clock start<\/code><code>while<\/code> <code>(!digitalRead(pinNumber))<\/code><code>; <\/code><code>\/\/data start<\/code><code>delayMicroseconds(HIGH_TIME);<\/code><code>databuf *= 2;<\/code><code>if<\/code> <code>(digitalRead(pinNumber) == 1) <\/code><code>\/\/1<\/code><code>{<\/code><code>databuf++;<\/code><code>}<\/code><code>}<\/code>&nbsp;<code>for<\/code> <code>(i = 0; i &lt; 8; i++)<\/code><code>{<\/code><code>while<\/code> <code>(digitalRead(pinNumber))<\/code><code>; <\/code><code>\/\/data clock start<\/code><code>while<\/code> <code>(!digitalRead(pinNumber))<\/code><code>; <\/code><code>\/\/data start<\/code><code>delayMicroseconds(HIGH_TIME);<\/code><code>crc *= 2;&nbsp; <\/code><code>if<\/code> <code>(digitalRead(pinNumber) == 1) <\/code><code>\/\/1<\/code><code>{<\/code><code>crc++;<\/code><code>}<\/code><code>}<\/code><code>return<\/code> <code>1;<\/code><code>}<\/code><code>else<\/code><code>{<\/code><code>return<\/code> <code>0;<\/code><code>}<\/code><code>}<\/code>&nbsp;<code>int<\/code> <code>main(<\/code><code>void<\/code><code>)<\/code><code>{<\/code><code>printf<\/code><code>(<\/code><code>\"PIN:%d\\n\"<\/code><code>, pinNumber);<\/code>&nbsp;<code>if<\/code> <code>(-1 == wiringPiSetup()) {<\/code><code>printf<\/code><code>(<\/code><code>\"Setup wiringPi failed!\"<\/code><code>);<\/code><code>return<\/code> <code>1;<\/code><code>}<\/code>&nbsp;<code>pinMode(pinNumber, OUTPUT); <\/code><code>\/\/ set mode to output<\/code><code>digitalWrite(pinNumber, 1); <\/code><code>\/\/ output a high level <\/code>&nbsp;<code>printf<\/code><code>(<\/code><code>\"Starting...\\n\"<\/code><code>);<\/code><code>while<\/code> <code>(1) <\/code><code>{<\/code><code>pinMode(pinNumber, OUTPUT); <\/code><code>\/\/ set mode to output<\/code><code>digitalWrite(pinNumber, 1); <\/code><code>\/\/ output a high level <\/code><code>delay(3000);<\/code><code>if<\/code> <code>(readSensorData())<\/code><code>{<\/code><code>printf<\/code><code>(<\/code><code>\"Sensor data read ok!\\n\"<\/code><code>);<\/code><code>printf<\/code><code>(<\/code><code>\"RH:%d.%d\\n\"<\/code><code>, (databuf &gt;&gt; 24) &amp; 0xff, (databuf &gt;&gt; 16) &amp; 0xff); <\/code><code>printf<\/code><code>(<\/code><code>\"TMP:%d.%d\\n\"<\/code><code>, (databuf &gt;&gt; 8) &amp; 0xff, databuf &amp; 0xff);<\/code><code>databuf = 0;<\/code><code>}<\/code><code>else<\/code><code>{<\/code><code>printf<\/code><code>(<\/code><code>\"Sensor dosent ans!\\n\"<\/code><code>);<\/code><code>databuf = 0;<\/code><code>}<\/code><code>}<\/code><code>return<\/code> <code>0;<\/code><code>}<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">\u7f16\u8bd1\u7a0b\u5e8f\u5e76\u8fd0\u884c<\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>12<\/td><td><code>gcc<\/code> <code>-Wall -o dht11 dht11.c -lwiringPi<\/code><code>sudo<\/code> <code>.<\/code><code>\/dht11<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u5ffd\u7565\u7f16\u8bd1\u8fc7\u7a0b\u4e2d\u7684\u8b66\u544a\u3002\u8fd0\u884c\u4e4b\u540e\u5c06\u51fa\u73b0\u6e29\u6e7f\u5ea6\u8bfb\u6570\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/shumeipai.nxez.com\/wp-content\/uploads\/2020\/05\/20200519010915299-0.jpg\" alt=\"\" class=\"wp-image-6743\"\/><\/figure><\/div>\n\n\n\n<p>\u76f8\u5173\u8ba8\u8bba\uff1a<a href=\"https:\/\/talk.quwj.com\/topic\/1005\" rel=\"noreferrer noopener\" target=\"_blank\" rel=\"nofollow\" >https:\/\/talk.quwj.com\/topic\/1005<\/a><strong>\u6587\u7ae0\u6807\u9898\uff1a<\/strong><a href=\"https:\/\/shumeipai.nxez.com\/2020\/05\/19\/raspberry-pi-read-data-from-dht11-sensor-by-c.html\" target=\"_blank\"  rel=\"nofollow\" >\u6811\u8393\u6d3e DHT11 \u6e29\u6e7f\u5ea6\u4f20\u611f\u5668\u8bfb\u53d6 C \u8bed\u8a00\u7248<\/a> - <a href=\"https:\/\/shumeipai.nxez.com\" target=\"_blank\"  rel=\"nofollow\" >\u6811\u8393\u6d3e\u5b9e\u9a8c\u5ba4<\/a><strong>\u56fa\u5b9a\u94fe\u63a5\uff1a<\/strong><a href=\"https:\/\/shumeipai.nxez.com\/2020\/05\/19\/raspberry-pi-read-data-from-dht11-sensor-by-c.html\" target=\"_blank\"  rel=\"nofollow\" >https:\/\/shumeipai.nxez.com\/2020\/05\/19\/raspberry-pi-read-data-from-dht11-sensor-by-c.html<\/a><\/p>\n<button class=\"simplefavorite-button\" data-postid=\"660\" data-siteid=\"1\" data-groupid=\"1\" data-favoritecount=\"0\" style=\"\">\u6536\u85cf <i class=\"sf-icon-star-empty\"><\/i><\/button>","protected":false},"excerpt":{"rendered":"<p>\u6211\u4eec\u4e4b\u524d\u4ecb\u7ecd\u8fc7\u4e09\u79cd\u8bfb\u53d6 DHT11 \u6e29\u6e7f\u5ea6\u4f20\u611f\u5668\u6570\u503c\u7684\u65b9\u6cd5\uff1a\u7528\u7cfb\u7edf\u529f\u80fd\u76f4\u8bfb\u3001\u7528 Adafruit \u7684\u5e93\u8bfb\u53d6\u3001\u7528 Python \u7f16\u7a0b &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,9,11],"tags":[],"class_list":["post-660","post","type-post","status-publish","format-standard","hentry","category-arduino","category-9","category-11"],"_links":{"self":[{"href":"https:\/\/www.iotch.xyz\/index.php?rest_route=\/wp\/v2\/posts\/660","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.iotch.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.iotch.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.iotch.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.iotch.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=660"}],"version-history":[{"count":0,"href":"https:\/\/www.iotch.xyz\/index.php?rest_route=\/wp\/v2\/posts\/660\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.iotch.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=660"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.iotch.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=660"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.iotch.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=660"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}