{"id":484,"date":"2017-02-08T23:00:37","date_gmt":"2017-02-08T15:00:37","guid":{"rendered":"http:\/\/192.168.1.20\/?p=484"},"modified":"2017-02-08T23:25:04","modified_gmt":"2017-02-08T15:25:04","slug":"{d4daabd1ba368d9860c36387ddb72bbda14f8f9559d69d60a952800885260c03}e6{d4daabd1ba368d9860c36387ddb72bbda14f8f9559d69d60a952800885260c03}a0{47dd41ec6bdcbd9a214c783a3735392b82ea6d1d918378c5a53e0640702d813","status":"publish","type":"post","link":"http:\/\/alextop.top\/?p=484","title":{"rendered":"\u6811\u8393\u6d3e\u63a5DTH11\u6e29\u5ea6\u4f20\u611f\u5668"},"content":{"rendered":"<p>\u4eca\u5929\u60f3\u628a\u6e29\u5ea6\u4f20\u611f\u5668DTH11\u63a5\u5230\u6811\u8393\u6d3e\u4e0a\uff0c\u4e00\u5f00\u59cb\u6211\u5f88\u76f8\u4fe1\u90a3\u4e2a\u6811\u8393\u6d3e\u5b9e\u9a8c\u5ba4\u4e0a\u7684\u5e16\u5b50\u8bf4\u7684\u8bdd\uff0c\u4ec0\u4e48\u4e0d\u9700\u8981\u4e0a\u62c9\u7535\u963b\u3001\u8fd8\u6709\u63a5led\u706f\u4f1a\u5e72\u6270\u3002\u3002\u611f\u89c9\u662f\u5c41\u8bdd\uff01\u4e00\u5f00\u59cb\u771f\u7684\u5f88\u76f8\u4fe1\uff0c\u7ed3\u679c\u76f4\u63a5\u5957\u7528\u4ed6\u5199\u7684python\u7a0b\u5e8f\u6ca1\u6709\u4efb\u4f55\u6539\u52a8\uff0c\u7ed3\u679c\u8bfb\u4e0d\u51fa\u6765\u3001\u8bfb\u4e0d\u51fa\u6765\u3001\u8bfb\u4e0d\u51fa\u6765\u3001\u8ba9\u6211\u628a\u677f\u5b50\u710a\u5f97\u9762\u76ee\u5168\u975e\u3002\u53c8\u662f\u62c6\u6d4b\u6e29\u5143\u4ef6\u3001\u53c8\u662f\u60f3\u628aled\u706f\u710a\u4e0b\u6765\uff0c\u542c\u4e86\u59e8\u7236\u7684\u8bdd\u53c8\u662f\u52a0\u4e86\u4e2a1F\u7684\u7535\u5bb9\u6765\u5c4f\u853d\u7535\u6e90\u5e72\u6270\uff0c\u7ed3\u679c\u8fd8\u662f\u8bfb\u4e0d\u51fa\u6765\u3002<\/p>\n<p>\u6fd2\u4e34\u5d29\u6e83\u7edd\u671b\u7684\u6211\u53ea\u80fd\u76f4\u8fde\u5143\u5668\u7136\u540e\u6362\u4e86\u4e2apython\u811a\u672c\uff0c\u7ed3\u679c\u5f00\u59cb\u8bfb\u51fa\u4e86\u6570\u636e\uff0c\u539f\u672c\u4ee5\u4e3a\u5143\u5668\u4ef6\u574f\u6389\u7684\u6211\u7ec8\u4e8e\u5f00\u5fc3\u7684\u7b11\u51fa\u4e86\u58f0\uff0c\u867d\u7136\u6570\u636e\u6709\u65f6\u8fd8\u662f\u51fa\u9519\uff0c\u4f46\u662f\u8d77\u7801\u5b83\u8bfb\u51fa\u6765\u4e86\uff0c\u4e0d\u50cf\u4ee5\u524d\u7684255\u3001255\u3001255\u3001255\u90a3\u6837\u7edd\u671b\u4e86\uff0c\u8fd9\u4ef6\u4e8b\u7ed9\u4e86\u6211\u4e00\u4e2a\u6559\u8bad\uff0c\u5148\u4ece\u81ea\u5df1\u53ef\u4ee5\u627e\u7684\u5730\u65b9\u6765\u627e\u9519\u8bef\uff0c\u4e0d\u8981\u628a\u9519\u8bef\u90fd\u63a8\u5230\u81ea\u5df1\u4e0d\u4e86\u89e3\u6216\u8005\u6ca1\u6709\u6d89\u8db3\u7684\u9886\u57df\uff0c\uff08python\u4e5f\u662f\u81ea\u5df1\u4e0d\u592a\u4e86\u89e3\u7684\u9886\u57df\u4f46\u662f\u6211\u4e3a\u4ec0\u4e48\u5bf9\u5b83\u6709\u4e00\u79cd\u83ab\u540d\u5176\u5999\u7684\u81ea\u4fe1\uff0c\u81ea\u4fe1\u5b83\u4e0d\u4f1a\u53d1\u751f\u9519\u8bef\uff1f\u3002\u3002\u3002\uff09<\/p>\n<p>\u6570\u636e\u662f\u8bfb\u51fa\u6765\u4e86\uff0c\u4f46\u662f\u6570\u636e\u8fd8\u662f\u4e0d\u5bf9\u52b2\u3002\u3002\u3002\u3002\u65f6\u597d\u65f6\u574f\uff0c\u59e8\u7236\u8bf4\u4e0a\u62c9\u7535\u963b\u8d8a\u5927\u8bfb\u53d6\u6570\u636e\u8d8a\u7a33\u5b9a\uff0c\u7136\u540e\u6211\u5c31\u628a\u677f\u5b50\u4e0a\u76841k\u7684\u8d34\u7247\u7535\u963b\u7ed9\u641e\u4e0b\u6765\u4e86\u3002\u6362\u4e86\u4e00\u4e2a5.1k\u7684\u7535\u963b\u7ed3\u679c\u6570\u636e\u8fd8\u662f\u8bfb\u9519\uff0c\u7136\u540e\u59e8\u7236\u8bf4\u627e\u5230\u4e86\u6bdb\u75c5\u6240\u5728\uff0c\u7ed3\u679c\u53c8\u6362\u4e86\u4e2a3.9k\u7684\u7535\u963b\uff0c\u6570\u636e\u4f9d\u7136\u4e0d\u662f100{d4daabd1ba368d9860c36387ddb72bbda14f8f9559d69d60a952800885260c03}\u6b63\u786e\uff0c\u7136\u540e\u59e8\u7236\u5efa\u8bae\u6211\u4ece\u7a0b\u5e8f\u65b9\u9762\u7740\u624b\uff0c\u5199\u4e00\u4e2a\u7ea0\u9519\u7684\u6570\u503c\u6bd4\u8f83\u5faa\u73af\uff0c\u6211\u5f53\u7136\u505a\u4e0d\u5230\u554a\uff0c\u6240\u4ee5\u6211\u5c31\u60f3\u7528for\u505a\u4e00\u4e2a\u6761\u4ef6\u5faa\u73af\uff0c\u7136\u540e\u683d\u5728range\u4e0a\uff0c\u6839\u672c\u641e\u4e0d\u61c2\u5728\u4e00\u4e2a\u6570\u96c6\u4e2d\u9009\u6570\u4ec0\u4e48\u4ec0\u4e48\u7684\uff0c\u6700\u540e\u9009\u7528\u4e86while\u7684\u65e0\u9650\u5faa\u73af\u548cif\u3001elif\u3001else\u505a\u8fdb\u4e00\u6b65\u7684\u5224\u65ad\u548c\u51b3\u5b9abreak\u7684\u65f6\u673a\uff0c\u6700\u540e\u6211\u6210\u529f\u4e86\uff01\u4e3a\u4e86\u4fdd\u9669\u548c\u4f20\u611f\u5668\u9884\u70ed\uff08\u4e0d\u77e5\u9053\u9884\u70ed\u662f\u4ec0\u4e48\u9b3c\u3002\u3002\u81ea\u5df1\u778e\u7f16\u7684\uff09\uff0c\u6211\u5728\u5faa\u73af\u524d\u9762\u5148\u6267\u884c\u4e00\u904d\u7a0b\u5e8f\u3002<\/p>\n<p>\u4eceue\u4e0a\u76f4\u63a5\u7c98\u8d34\u5230word\u4e0a\u7684\u683c\u5f0f\u53ef\u80fd\u4f1a\u9b3c\u755c\u5927\u5bb6\u89c1\u8c05<\/p>\n<p>\u4e0b\u8f7d\u94fe\u63a5\uff1a<a href=\"http:\/\/sxfu.tk\/wp-content\/uploads\/2017\/02\/\u771f\u6b63\u7684\u81ea\u7f16DTH11\u5e26\u7ea0\u9519.zip\">\u771f\u6b63\u7684\u81ea\u7f16DTH11\u5e26\u7ea0\u9519<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>#!\/usr\/bin\/python<\/p>\n<p>import RPi.GPIO as GPIO<\/p>\n<p>import time<\/p>\n<p>channel =12<\/p>\n<p>data = []<\/p>\n<p>j = 0<\/p>\n<p>GPIO.setmode(GPIO.BOARD)<\/p>\n<p>time.sleep(2)<\/p>\n<p>GPIO.setup(channel, GPIO.OUT)<\/p>\n<p>GPIO.output(channel, GPIO.LOW)<\/p>\n<p>time.sleep(0.02)<\/p>\n<p>GPIO.output(channel, GPIO.HIGH)<\/p>\n<p>GPIO.setup(channel, GPIO.IN)<\/p>\n<p>while GPIO.input(channel) == GPIO.LOW:<\/p>\n<p>continue<\/p>\n<p>while GPIO.input(channel) == GPIO.HIGH:<\/p>\n<p>continue<\/p>\n<p>while j &lt; 40:<\/p>\n<p>k = 0<\/p>\n<p>while GPIO.input(channel) == GPIO.LOW:<\/p>\n<p>continue<\/p>\n<p>while GPIO.input(channel) == GPIO.HIGH:<\/p>\n<p>k += 1<\/p>\n<p>if k &gt; 100:<\/p>\n<p>break<\/p>\n<p>if k &lt; 8:<\/p>\n<p>data.append(0)<\/p>\n<p>else:<\/p>\n<p>data.append(1)<\/p>\n<p>j += 1<\/p>\n<p>print &#8220;\u4f20\u611f\u5668\u5de5\u4f5c\u4e2d&#8221;<\/p>\n<p>humidity_bit = data[0:8]<\/p>\n<p>humidity_point_bit = data[8:16]<\/p>\n<p>temperature_bit = data[16:24]<\/p>\n<p>temperature_point_bit = data[24:32]<\/p>\n<p>check_bit = data[32:40]<\/p>\n<p>humidity = 0<\/p>\n<p>humidity_point = 0<\/p>\n<p>temperature = 0<\/p>\n<p>temperature_point = 0<\/p>\n<p>check = 0<\/p>\n<p>for i in range(8):<\/p>\n<p>humidity += humidity_bit[i] * 2 ** (7-i)<\/p>\n<p>humidity_point += humidity_point_bit[i] * 2 ** (7-i)<\/p>\n<p>temperature += temperature_bit[i] * 2 ** (7-i)<\/p>\n<p>temperature_point += temperature_point_bit[i] * 2 ** (7-i)<\/p>\n<p>check += check_bit[i] * 2 ** (7-i)<\/p>\n<p>tmp = humidity + humidity_point + temperature + temperature_point<\/p>\n<p>var = 1<\/p>\n<p>while var == 1:<\/p>\n<p>GPIO.setmode(GPIO.BOARD)<\/p>\n<p>channel =12<\/p>\n<p>data = []<\/p>\n<p>j = 0<\/p>\n<p>time.sleep(2)<\/p>\n<p>GPIO.setup(channel, GPIO.OUT)<\/p>\n<p>GPIO.output(channel, GPIO.LOW)<\/p>\n<p>time.sleep(0.025)<\/p>\n<p>GPIO.output(channel, GPIO.HIGH)<\/p>\n<p>GPIO.setup(channel, GPIO.IN)<\/p>\n<p>while GPIO.input(channel) == GPIO.LOW:<\/p>\n<p>continue<\/p>\n<p>while GPIO.input(channel) == GPIO.HIGH:<\/p>\n<p>continue<\/p>\n<p>while j &lt; 40:<\/p>\n<p>k = 0<\/p>\n<p>while GPIO.input(channel) == GPIO.LOW:<\/p>\n<p>continue<\/p>\n<p>while GPIO.input(channel) == GPIO.HIGH:<\/p>\n<p>k += 1<\/p>\n<p>if k &gt; 100:<\/p>\n<p>break<\/p>\n<p>if k &lt; 8:<\/p>\n<p>data.append(0)<\/p>\n<p>else:<\/p>\n<p>data.append(1)<\/p>\n<p>j += 1<\/p>\n<p>print&#8221; &#8221;<\/p>\n<p>humidity_bit = data[0:8]<\/p>\n<p>humidity_point_bit = data[8:16]<\/p>\n<p>temperature_bit = data[16:24]<\/p>\n<p>temperature_point_bit = data[24:32]<\/p>\n<p>check_bit = data[32:40]<\/p>\n<p>humidity = 0<\/p>\n<p>humidity_point = 0<\/p>\n<p>temperature = 0<\/p>\n<p>temperature_point = 0<\/p>\n<p>check = 0<\/p>\n<p>for i in range(8):<\/p>\n<p>humidity += humidity_bit[i] * 2 ** (7 &#8211; i)<\/p>\n<p>humidity_point += humidity_point_bit[i] * 2 ** (7 &#8211; i)<\/p>\n<p>temperature += temperature_bit[i] * 2 ** (7 &#8211; i)<\/p>\n<p>temperature_point += temperature_point_bit[i] * 2 ** (7 &#8211; i)<\/p>\n<p>check += check_bit[i] * 2 ** (7 &#8211; i)<\/p>\n<p>tmp = humidity + humidity_point + temperature + temperature_point<\/p>\n<p>if temperature &lt; 100:<\/p>\n<p>print&#8221;\u6e29\u5ea6\u6b63\u786e&#8221;<\/p>\n<p>#elif humidity &lt; 150:<\/p>\n<p>print&#8221;\u6e7f\u5ea6\u6b63\u786e&#8221;<\/p>\n<p>print &#8220;\u6e29\u5ea6 :&#8221;, temperature, &#8220;*C, \u6e7f\u5ea6 :&#8221;, humidity, &#8220;{d4daabd1ba368d9860c36387ddb72bbda14f8f9559d69d60a952800885260c03}&#8221;<\/p>\n<p>break<\/p>\n<p>else:<\/p>\n<p>print&#8221;\u6570\u636e\u9519\u8bef\uff01\u91cd\u65b0\u8bfb\u53d6&#8221;<\/p>\n<p>GPIO.cleanup()<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5929\u60f3\u628a\u6e29\u5ea6\u4f20\u611f\u5668DTH11\u63a5&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"class_list":["post-484","post","type-post","status-publish","format-standard","hentry","category-reapberry"],"_links":{"self":[{"href":"http:\/\/alextop.top\/index.php?rest_route=\/wp\/v2\/posts\/484"}],"collection":[{"href":"http:\/\/alextop.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/alextop.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/alextop.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/alextop.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=484"}],"version-history":[{"count":0,"href":"http:\/\/alextop.top\/index.php?rest_route=\/wp\/v2\/posts\/484\/revisions"}],"wp:attachment":[{"href":"http:\/\/alextop.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=484"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/alextop.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=484"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/alextop.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}