{"id":1380,"date":"2019-06-25T14:44:12","date_gmt":"2019-06-25T14:44:12","guid":{"rendered":"https:\/\/thezhut.com\/?page_id=1380"},"modified":"2019-06-25T14:44:12","modified_gmt":"2019-06-25T14:44:12","slug":"how-to-find-the-address-of-any-i2c-device-connected-to-your-arduino-board","status":"publish","type":"page","link":"https:\/\/thezhut.com\/?page_id=1380","title":{"rendered":"How to find the address of any I2C device connected to your Arduino board"},"content":{"rendered":"<h1>\u00a0 If you have a I2C device you want to use with your Arduino but you don&#8217;t know what the address is, well today on this episode of Basic ARDUINO I will show you how you can use the Arduino itself to scan and find the address for that I2C device.<\/h1>\n<p>&nbsp;<\/p>\n<p><iframe loading=\"lazy\" title=\"How to find the address of any I2C device connected to your Arduino board\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/Htdia6cdlos?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<p>&nbsp;<\/p>\n<h1 style=\"text-align: center;\"><a href=\"https:\/\/playground.arduino.cc\/Main\/I2cScanner\/\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>Click here for more info on the I2C scanner on the Arduino Playground<\/strong><\/a><\/h1>\n<h1><\/h1>\n<h1><span style=\"color: #800080;\">ARDUINO CODE:<\/span><\/h1>\n<p>\/\/ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n\/\/ i2c_scanner<br \/>\n\/\/<br \/>\n\/\/ Version 1<br \/>\n\/\/ This program (or code that looks like it)<br \/>\n\/\/ can be found in many places.<br \/>\n\/\/ For example on the Arduino.cc forum.<br \/>\n\/\/ The original author is not know.<br \/>\n\/\/ Version 2, Juni 2012, Using Arduino 1.0.1<br \/>\n\/\/ Adapted to be as simple as possible by Arduino.cc user Krodal<br \/>\n\/\/ Version 3, Feb 26 2013<br \/>\n\/\/ V3 by louarnold<br \/>\n\/\/ Version 4, March 3, 2013, Using Arduino 1.0.3<br \/>\n\/\/ by Arduino.cc user Krodal.<br \/>\n\/\/ Changes by louarnold removed.<br \/>\n\/\/ Scanning addresses changed from 0&#8230;127 to 1&#8230;119,<br \/>\n\/\/ according to the i2c scanner by Nick Gammon<br \/>\n\/\/ https:\/\/www.gammon.com.au\/forum\/?id=10896<br \/>\n\/\/ Version 5, March 28, 2013<br \/>\n\/\/ As version 4, but address scans now to 127.<br \/>\n\/\/ A sensor seems to use address 120.<br \/>\n\/\/ Version 6, November 27, 2015.<br \/>\n\/\/ Added waiting for the Leonardo serial communication.<br \/>\n\/\/<br \/>\n\/\/<br \/>\n\/\/ This sketch tests the standard 7-bit addresses<br \/>\n\/\/ Devices with higher bit address might not be seen properly.<br \/>\n\/\/<\/p>\n<p>#include &lt;Wire.h&gt;<\/p>\n<p>void setup()<br \/>\n{<br \/>\nWire.begin();<\/p>\n<p>Serial.begin(9600);<br \/>\nwhile (!Serial); \/\/ Leonardo: wait for serial monitor<br \/>\nSerial.println(&#8220;\\nI2C Scanner&#8221;);<br \/>\n}<\/p>\n<p>void loop()<br \/>\n{<br \/>\nbyte error, address;<br \/>\nint nDevices;<\/p>\n<p>Serial.println(&#8220;Scanning&#8230;&#8221;);<\/p>\n<p>nDevices = 0;<br \/>\nfor(address = 1; address &lt; 127; address++ )<br \/>\n{<br \/>\n\/\/ The i2c_scanner uses the return value of<br \/>\n\/\/ the Write.endTransmisstion to see if<br \/>\n\/\/ a device did acknowledge to the address.<br \/>\nWire.beginTransmission(address);<br \/>\nerror = Wire.endTransmission();<\/p>\n<p>if (error == 0)<br \/>\n{<br \/>\nSerial.print(&#8220;I2C device found at address 0x&#8221;);<br \/>\nif (address&lt;16)<br \/>\nSerial.print(&#8220;0&#8243;);<br \/>\nSerial.print(address,HEX);<br \/>\nSerial.println(&#8221; !&#8221;);<\/p>\n<p>nDevices++;<br \/>\n}<br \/>\nelse if (error==4)<br \/>\n{<br \/>\nSerial.print(&#8220;Unknown error at address 0x&#8221;);<br \/>\nif (address&lt;16)<br \/>\nSerial.print(&#8220;0&#8221;);<br \/>\nSerial.println(address,HEX);<br \/>\n}<br \/>\n}<br \/>\nif (nDevices == 0)<br \/>\nSerial.println(&#8220;No I2C devices found\\n&#8221;);<br \/>\nelse<br \/>\nSerial.println(&#8220;done\\n&#8221;);<\/p>\n<p>delay(5000); \/\/ wait 5 seconds for next scan<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 If you have a I2C device you want to use with your Arduino but you don&#8217;t know what the address is, well today on this episode of Basic ARDUINO I will show you how you can use the Arduino &hellip; <a href=\"https:\/\/thezhut.com\/?page_id=1380\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1382,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":"","_links_to":"","_links_to_target":""},"class_list":["post-1380","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/1380","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thezhut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1380"}],"version-history":[{"count":2,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/1380\/revisions"}],"predecessor-version":[{"id":1394,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/1380\/revisions\/1394"}],"up":[{"embeddable":true,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/1382"}],"wp:attachment":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}