{"id":123,"date":"2012-02-08T13:08:31","date_gmt":"2012-02-08T04:08:31","guid":{"rendered":"http:\/\/www.gvc-on.net\/?page_id=123"},"modified":"2014-01-21T14:51:56","modified_gmt":"2014-01-21T05:51:56","slug":"arduino-i2c-module-scanner-wire-library-only","status":"publish","type":"page","link":"https:\/\/www.gvc-on.net\/?page_id=123","title":{"rendered":"Arduino I2C Module Scanner (Wire Library Only)"},"content":{"rendered":"<p>Arduino \u306b\u63a5\u7d9a\u3057\u305fI2C\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u691c\u7d22\u3059\u308b\u30b5\u30f3\u30d7\u30eb\u30bd\u30fc\u30b9\u3067\u3059\u3002<br \/>\nWire\u30e9\u30a4\u30d6\u30e9\u30ea\u3057\u304b\u4f7f\u3063\u3066\u3044\u306a\u3044\u306e\u3067\u30bd\u30fc\u30b9\u304c\u30b7\u30f3\u30d7\u30eb\u3067\u3059\u3002:-)<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n\r\n\/\/ --------------------------------------------------\r\n\/\/ Global Versatile Controler\r\n\/\/ --------------------------------------------------\r\n\/\/ --------------------------------------------------\r\n\/\/ Memo\r\n\/\/ --------------------------------------------------\r\n\/\/ ------------------------------\r\n\/\/ BASE\r\n\/\/ ------------------------------\r\n\/\/ I2C Module Scan by Wire Liblary, for Arduino.\r\n\/\/\r\n\/\/ New BSD License. Copyright (c) 2011-2012, Future Versatile Group\r\n\/\/ All rights reserved.\r\n\/\/\r\n\/\/ 2012.02.08 T.Kabu http:\/\/www.gvc-on.net\/\r\n\/\/\r\n\/\/ http:\/\/todbot.com\/blog\/2009\/11\/29\/i2cscanner-pde-arduino-as-i2c-bus-scanner\/  ... I2C bus scanner for Arduino\r\n\r\n#include &quot;Wire.h&quot;\r\n\r\n\/\/ ------------------------------\r\n\/\/ GVC Module Scan\r\n\/\/ ------------------------------\r\nvoid gvc_module_scan(byte from_id, byte to_id)\r\n{\r\n    char    module_id;    \/\/ Target I2C ID\r\n    byte    data;         \/\/ Dummy data\r\n    byte    result;       \/\/ Result of TX\r\n\r\n    \/\/ Open I2C device\r\n    Wire.begin();\r\n\r\n    \/\/ I2C Module Scan, from_id ... to_id\r\n    for (module_id = from_id; module_id &lt;= to_id; module_id ++)\r\n    {\r\n        Wire.beginTransmission(module_id);\r\n        Wire.write(&amp;data, 0);\r\n        result = Wire.endTransmission();\r\n\r\n        \/\/ I2C Module found out!\r\n        if (result == 0)\r\n        {\r\n            Serial.print(&quot;I2C Module Found! ID = &quot;);\r\n            Serial.println(module_id, DEC);\r\n        }\r\n    }\r\n}\r\n\r\nvoid setup()\r\n{\r\n    \/\/ Serial Start!\r\n    Serial.begin(9600);\r\n    Serial.print(&quot;Wire(I2C) ID Scan.\\n&quot;);\r\n\r\n    \/\/ I2C Module Scan\r\n    gvc_module_scan(1, 100);\r\n\r\n    Serial.print(&quot;\\nEND\\n&quot;);\r\n}\r\n\r\nvoid loop()\r\n{\r\n    digitalWrite(13,HIGH);\r\n    delay(500);\r\n\r\n    digitalWrite(13,LOW);\r\n    delay(500);\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Arduino \u306b\u63a5\u7d9a\u3057\u305fI2C\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u691c\u7d22\u3059\u308b\u30b5\u30f3\u30d7\u30eb\u30bd\u30fc\u30b9\u3067\u3059\u3002 Wire\u30e9\u30a4\u30d6\u30e9\u30ea\u3057\u304b\u4f7f\u3063\u3066\u3044\u306a\u3044\u306e\u3067\u30bd\u30fc\u30b9\u304c\u30b7\u30f3\u30d7\u30eb\u3067\u3059\u3002:-) \/\/ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &hellip; <a href=\"https:\/\/www.gvc-on.net\/?page_id=123\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":521,"menu_order":0,"comment_status":"closed","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-123","page","type-page","status-publish","hentry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.gvc-on.net\/index.php?rest_route=\/wp\/v2\/pages\/123","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gvc-on.net\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.gvc-on.net\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.gvc-on.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gvc-on.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=123"}],"version-history":[{"count":14,"href":"https:\/\/www.gvc-on.net\/index.php?rest_route=\/wp\/v2\/pages\/123\/revisions"}],"predecessor-version":[{"id":523,"href":"https:\/\/www.gvc-on.net\/index.php?rest_route=\/wp\/v2\/pages\/123\/revisions\/523"}],"up":[{"embeddable":true,"href":"https:\/\/www.gvc-on.net\/index.php?rest_route=\/wp\/v2\/pages\/521"}],"wp:attachment":[{"href":"https:\/\/www.gvc-on.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}