{"id":196,"date":"2017-05-08T16:37:53","date_gmt":"2017-05-08T07:37:53","guid":{"rendered":"http:\/\/home.hiroshima-u.ac.jp\/~tigawa\/?p=196"},"modified":"2019-10-17T22:26:25","modified_gmt":"2019-10-17T13:26:25","slug":"arduino%e3%81%a7%e6%b0%b4%e6%a7%bd%e3%81%ae%e6%b8%a9%e5%ba%a6%e7%ae%a1%e7%90%86","status":"publish","type":"post","link":"https:\/\/home.hiroshima-u.ac.jp\/~tigawa\/?p=196","title":{"rendered":"[iot][arduino][breeding]Arduino\u3067\u6c34\u69fd\u306e\u6e29\u5ea6\u7ba1\u7406"},"content":{"rendered":"<p>\u5b89\u4fa1\u306a\u30de\u30a4\u30b3\u30f3\u57fa\u76e4\u3067\u3042\u308bArduino\u3092\u4f7f\u3063\u3066\u3001\u6c34\u69fd\u306e\u6e29\u5ea6\u3092\u30af\u30e9\u30a6\u30c9\u30b5\u30fc\u30d3\u30b9\u3092\u5229\u7528\u3057\u3066\u30e2\u30cb\u30bf\u30ea\u30f3\u30b0\u3057\u3001\u3055\u3089\u306b\u4e00\u5b9a\u306e\u6e29\u5ea6\u304b\u3089\u5916\u308c\u308b\u3068\u30a2\u30e9\u30fc\u30c8\u3092\u30e1\u30fc\u30eb\u3057\u3066\u304f\u308c\u308b\u30b7\u30b9\u30c6\u30e0\u3092\u4f5c\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u8cfc\u5165\u3057\u305f\u306e\u306f\u3001\u4ee5\u4e0b\u306e\u6a5f\u6750<br \/>\n\u30fb<a href=\"http:\/\/amzn.to\/2sn1dUl\" target=\"_blank\" rel=\"noopener noreferrer\">Arduino Uno<\/a> (\u306e\u30af\u30ed\u30fc\u30f3\u306e\u5b89\u7269\u30011,000\u5186\u7a0b\u5ea6)<br \/>\n\u30fb<a href=\"http:\/\/amzn.to\/2tp06IF\" target=\"_blank\" rel=\"noopener noreferrer\">Ethernet Shield for Arduino Uno<\/a> (\u306e\u30af\u30ed\u30fc\u30f3\u306e\u5b89\u7269\u30011,500\u5186\u7a0b\u5ea6\uff09<br \/>\n\u30fb<a href=\"http:\/\/amzn.to\/2smLILS\" target=\"_blank\" rel=\"noopener noreferrer\">\u6e29\u5ea6\u30bb\u30f3\u30b5\u30fc DS18B20<br \/>\n<\/a>\u30fb<a href=\"http:\/\/amzn.to\/2uj60HK\">\u30d6\u30ec\u30c3\u30c9\u30dc\u30fc\u30c9<br \/>\n<\/a>\u30fb<a href=\"http:\/\/amzn.to\/2sndmIU\">\u91d1\u5c5e\u76ae\u819c\u62b5\u6297\u5668<br \/>\n<\/a>\u30fb<a href=\"http:\/\/amzn.to\/2smWwd9\">\u30b8\u30e3\u30f3\u30d7\u30ef\u30a4\u30e4\u30ad\u30c3\u30c8<\/a><\/p>\n<figure id=\"attachment_228\" aria-describedby=\"caption-attachment-228\" style=\"width: 640px\" class=\"wp-caption aligncenter\"><img loading=\"eager\" decoding=\"async\" class=\"wp-image-228 size-full\" src=\"https:\/\/home.hiroshima-u.ac.jp\/~tigawa\/wp-content\/uploads\/2017\/05\/IMG_8420.jpg\" alt=\"\" width=\"640\" height=\"480\" srcset=\"https:\/\/home.hiroshima-u.ac.jp\/~tigawa\/wp-content\/uploads\/2017\/05\/IMG_8420.jpg 640w, https:\/\/home.hiroshima-u.ac.jp\/~tigawa\/wp-content\/uploads\/2017\/05\/IMG_8420-300x225.jpg 300w, https:\/\/home.hiroshima-u.ac.jp\/~tigawa\/wp-content\/uploads\/2017\/05\/IMG_8420-400x300.jpg 400w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><figcaption id=\"caption-attachment-228\" class=\"wp-caption-text\">\u5fc5\u8981\u306a\u90e8\u6750<\/figcaption><\/figure>\n<p>\u30d6\u30ec\u30c3\u30c9\u30dc\u30fc\u30c9\u306b\u30bb\u30f3\u30b5\u30fc\u306e\u4e09\u82af\u7dda\u3068Arduino\u306e5V\u96fb\u6e90\u3001GRD\u3001\u30c7\u30b8\u30bf\u30eb\u5165\u529b\u304b\u3089\u306e\u30b8\u30e3\u30f3\u30d1\u7dda\u3092\u523a\u3057\u3001\u30b5\u30f3\u30d7\u30eb\u306e\u30b9\u30b1\u30c3\u30c1\u3092\u53c2\u8003\u306b\u624b\u76f4\u3057\u3092\u52a0\u3048\u305f\u3089\u5b8c\u6210\u3002<\/p>\n<p>\u4eca\u306e\u3068\u3053\u308d\u3001\u5ba4\u6e29\u30684\u3064\u306e\u6c34\u69fd\u306e\u6c34\u6e29\uff08\uff1d5\u3064\u306e\u6e29\u5ea6\u30d7\u30ed\u30fc\u30d6\uff09\u30925\u5206\u3054\u3068\u306b\u53d6\u5f97\u3057\u3001\u3053\u308c\u3092AT&amp;T\u306e\u30af\u30e9\u30a6\u30c9\u30ea\u30bd\u30fc\u30b9\u3001<a href=\"https:\/\/m2x.att.com\/\">m2x<\/a>\u306b\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u3001\u30e2\u30cb\u30bf\u30ea\u30f3\u30b0\u3057\u3066\u3044\u307e\u3059\uff08<a href=\"https:\/\/m2x.att.com\/dashboards\/shared\/495b633bc073de3bcbbcb70934f5c51a\" target=\"_blank\" rel=\"noopener noreferrer\">\u5b9f\u969b\u306e\u30b5\u30a4\u30c8<\/a>\uff09\u3002\u8a2d\u5b9a\u6e29\u5ea6\u304b\u3089\u4e0a\u4e0b1\u2103\u4ee5\u4e0a\u5909\u52d5\u3059\u308b\u3068\u3001Heroku\u306b\u7f6e\u3044\u305f\u30a2\u30e9\u30fc\u30c8\u304c\u4f5c\u52d5\u3057\u3066\u30e9\u30dc\u306e\u30e1\u30f3\u30d0\u30fc\u306b\u30e1\u30fc\u30eb\u304c\u901a\u77e5\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002\u4eca\u306e\u3068\u3053\u308d\u8a2d\u7f6e\u3057\u3066\u304b\u3089\u4e8c\u304b\u6708\u4ee5\u4e0a\u3001\u5b89\u5b9a\u3057\u3066\u52d5\u4f5c\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u30b9\u30b1\u30c3\u30c1\u306f\u4e0b\u8a18\u306e\u3082\u306e\u3002\u3044\u308d\u3044\u308d\u8a66\u884c\u932f\u8aa4\u3057\u305f\u7d50\u679c\u3001MSTimer2\u3092\u5229\u7528\u3059\u308b\u306e\u304c\u6700\u3082\u5b89\u5b9a\u3057\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\" title=\"MSTimer2\u3092\u5229\u7528\u3057\u305f\u6e29\u5ea6\u30ed\u30b0\u53d6\u5f97\u30b9\u30b1\u30c3\u30c1\">#include &lt;MsTimer2.h&gt;\n#include &lt;SPI.h&gt;\n#include &lt;Ethernet.h&gt;\n#include &lt;OneWire.h&gt;\n#include &lt;DallasTemperature.h&gt;\n#define TEMPERATURE_PRECISION 12\n#define ARDUINO_PLATFORM\n#include \"M2XStreamClient.h\"\n\n\/\/ MAC address for your Ethernet shield\nbyte mac[] = { NIC\u306eMAC\u30a2\u30c9\u30ec\u30b9 };\n\/\/ Set the static IP address to use if the DHCP fails to assign\nbyte ip[] = { NIC\u306eIP\u30a2\u30c9\u30ec\u30b9 };\nbyte dns_adress[] = { DNS\u30a2\u30c9\u30ec\u30b9 };\nbyte gateway[] = { \u30b2\u30fc\u30c8\u30a6\u30a7\u30a4\u30a2\u30c9\u30ec\u30b9 };\nbyte subnet[] = { \u30b5\u30d6\u30cd\u30c3\u30c8\u30de\u30b9\u30af };\n\n\nchar deviceId[] = \"m2x\u306e\u30c7\u30d0\u30a4\u30b9ID\"; \/\/ Device you want to push to\nchar m2xKey[] = \"m2x\u306e\u30ad\u30fc\"; \/\/ Your M2X access key\nchar streamName1[] = { \"temp01\"};\nchar streamName2[] = { \"temp02\"};\nchar streamName3[] = { \"temp03\"};\nchar streamName4[] = { \"temp04\"};\nchar streamName5[] = { \"temp05\"};\n\nconst int temperaturePin = 0;\nEthernetClient client;\nM2XStreamClient m2xClient(&amp;client, m2xKey);\n#define ONE_WIRE_BUS 2\n\nOneWire oneWire(ONE_WIRE_BUS);\nDallasTemperature sensors(&amp;oneWire);\nDeviceAddress temp0 = { DS18B20\u306e\u30c7\u30d0\u30a4\u30b9\u30a2\u30c9\u30ec\u30b9 \n\u4f8b\u30000x28, 0xFF, 0xB0, 0xA5, 0x8C, 0x16, 0x03, 0x54 };\nDeviceAddress temp1 = { };\nDeviceAddress temp2 = { };\nDeviceAddress temp3 = { };\nDeviceAddress temp4 = { };\n\n\n\nvoid setup() {\n  sensors.begin();\n  sensors.setResolution(TEMPERATURE_PRECISION);\n  Serial.begin(9600);\n  Ethernet.begin(mac, ip, dns_adress, gateway, subnet);\n   \/\/300000ms\u6bce\u306b\u8a18\u9332\n  MsTimer2::set(300000, timerRecord);\n  MsTimer2::start();\n\n  \/\/while (!Serial) {\n  \/\/  ; \/\/ wait for serial port to connect. Needed for Leonardo only\n  \/\/}\n}\n\nvoid timerRecord() {\n\n\/\/  Serial.println(\"Connected to Ethernet\");\n\/\/  printEthernetStatus();\n\n  float temp01, temp02, temp03, temp04, temp05;\n  sensors.requestTemperatures();\n\n  temp01 = sensors.getTempC(temp0);\n  temp02 = sensors.getTempC(temp1);\n  temp03 = sensors.getTempC(temp2);\n  temp04 = sensors.getTempC(temp3);\n  temp05 = sensors.getTempC(temp4);\n\n\/\/  Serial.println(sensors.getTempC(temp0));\n\/\/  Serial.println(sensors.getTempC(temp1));\n\/\/  Serial.println(sensors.getTempC(temp2));\n\/\/  Serial.println(sensors.getTempC(temp3));\n\/\/  Serial.println(sensors.getTempC(temp4));\n\n  int response1 = m2xClient.updateStreamValue(deviceId, streamName1, temp01);\n  int response2 = m2xClient.updateStreamValue(deviceId, streamName2, temp02);\n  int response3 = m2xClient.updateStreamValue(deviceId, streamName3, temp03);\n  int response4 = m2xClient.updateStreamValue(deviceId, streamName4, temp04);\n  int response5 = m2xClient.updateStreamValue(deviceId, streamName5, temp05);\n\/\/ Serial.print(\"M2x client response code: \");\n\/\/ Serial.println(response);\n\n  delay(10000);\n}\n\n\nvoid printEthernetStatus() {\n  \/\/ print local IP\n  Serial.print(\"Local IP: \");\n  Serial.println(Ethernet.localIP());\n\n  \/\/ print subnet mask\n  Serial.print(\"Subnet Mask: \");\n  Serial.println(Ethernet.subnetMask());\n\n  \/\/ print gateway IP\n  Serial.print(\"Gateway IP: \");\n  Serial.println(Ethernet.gatewayIP());\n\n  \/\/ print dns IP\n  Serial.print(\"DNS IP: \");\n  Serial.println(Ethernet.dnsServerIP());\n}\n\nvoid loop(){}\n<\/pre>\n<p>2019\/10\/9\u3000\u8ffd\u8a18\uff1a<br \/>\n\u8907\u6570\uff08\u5f53\u65b9\u306e\u5834\u5408\u30015\u3064\u4ee5\u4e0a\uff09\u306eDS20B18\u306e\u30b3\u30fc\u30c9\u3092\u5ef6\u9577\u3057\u3066\u63a5\u7d9a\u3059\u308b\u3068\u30a8\u30e9\u30fc\u5024\u304c\u983b\u767a\u3057\u3066\u3057\u307e\u3046\u304c\u3001\u3053\u308c\u306f\u3069\u3046\u3082\u5ef6\u9577\u3057\u305f\u308a\u8907\u6570\u7e4b\u3050\u3068DS20B18\u81ea\u4f53\u304c\u62b5\u6297\u3068\u306a\u3063\u3066\u3057\u307e\u3044\u3001\u901a\u5e38\u306e4K7\u306e\u62b5\u6297\u3092\u5165\u308c\u308b\u3068\u96fb\u5727\u304c\u9ad8\u304f\u306a\u308a\u3059\u304e\u308b\u3001\u3042\u308b\u3044\u306f\u96fb\u6d41\u304c\u5fae\u5f31\u306b\u306a\u3063\u3066\u8aad\u307f\u53d6\u308c\u306a\u304f\u306a\u308b\u3089\u3057\u3044\u3002\u305d\u306e\u5834\u5408\u3001\u62b5\u6297\u3092\u4f4e\u3044\u3082\u306e\u306b\u5909\u3048\u308b\u3068\u3046\u307e\u304f\u884c\u304f\uff08\u4eca\u56de\u306f2K2\u306e\u62b5\u6297\u306b\u4ea4\u63db\uff09\u3002\u3053\u306e\u73fe\u8c61\u306farduino\u306e\u500b\u4f53\u5dee\u3084\u914d\u7f6e\u3059\u308b\u74b0\u5883\u306b\u3088\u3063\u3066\u3082\u7570\u306a\u308b\u3089\u3057\u304f\u3001\u539f\u56e0\u304c\u308f\u304b\u3089\u305a\u306b1\u5e74\u3050\u3089\u3044\u30c8\u30e9\u30d6\u30eb\u30b7\u30e5\u30fc\u30c8\u306b\u6642\u9593\u304c\u304b\u304b\u3063\u3066\u3057\u307e\u3063\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b89\u4fa1\u306a\u30de\u30a4\u30b3\u30f3\u57fa\u76e4\u3067\u3042\u308bArduino\u3092<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","_locale":"ja","_original_post":"196","footnotes":""},"categories":[7],"tags":[14,17,13],"class_list":["post-196","post","type-post","status-publish","format-standard","hentry","category-protocol","tag-arduino","tag-breeding-amphibians","tag-iot","ja"],"_links":{"self":[{"href":"https:\/\/home.hiroshima-u.ac.jp\/~tigawa\/index.php?rest_route=\/wp\/v2\/posts\/196","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/home.hiroshima-u.ac.jp\/~tigawa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/home.hiroshima-u.ac.jp\/~tigawa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/home.hiroshima-u.ac.jp\/~tigawa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/home.hiroshima-u.ac.jp\/~tigawa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=196"}],"version-history":[{"count":12,"href":"https:\/\/home.hiroshima-u.ac.jp\/~tigawa\/index.php?rest_route=\/wp\/v2\/posts\/196\/revisions"}],"predecessor-version":[{"id":1093,"href":"https:\/\/home.hiroshima-u.ac.jp\/~tigawa\/index.php?rest_route=\/wp\/v2\/posts\/196\/revisions\/1093"}],"wp:attachment":[{"href":"https:\/\/home.hiroshima-u.ac.jp\/~tigawa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/home.hiroshima-u.ac.jp\/~tigawa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/home.hiroshima-u.ac.jp\/~tigawa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}