{"id":237,"date":"2018-07-10T19:00:16","date_gmt":"2018-07-10T11:00:16","guid":{"rendered":"https:\/\/fick707.com\/?p=237"},"modified":"2024-08-01T10:23:49","modified_gmt":"2024-08-01T02:23:49","slug":"iotstudy05-arduino-4bitdisplay","status":"publish","type":"post","link":"https:\/\/fick707.com\/?p=237","title":{"rendered":"\u4e00\u4e2ajava\u5de5\u7a0b\u5e08\u7684IOT\u5165\u95e8\u4e4b\u8def05&#8211;arduino 4\u4f4d\u7ba1\u663e\u793a\u6e29\u5ea6"},"content":{"rendered":"<h2>\u524d\u60c5\u63d0\u793a<\/h2>\n<p>\u8fd8\u8bb0\u5f97\u6211\u7684\u521d\u5fc3\u5417\uff1f\u60f3\u505a\u4e00\u4e2a\u81ea\u52a8\u6d47\u6c34\u7684\u7cfb\u7edf\u3002\u5230\u624b\u7684arduino uno r3\u5f00\u53d1\u677f\u5957\u88c5\u91cc\u6709\u597d\u51e0\u4e2a\u4f20\u611f\u5668\uff0c\u6e29\u5ea6\u4f20\u611f\u5668\uff0c\u58f0\u97f3\u4f20\u611f\u5668\uff0c\u663e\u793a\u5c4f\uff0c\u8fd8\u67094\u4f4d\u6570\u7801\u7ba1\u7b49\u3002<\/p>\n<p>\u6211\u8981\u7684\u571f\u58e4\u6e7f\u5ea6\u4f20\u611f\u5668\uff0c\u7ee7\u7535\u5668\u6ca1\u6709\uff0c\u5c31\u5728\u67d0\u5b9d\u4e0a\u518d\u4e70\u4e86\u3002<\/p>\n<h2>\u5148\u641e\u4e9b\u4e8b\u60c5<\/h2>\n<p>\u7b49\u8fd9\u4e9b\u4e1c\u897f\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4e0d\u9632\u8bd5\u4e00\u7740\u518d\u73a9\u4e00\u4e0b\uff0c\u75284\u4f4d\u6570\u7801\u7ba1\u663e\u793a\u4e00\u4e0b\u6e29\u5ea6\uff1f\u54c8\u54c8\u3002<\/p>\n<h2>\u7b2c\u4e00\u6b65\uff0c\u5148\u73a9\u8f6c\u4f20\u611f\u5668DS18B20<\/h2>\n<p><font color='red'>\u5982\u679c\u4e0d\u60f3\u4ed4\u7ec6\u4e86\u89e3\u8be5\u4f20\u611f\u5668\uff0c\u53ef\u4ee5\u76f4\u63a5\u8df3\u5230\u7b2c\u4e8c\u6b65\u3002<\/font><\/p>\n<h3>\u8017\u6750<\/h3>\n<pre><code>\u6e29\u5ea6\u4f20\u611f\u5668DS18B20 * 1\uff1b\n10k \u03a9 \u7535\u963b * 1\uff1b\n\u8fde\u63a5\u7ebf \u82e5\u5e72\uff1b\n<\/code><\/pre>\n<h3>\u8fde\u63a5\u7ec6\u8282<\/h3>\n<pre><code>1. \u6e29\u5ea6\u4f20\u611f\u5668DS18B20\u5f15\u811a\uff1a\u4e09\u4e2a\u5f15\u811a\uff0c\u5e73\u9762\u9762\u5bf9\u6211\u4eec\u7684\u65f6\u5019\uff0c\u6700\u5de6\u4fa7\u63a5\u5730\uff1b\u6700\u53f3\u4fa7\u63a5+5v\uff1b\u4e2d\u95f4\u662f\u6570\u636e\u5f15\u811a\uff1b\n2. \u6570\u636e\u5f15\u811a\u9700\u8981\u4e00\u4e2a10k \u03a9\u7684\u4e0a\u62c9\u7535\u963b\uff1b\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"\/pics\/iot\/05\/connection.jpg\" alt=\"\" \/><\/p>\n<h3>\u7a0b\u5e8f<\/h3>\n<pre><code>1. \u4f9d\u8d56OneWire\u7c7b\u5e93\n    #include &lt;OneWire.h&gt;\n2. \u4f9d\u8d56DallasTemperature\u7c7b\u5e93\n    #include &lt;DallasTemperature.h&gt; \n    \u8fd9\u4e2a\u7c7b\u5e93\u5c06\u5c01\u88c5\u4e86\u51e0\u4e2a\u6e29\u5ea6\u4f20\u611f\u5668\u7684\u4f7f\u7528\u7a0b\u5e8f\uff0c\u652f\u6301DS18S20\uff0cDS18B20\uff0cDS1822\uff0c\u6211\u4eec\u53ef\u4ee5\u5f88\u7b80\u5355\u7684\u4f7f\u7528\u5176api\u8c03\u7528\u8be5\u6a21\u5757\u7684\u529f\u80fd\uff1b\n\n\u5982\u679c\u8fd8\u6ca1\u6709\u5b89\u88c5OneWire\u7c7b\u5e93\uff0c\u53ef\u4ee5\u6839\u636e\u4ee5\u4e0b\u6b65\u9aa4\u5b89\u88c5\uff0c\u5982\u679c\u6ca1\u6709\u5b89\u88c5DallasTemperature\u7c7b\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528[github\u4e0a\u7684](https:\/\/github.com\/milesburton\/Arduino-Temperature-Control-Library)\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"\/pics\/iot\/05\/00001.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"\/pics\/iot\/05\/00002.png\" alt=\"\" \/><\/p>\n<h4>\u4ee3\u7801<\/h4>\n<pre><code class=\"\">#include &lt;OneWire.h&gt;\n#include &lt;DallasTemperature.h&gt;\n\/\/ Data wire is plugged into port 2 on the Arduino\n#define ONE_WIRE_BUS A0\n\/\/ Setup a oneWire instance to communicate with any OneWire devices (not just Maxim\/Dallas temperature ICs)\nOneWire oneWire(ONE_WIRE_BUS);\n\/\/ Pass our oneWire reference to Dallas Temperature. \nDallasTemperature sensors(&amp;oneWire);\nvoid setup(void)\n{\n  \/\/ start serial port\n  Serial.begin(9600);\n  Serial.println(\"Dallas Temperature IC Control Library Demo\");\n  \/\/ Start up the library\n  sensors.begin();\n}\nvoid loop(void)\n{ \n  \/\/ call sensors.requestTemperatures() to issue a global temperature \n  \/\/ request to all devices on the bus\n  Serial.print(\"Requesting temperatures...\");\n  sensors.requestTemperatures(); \/\/ Send the command to get temperatures\n  Serial.println(\"DONE\");\n\n  Serial.print(\"Temperature for the device 1 (index 0) is: \");\n  Serial.println(sensors.getTempCByIndex(0));  \n  delay(3000);\n}\n<\/code><\/pre>\n<h2>\u7b2c\u4e8c\u6b65\uff0c\u73a9\u8f6c4\u4f4d\u7ba1\u8ba9\u6e29\u5ea6\u663e\u793a\u57284\u4f4d\u7ba1\u4e0a<\/h2>\n<h3>\u8017\u6750<\/h3>\n<pre><code>\u7ebf\uff1a\u82e5\u5e72\uff1b\n1k \u03a9 \u7535\u963b * 4\uff1b\n10k \u03a9 \u7535\u963b * 1\uff1b\n4\u4f4d\u7ba1 * 1\uff083641AS\uff09\uff1b\n\u6e29\u5ea6\u4f20\u611f\u5668 * 1 (DS18B20);\n<\/code><\/pre>\n<h3>\u7ec6\u8282<\/h3>\n<p><a href=\"https:\/\/blog.csdn.net\/ki1381\/article\/details\/52304573\">\u767e\u5ea6\u4e0a\u5b66\u4e60\u5230\u7684\u6559\u7a0b<\/a><\/p>\n<p><img decoding=\"async\" src=\"\/pics\/iot\/05\/connection01.jpg\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"\/pics\/iot\/05\/pin.jpg\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"\/pics\/iot\/05\/effect.jpg\" alt=\"\" \/><\/p>\n<h4>\u4ee3\u7801<\/h4>\n<pre><code class=\"\">\/*\n  Unit1 A1\n  Unit2 A2\n  Unit3 A3\n  Unit4 A4\n\n  A-G,DP  3-10\n\n  A0 18B20's data pin \n\n*\/\n\n\n#include &lt;OneWire.h&gt;\n#include &lt;DallasTemperature.h&gt;\n\n#define TempSensor A0\n\nOneWire oneWire(TempSensor);\nDallasTemperature sensors(&amp;oneWire);\n\n#define EyesDelay 1\n\nvoid SelectUnit(int ID)\n{\n  switch (ID)\n  {\n    case 1:\n      digitalWrite(A1, LOW);\n      digitalWrite(A2, HIGH);\n      digitalWrite(A3, HIGH);\n      digitalWrite(A4, HIGH);\n      break;\n    case 2:\n      digitalWrite(A1, HIGH);\n      digitalWrite(A2, LOW);\n      digitalWrite(A3, HIGH);\n      digitalWrite(A4, HIGH);\n      break;\n    case 3:\n      digitalWrite(A1, HIGH);\n      digitalWrite(A2, HIGH);\n      digitalWrite(A3, LOW);\n      digitalWrite(A4, HIGH);\n      break;\n    case 4:\n      digitalWrite(A1, HIGH);\n      digitalWrite(A2, HIGH);\n      digitalWrite(A3, HIGH);\n      digitalWrite(A4, LOW);\n      break;\n    default:\n      digitalWrite(A1, HIGH);\n      digitalWrite(A2, HIGH);\n      digitalWrite(A3, HIGH);\n      digitalWrite(A4, HIGH);\n      break;\n  }\n}\n\nvoid ShowData(int UnitID, char * data)\n{\n\n  SelectUnit(UnitID);\n\n  for (int i = 0; i &lt; 8; i++)\n  {\n    if (data[i] == '0')\n    {\n      digitalWrite(i + 3, LOW);\n    }\n    else\n    {\n      digitalWrite(i + 3, HIGH);\n    }\n  }\n}\n\nvoid ShowNone()\n{\n  digitalWrite(A1, HIGH);\n  digitalWrite(A2, HIGH);\n  digitalWrite(A3, HIGH);\n  digitalWrite(A4, HIGH);\n\n  for (int i = 3; i &lt;= 10 ; i++)\n  {\n    digitalWrite(i, LOW);\n  }\n}\n\n\n\nvoid Show(int UnitID, char a)\n{\nShowNone();\n  switch (a)\n  {\n    case '0':\n        ShowData(UnitID, \"11111100\");\n      break;\n    case '1':\n      ShowData(UnitID, \"01100000\");\n      break;\n    case '2':\n      ShowData(UnitID, \"11011010\");\n      break;\n    case '3':\n     ShowData(UnitID, \"11110010\");\n      break;\n    case '4':\n      ShowData(UnitID, \"01100110\");\n      break;\n    case '5':\n      ShowData(UnitID, \"10110110\");\n      break;\n    case '6':\n        ShowData(UnitID, \"10111110\");\n      break;\n    case '7':\n        ShowData(UnitID, \"11100000\");\n      break;\n    case '8':\n      ShowData(UnitID, \"11111110\");\n      break;\n    case '9':\n        ShowData(UnitID, \"11110110\");\n      break;\n    case '.':\n      ShowData(UnitID, \"00000001\");\n      break;\n    case '-':\n      ShowData(UnitID, \"00000010\");\n      break;\n    default:\n      ShowNone();\n      break;\n\n  }\n\n    delay(EyesDelay);\n}\n\nvoid setup() {\n  \/\/ put your setup code here, to run once:\n  Serial.begin(9600);\n  for (int i = 3; i &lt;= 10; i++)\n  {\n    pinMode(i, OUTPUT);\n  }\n\n  pinMode(A1, OUTPUT);\n  pinMode(A2, OUTPUT);\n  pinMode(A3, OUTPUT);\n  pinMode(A4, OUTPUT);\n\n  sensors.begin();\n\n}\n\nvoid ShowTemp(float val)\n{\n  char buf[8];\n  for (int i = 0; i &lt; 8; i++)\n  {\n    buf[i] = '\\0';\n  }\n  dtostrf(val, 1, 3, buf);\n\n  if (buf[1] == '.') \/\/0.123\n  {\n    Show(1, buf[0]);\n    Show(1, '.');\n    Show(2, buf[2]);\n    Show(3, buf[3]);\n    Show(4, buf[4]);\n  }\n\n  if (buf[2] == '.') \/\/11.12\n  {\n    Show(1, buf[0]);\n    Show(2, buf[1]);\n    Show(2, '.');\n    Show(3, buf[3]);\n    Show(4, buf[4]);\n  }\n\n\n  if (buf[3] == '.') \/\/111.12\n  {\n    Show(1, buf[0]);\n    Show(2, buf[1]);\n    Show(3, buf[2]);\n    Show(3, '.');\n    Show(4, buf[4]);\n  }\n\n  if (buf[4] == '.') \/\/1112.12\n  {\n    Show(1, buf[0]);\n    Show(2, buf[1]);\n    Show(3, buf[2]);\n    Show(4, buf[3]);\n    Show(4, '.');\n  }\n}\n\nvoid loop() {\n \/\/ Get 18B20 Data\n  sensors.requestTemperatures();\n  float t = sensors.getTempCByIndex(0); \n  Serial.print(\"Temperature is: \");\n  Serial.println(t);  \n  delay(1000);\n\n  for (int i = 0; i &lt; 600; i++)\n  {\n    ShowTemp(t);\n  }\n\n  ShowNone();\n}\n\n<\/code><\/pre>\n<p>4\u4f4d\u7ba1\u7684\u64cd\u4f5c\u4e5f\u53ef\u4ee5\u641e\u6210\u4e00\u4e2a\u7c7b\u5e93\uff0c\u6709\u5174\u8da3\u7684\u540c\u5b66\u53ef\u4ee5\u8bd5\u4e00\u8bd5\u54c8\u3002<\/p>\n<h3>\u5b66\u5230<\/h3>\n<pre><code>\u4e0a\u62c9\u7535\u963b\uff1a\u4e0a\u62c9\u5c31\u662f\u5c06\u4e0d\u786e\u5b9a\u7684\u4fe1\u53f7\u901a\u8fc7\u4e00\u4e2a\u7535\u963b\u94b3\u4f4d\u5728\u9ad8\u7535\u5e73\uff0c\u7535\u963b\u540c\u65f6\u8d77\u9650\u6d41\u4f5c\u7528\u3002\u4e0b\u62c9\u540c\u7406\uff0c\u4e5f\u662f\u5c06\u4e0d\u786e\u5b9a\u7684\u4fe1\u53f7\u901a\u8fc7\u4e00\u4e2a\u7535\u963b\u94b3\u4f4d\u5728\u4f4e\u7535\u5e73\u3002\n\n\u4e0a\u62c9\u662f\u5bf9\u5668\u4ef6\u8f93\u5165\u7535\u6d41\uff0c\u4e0b\u62c9\u662f\u8f93\u51fa\u7535\u6d41\uff1b\u5f3a\u5f31\u53ea\u662f\u4e0a\u62c9\u7535\u963b\u7684\u963b\u503c\u4e0d\u540c\uff0c\u6ca1\u6709\u4ec0\u4e48\u4e25\u683c\u533a\u5206\uff1b\u5bf9\u4e8e\u975e\u96c6\u7535\u6781\uff08\u6216\u6f0f\u6781\uff09\u5f00\u8def\u8f93\u51fa\u578b\u7535\u8def\uff08\u5982\u666e\u901a\u95e8\u7535\u8def\uff09\u63d0\u4f9b\u7535\u6d41\u548c\u7535\u538b\u7684\u80fd\u529b\u662f\u6709\u9650\u7684\uff0c\u4e0a\u62c9\u7535\u963b\u7684\u529f\u80fd\u4e3b\u8981\u662f\u4e3a\u96c6\u7535\u6781\u5f00\u8def\u8f93\u51fa\u578b\u7535\u8def\u8f93\u51fa\u7535\u6d41\u901a\u9053\u3002\n<\/code><\/pre>\n<p>\u4e0a\u62c9\u7535\u963b\u56fe\u793a\uff1a<\/p>\n<p><img decoding=\"async\" src=\"\/pics\/iot\/05\/upr.jpg\" alt=\"\" \/><\/p>\n<p>\u4e0b\u62c9\u7535\u963b(R1)\u56fe\u793a(\u610f\u601d\u662f\u5c06\u7535\u8def\u8282\u70b9\u7684\u7535\u5e73\u5411\u4f4e\u65b9\u5411\uff08\u5730\uff09\u62c9)\uff1a<\/p>\n<p><img decoding=\"async\" src=\"\/pics\/iot\/05\/downr.jpg\" alt=\"\" \/><\/p>\n<p>2018.06.02<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u60c5\u63d0\u793a \u8fd8\u8bb0\u5f97\u6211\u7684\u521d\u5fc3\u5417\uff1f\u60f3\u505a\u4e00\u4e2a\u81ea\u52a8\u6d47\u6c34\u7684\u7cfb\u7edf\u3002\u5230\u624b\u7684arduino uno r3\u5f00\u53d1\u677f\u5957\u88c5\u91cc\u6709 &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[7],"series":[27],"class_list":["post-237","post","type-post","status-publish","format-standard","hentry","category-iot","tag-iot","series-iot_step_by_step"],"_links":{"self":[{"href":"https:\/\/fick707.com\/index.php?rest_route=\/wp\/v2\/posts\/237"}],"collection":[{"href":"https:\/\/fick707.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fick707.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fick707.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fick707.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=237"}],"version-history":[{"count":2,"href":"https:\/\/fick707.com\/index.php?rest_route=\/wp\/v2\/posts\/237\/revisions"}],"predecessor-version":[{"id":239,"href":"https:\/\/fick707.com\/index.php?rest_route=\/wp\/v2\/posts\/237\/revisions\/239"}],"wp:attachment":[{"href":"https:\/\/fick707.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fick707.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fick707.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=237"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/fick707.com\/index.php?rest_route=%2Fwp%2Fv2%2Fseries&post=237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}