{"id":1189,"date":"2022-03-25T15:51:51","date_gmt":"2022-03-25T07:51:51","guid":{"rendered":"https:\/\/104.es\/?p=1189"},"modified":"2022-03-25T15:51:51","modified_gmt":"2022-03-25T07:51:51","slug":"raspberry-pi-dht11","status":"publish","type":"post","link":"https:\/\/104.es\/index.php\/2022\/03\/25\/raspberry-pi-dht11\/","title":{"rendered":"\u6a39\u8393\u6d3e\u5229\u7528DHT11\u8b80\u53d6\u74b0\u5883\u6eab\u6fd5\u5ea6"},"content":{"rendered":"\n<p>\u6a39\u8393\u6d3e\u672c\u8eab\u96d6\u7136\u6c92\u6709\u81ea\u5e36\u611f\u6e2c\u5668\uff0c\u4f46\u662f\u900f\u904e\u4e00\u4e9b\u611f\u6e2c\u5668\u5176\u5be6\u53ef\u4ee5\u5f88\u5bb9\u6613\u900f\u904e\u5225\u4eba\u5beb\u597d\u7684\u7a0b\u5f0f\u6a21\u7d44\uff0c\u547c\u53eb\u5b83\u7684\u6307\u4ee4\u5373\u53ef\u53d6\u5f97\u5916\u90e8\u7684\u8cc7\u6599\uff0c\u5176\u4e2d\u6eab\u6fd5\u5ea6\u662f\u6700\u5be6\u7528\u7684\u8cc7\u8a0a\u4e4b\u4e00\uff0c\u7576\u7136\u4e5f\u662f\u6700\u5bb9\u6613\u4f7f\u7528\u7684\u611f\u6e2c\u5668\u3002<\/p>\n\n\n\n<p>\u9996\u5148\uff0c\u6211\u5011\u4f7f\u7528\u7684\u6eab\u6fd5\u5ea6\u611f\u6e2c\u6a21\u7d44\u662fDHT11\uff0c\u53ef\u4ee5\u5728\u4ee5\u4e0b\u7684\u9023\u7d50\u4e2d\u627e\u5230\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-\u53f0\u7063\u7269\u806f\u79d1\u6280-taiwaniot-studio wp-block-embed-\u53f0\u7063\u7269\u806f\u79d1\u6280-taiwaniot-studio\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"SyWQarAA7d\"><a href=\"https:\/\/www.taiwaniot.com.tw\/product\/dht11-%e6%ba%ab%e6%bf%95%e5%ba%a6%e6%84%9f%e6%b8%ac%e5%99%a8%e5%82%b3%e6%84%9f%e5%99%a8-%e6%a8%a1%e7%b5%84-%e9%80%81-%e6%a2%9d%e6%9d%9c%e9%82%a6%e7%b7%9a\/\">DHT11 \u6eab\u6fd5\u5ea6 \u611f\u6e2c\u5668 \u50b3\u611f\u5668 \u6a21\u7d44 \u9001 \u675c\u90a6\u7dda<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"DHT11 \u6eab\u6fd5\u5ea6 \u611f\u6e2c\u5668 \u50b3\u611f\u5668 \u6a21\u7d44 \u9001 \u675c\u90a6\u7dda &#8212; \u53f0\u7063\u7269\u806f\u79d1\u6280 TaiwanIOT Studio\" src=\"https:\/\/www.taiwaniot.com.tw\/product\/dht11-%e6%ba%ab%e6%bf%95%e5%ba%a6%e6%84%9f%e6%b8%ac%e5%99%a8%e5%82%b3%e6%84%9f%e5%99%a8-%e6%a8%a1%e7%b5%84-%e9%80%81-%e6%a2%9d%e6%9d%9c%e9%82%a6%e7%b7%9a\/embed\/#?secret=SyWQarAA7d\" data-secret=\"SyWQarAA7d\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>\u9019\u500b\u611f\u6e2c\u5668\u6709\u591a\u7a2e\u7248\u672c\uff0c\u6211\u5011\u4f7f\u7528\u76843\u652f\u8173\u7684\u7248\u672c\uff0c\u5b83\u5011\u5206\u5225\u662f\u6b63\u6975\u3001\u8ca0\u6975\u3001\u4ee5\u53ca\u8cc7\u6599\u7dda\uff08Data\u6216\u662fOut\uff09\u3002\u5728\u9023\u63a5\u7dda\u4e0a\uff0c\u8acb\u628a\u6b63\u6975\u9023\u5230\u6a39\u8393\u6d3e\u677f\u5b50\u4e0a\u7684\u7b2c2\u8173\uff08+5V\uff09\uff0c\u8ca0\u6975\u9023\u63a5\u5230\u7b2c6\u8173\uff08GND\uff09\uff0c\u8cc7\u6599\u7dda\u5247\u9023\u63a5\u5230\u4efb\u4e00GPIO\u63a5\u8173\uff0c\u5728\u6b64\u4f8b\u4e2d\u6211\u5011\u628a\u5b83\u653e\u5728GPIO4\uff08\u5be6\u9ad4\u9023\u7dda\u662f\u7b2c7\u8173\uff09\uff0c\u5982\u4e0b\u9762\u7684\u7167\u7247\u6240\u793a\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"http:\/\/104es.nkust.org\/wp-content\/uploads\/2022\/03\/310907.jpg?w=1024\" alt=\"\" class=\"wp-image-1194\" \/><\/figure>\n\n\n\n<p>\u8981\u7279\u5225\u7559\u610f\u7684\u662f\uff0c\u4e0d\u540c\u516c\u53f8\u51fa\u54c1\u7684DHT11\u7684\u63a5\u8173\u4f4d\u7f6e\u6709\u8a31\u591a\u5dee\u7570\uff0c\u53ea\u8981\u63a5\u932fDHT11\u5c31\u6703\u71d2\u6bc0\uff0c\u6240\u4ee5\u5728\u9023\u63a5\u6642\u8981\u7279\u5225\u5c0f\u5fc3\u3002<\/p>\n\n\n\n<p class=\"has-text-align-center\">\u3010\u4ee5\u4e0b\u662fRaspberry Pi 3\u7684\u64cd\u4f5c\u65b9\u5f0f\uff0c\u5982\u679c\u4f60\u4f7f\u7528\u7684\u662fRasbperry Pi 4\u7684\u8a71\uff0c\u8acb\u770b\u672c\u6587\u7684\u5f8c\u534a\u6bb5\u8aaa\u660e\u3011<\/p>\n\n\n\n<p>\u9023\u63a5\u5b8c\u7562\u4e4b\u5f8c\uff0c\u8acb\u5728\u4f60\u7684\u6a39\u8393\u6d3e\u74b0\u5883\u4e2d\u5b89\u88dd\u4ee5\u4e0b\u7684\u6a21\u7d44\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install Adafruit_DHT<\/code><\/pre>\n\n\n\n<p>\u7136\u5f8c\u5229\u7528\u4ee5\u4e0b\u7684\u7a0b\u5f0f\u78bc\u5373\u53ef\u8b80\u53d6\u74b0\u5883\u7684\u6eab\u6fd5\u5ea6\u4e86\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import Adafruit_DHT\nimport time\ndht11 = Adafruit_DHT.DHT11\nDHT_PIN = 4\nwhile True:\n    h, t = Adafruit_DHT.read_retry(dht11, DHT_PIN)\n    print(h, t)\n    time.sleep(1)<\/code><\/pre>\n\n\n\n<p>\u8f38\u51fa\u7d50\u679c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1003\" height=\"239\" src=\"http:\/\/104es.nkust.org\/wp-content\/uploads\/2022\/03\/image-20.png?w=1003\" alt=\"\" class=\"wp-image-1195\" srcset=\"https:\/\/104.es\/wp-content\/uploads\/2022\/03\/image-20.png 1003w, https:\/\/104.es\/wp-content\/uploads\/2022\/03\/image-20-300x71.png 300w, https:\/\/104.es\/wp-content\/uploads\/2022\/03\/image-20-768x183.png 768w\" sizes=\"auto, (max-width: 1003px) 100vw, 1003px\" \/><\/figure>\n\n\n\n<p>\u6700\u5f8c\u8981\u7559\u610f\u4e00\u9ede\uff0c\u4e0a\u8ff0\u6a21\u7d44\u53ea\u9069\u65bc\u6a39\u8393\u6d3e3\uff0c\u5728Pi 4\u4e0a\u4e26\u7121\u6cd5\u9806\u5229\u57f7\u884c\u3002<\/p>\n\n\n\n<p class=\"has-text-align-center\">\u3010\u65b0\u7248\u7684\u6a39\u8393\u6d3e4\u8981\u6539\u70ba\u4f7f\u7528\u4ee5\u4e0b\u9019\u500b\u6a21\u7d44\u624d\u884c\u3011<\/p>\n\n\n\n<p>https:\/\/github.com\/adafruit\/Adafruit_CircuitPython_DHT<\/p>\n\n\n\n<p>Pi 4\u8b80\u53d6DHT11\u6eab\u6fd5\u5ea6\u7684\u65b9\u6cd5\u5982\u4e0b\uff0c\u9996\u5148\u8981\u5b89\u88dd\u53e6\u5916\u4e00\u500bPython  \u6a21\u7d44\uff0c\u6307\u4ee4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install adafruit-circuitpython-dht<\/code><\/pre>\n\n\n\n<p>\u9084\u6709\u5728Linux\u4f5c\u696d\u7cfb\u7d71\u4e0b\u5b89\u88ddlibgpiod2\u5957\u4ef6\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install libgpiod2 -y<\/code><\/pre>\n\n\n\n<p>\u7136\u5f8c\uff0c\u4f7f\u7528\u4ee5\u4e0b\u7684\u7a0b\u5f0f\u5c31\u53ef\u4ee5\u5728Pi 4\u4e0b\u9032\u884c\u6eab\u6fd5\u5ea6\u7684\u8b80\u53d6\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import adafruit_dht\nimport time\nimport board\ndht11 = adafruit_dht.DHT11(board.D4)\nwhile True:\n    t = dht11.temperature\n    h = dht11.humidity\n    print(\"{}C, {}%\".format(t, h))\n    time.sleep(1)<\/code><\/pre>\n\n\n\n<p>\u8f38\u51fa\u7684\u7d50\u679c\u5982\u4e0b\u5716\u6240\u793a\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/104es.nkust.org\/wp-content\/uploads\/2022\/12\/image.png?w=669\" alt=\"\" class=\"wp-image-1846\" width=\"380\" height=\"133\" srcset=\"https:\/\/104.es\/wp-content\/uploads\/2022\/12\/image.png 669w, https:\/\/104.es\/wp-content\/uploads\/2022\/12\/image-300x105.png 300w\" sizes=\"auto, (max-width: 380px) 100vw, 380px\" \/><\/figure>\n\n\n\n<p>\u7d50\u5408\u4e4b\u524d\u5b78\u7fd2\u904e\u7684LCD\u7684\u8f38\u51fa\uff0c\u53ef\u4ee5\u628a\u7a0b\u5f0f\u4fee\u6539\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import adafruit_dht\nimport time\nimport board\nimport smbus2, sys\nfrom RPLCD.i2c import CharLCD\n\nsys.modules&#091;'smbus'] = smbus2\nlcd = CharLCD('PCF8574', address=0x27, port=1, backlight_enabled = True)\nlcd.clear()\nlcd.cursor_pos = (0, 0)\nlcd.write_string(\"NKUST Welcome\")\n\ndht11 = adafruit_dht.DHT11(board.D4)\nwhile True:\n    t = dht11.temperature\n    h = dht11.humidity\n    print(\"{}C, {}%\".format(t, h))\n    lcd.cursor_pos = (1, 0)\n    lcd.write_string(\"{}C, {}%\".format(t, h))\n    time.sleep(1)<\/code><\/pre>\n\n\n\n<p>\u4e0a\u8ff0\u7a0b\u5f0f\u57f7\u884c\u4e4b\u5f8c\uff0c\u9664\u4e86\u9084\u662f\u4e00\u6a23\u6703\u5728\u756b\u9762\u4e0a\u8f38\u51fa\u76ee\u524d\u6240\u5075\u6e2c\u5230\u7684\u6eab\u6fd5\u5ea6\u4e4b\u5916\uff0c\u4e5f\u6703\u5728LCD\u4e0a\u986f\u793a\u5982\u4e0b\u6240\u793a\u7684\u8a0a\u606f\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1267\" height=\"616\" src=\"http:\/\/104es.nkust.org\/wp-content\/uploads\/2022\/12\/image-1.png?w=1024\" alt=\"\" class=\"wp-image-1850\" srcset=\"https:\/\/104.es\/wp-content\/uploads\/2022\/12\/image-1.png 1267w, https:\/\/104.es\/wp-content\/uploads\/2022\/12\/image-1-300x146.png 300w, https:\/\/104.es\/wp-content\/uploads\/2022\/12\/image-1-1024x498.png 1024w, https:\/\/104.es\/wp-content\/uploads\/2022\/12\/image-1-768x373.png 768w\" sizes=\"auto, (max-width: 1267px) 100vw, 1267px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u6a39\u8393\u6d3e\u672c\u8eab\u96d6\u7136\u6c92\u6709\u81ea\u5e36\u611f\u6e2c\u5668\uff0c\u4f46\u662f\u900f\u904e\u4e00\u4e9b\u611f\u6e2c\u5668\u5176\u5be6\u53ef\u4ee5\u5f88\u5bb9\u6613\u900f\u904e\u5225\u4eba\u5beb\u597d\u7684\u7a0b\u5f0f\u6a21\u7d44\uff0c\u547c\u53eb\u5b83\u7684\u6307\u4ee4\u5373\u53ef\u53d6\u5f97\u5916\u90e8\u7684\u8cc7\u6599\uff0c\u5176\u4e2d\u6eab\u6fd5\u5ea6\u662f\u6700\u5be6\u7528\u7684\u8cc7\u8a0a\u4e4b\u4e00\uff0c\u7576\u7136\u4e5f\u662f\u6700\u5bb9\u6613\u4f7f\u7528\u7684\u611f\u6e2c\u5668\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[17],"tags":[],"class_list":["post-1189","post","type-post","status-publish","format-standard","hentry","category-raspberry-pi"],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/1189","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/comments?post=1189"}],"version-history":[{"count":0,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/1189\/revisions"}],"wp:attachment":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/media?parent=1189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/categories?post=1189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/tags?post=1189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}