{"id":144601,"date":"2023-12-27T18:13:50","date_gmt":"2023-12-27T18:13:50","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=144601"},"modified":"2024-01-04T14:54:59","modified_gmt":"2024-01-04T14:54:59","slug":"raspberry-pi-pico-i2c-scanner-arduino","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-i2c-scanner-arduino\/","title":{"rendered":"Raspberry Pi Pico: I2C Scanner (Arduino IDE) &#8211; Finding the Address of I2C Devices"},"content":{"rendered":"\n<p>This is a quick guide that shows how to find the address of I2C devices with the Raspberry Pi Pico programmed using Arduino IDE.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/12\/Raspberry-Pi-Pico-I2C-Scanner-Arduino-IDE.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Pico I2C Scanner Arduino IDE Finding the Address of I2C Devices\" class=\"wp-image-144603\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/12\/Raspberry-Pi-Pico-I2C-Scanner-Arduino-IDE.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/12\/Raspberry-Pi-Pico-I2C-Scanner-Arduino-IDE.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/12\/Raspberry-Pi-Pico-I2C-Scanner-Arduino-IDE.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/12\/Raspberry-Pi-Pico-I2C-Scanner-Arduino-IDE.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n<p class=\"rntbox rntclgreen\">Already familiar with the Raspberry Pi Pico? <a href=\"#i2c-scanner\" title=\"\">Jump to the I2C scanner sketch<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p>This tutorial uses Raspberry Pi Pico programmed with Arduino IDE. You need to install the Raspberry Pi Pico boards on Arduino IDE and you must know how to upload code to the board. Check out the following tutorial first if you haven\u2019t already:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/programming-raspberry-pi-pico-w-arduino-ide\/\">Programming Raspberry Pi Pico with Arduino IDE<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Raspberry Pi Pico &#8211; Default I2C Pins<\/h2>\n\n\n\n<p>In the Raspberry Pi Pico, there are two I2C peripherals available, named <strong>I2C1 <\/strong>and <strong>I2C0<\/strong>. You can use two different buses (I2C1 and I2C2) simultaneously, but you can&#8217;t use two I2C1 or two I2C2 at the same time. You can use I2C communication on any of the I2C pins available.<\/p>\n\n\n\n<p class=\"rntbox rntclgreen\">The default I2C pins are <strong>GPIO 4 (SDA) <\/strong>and <strong>GPIO 5 (SCL)<\/strong> &#8211; <a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-w-pinout-gpios\/\">read our Raspberry Pi Pico Pinout<\/a>.<\/p>\n\n\n\n<p>The following table shows all the pins you can use for I2C communication.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>I2C Controller<\/strong><\/td><td><strong>SDA GPIOs<\/strong><\/td><td><strong>SCL GPIOs<\/strong><\/td><\/tr><tr><td><strong>I2C0<\/strong><\/td><td>GPIO0, GPIO4, GPIO8, GPIO12, GPIO16, GPIO20<\/td><td>GPIO1, GPIO5, GPIO9, GPIO13, GPIO17, GPIO21<\/td><\/tr><tr><td><strong>I2C1<\/strong><\/td><td>GPIO2, GPIO6, GPIO10, GPIO14, GPIO18, GPIO26<\/td><td>GPIO3, GPIO7, GPIO11, GPIO15, GPIO19, GPIO27<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i2c-scanner\">I2C Scanner Sketch &#8211; Arduino IDE<\/h2>\n\n\n\n<p>If you want to find the I2C address of a specific sensor, display, or any other I2C peripheral, connect it to the Raspberry Pi Pico I2C pins and then run the I2C scanner sketch provided.<\/p>\n\n\n\n<p>Copy the following code to the Arduino IDE and upload it to the Raspberry Pi Pico.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*********\n  Rui Santos\n  Complete project details at https:\/\/RandomNerdTutorials.com\/raspberry-pi-pico-i2c-scanner-arduino\/\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.\n  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n*********\/\n\n#include &lt;Wire.h&gt;\n \nvoid setup() {\n  Wire.begin();\n  Serial.begin(115200);\n  Serial.println(&quot;\\nI2C Scanner&quot;);\n}\n \nvoid loop() {\n  byte error, address;\n  int nDevices;\n  Serial.println(&quot;Scanning...&quot;);\n  nDevices = 0;\n  for(address = 1; address &lt; 127; address++ ) {\n    Wire.beginTransmission(address);\n    error = Wire.endTransmission();\n    if (error == 0) {\n      Serial.print(&quot;I2C device found at address 0x&quot;);\n      if (address&lt;16) {\n\n        \n        Serial.print(&quot;0&quot;);\n      }\n      Serial.println(address,HEX);\n      nDevices++;\n    }\n    else if (error==4) {\n      Serial.print(&quot;Unknow error at address 0x&quot;);\n      if (address&lt;16) {\n        Serial.print(&quot;0&quot;);\n      }\n      Serial.println(address,HEX);\n    }    \n  }\n  if (nDevices == 0) {\n    Serial.println(&quot;No I2C devices found\\n&quot;);\n  }\n  else {\n    Serial.println(&quot;done\\n&quot;);\n  }\n  delay(5000);          \n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Raspberry-Pi-Pico\/Arduino\/I2C_Scanner.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>After uploading the code, make sure you have your I2C peripheral properly connected to your board on the right I2C pins (SCL=GPIO5 ; SDA =GPIO4). <\/p>\n\n\n\n<div class=\"wp-block-group rntbox rntclgray\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<p>If you&#8217;re using different pins, make sure you adjust that on the code. Replace:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Wire.begin();<\/code><\/pre>\n\n\n\n<p>With the following line, in which <strong>I2C_SDA<\/strong> corresponds to the GPIO number you&#8217;re using as SDA and <strong>I2C_SCL <\/strong>to the GPIO number you&#8217;re using as SCL.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Wire.begin(<strong>I2C_SDA<\/strong>, <strong>I2C_SCL<\/strong>);<\/code><\/pre>\n<\/div><\/div>\n\n\n\n<p>Open the Serial Monitor at a baud rate of 115200.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/10\/Serial-Monitor.png?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"34\" height=\"30\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/10\/Serial-Monitor.png?resize=34%2C30&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" class=\"wp-image-120313\"\/><\/a><\/figure><\/div>\n\n\n<p>Wait a couple of seconds, and the I2C address of your peripheral will be printed in the Serial Monitor. If you have more than one device connected to the same I2C bus, it will display the address of all devices.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"601\" height=\"381\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/12\/I2C-Scanner-Raspberry-Pi-Pico-Arduino-IDE.png?resize=601%2C381&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Pico I2C Scanner Serial Monitor\" class=\"wp-image-144605\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/12\/I2C-Scanner-Raspberry-Pi-Pico-Arduino-IDE.png?w=601&amp;quality=100&amp;strip=all&amp;ssl=1 601w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/12\/I2C-Scanner-Raspberry-Pi-Pico-Arduino-IDE.png?resize=300%2C190&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 601px) 100vw, 601px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In this guide, you learned how to quickly find the address of I2C devices. You just need to connect your I2C peripheral to the Raspberry Pi Pico and upload the I2C scanner sketch provided.<\/p>\n\n\n\n<p>We hope you&#8217;ve found this guide useful.<\/p>\n\n\n\n<p>Learn more about the Raspberry Pi Pico with our resources:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/projects-raspberry-pi-pico\/\" title=\"\">Raspberry Pi Pico Projects and Tutorials<\/a><\/li>\n<\/ul>\n\n\n\n<p>We also have guides for other popular microcontroller boards:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/projects-esp32\/\" title=\"\">ESP32 Projects and Tutorials<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/projects-esp8266\/\" title=\"\">ESP8266 Projects and Tutorials<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/projects-esp32-esp8266-micropython\/\" title=\"\">MicroPython Projects with the ESP32 and ESP8266<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/projects-raspberry-pi\/\" title=\"\">Raspberry Pi Projects and Guides<\/a><\/li>\n<\/ul>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a quick guide that shows how to find the address of I2C devices with the Raspberry Pi Pico programmed using Arduino IDE. Already familiar with the Raspberry Pi &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Raspberry Pi Pico: I2C Scanner (Arduino IDE) &#8211; Finding the Address of I2C Devices\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-i2c-scanner-arduino\/#more-144601\" aria-label=\"Read more about Raspberry Pi Pico: I2C Scanner (Arduino IDE) &#8211; Finding the Address of I2C Devices\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":144603,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[324,325],"tags":[],"class_list":["post-144601","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-raspberry-pi-pico","category-raspberry-pi-pico-arduino-ide"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/12\/Raspberry-Pi-Pico-I2C-Scanner-Arduino-IDE.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/144601","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=144601"}],"version-history":[{"count":8,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/144601\/revisions"}],"predecessor-version":[{"id":145175,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/144601\/revisions\/145175"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/144603"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=144601"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=144601"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=144601"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}