Raspberry Pi Pico: I2C Scanner (MicroPython) – Finding the Address of I2C Devices

This is a quick guide to show you how to find the address of I2C devices with the Raspberry Pi Pico programmed using MicroPython firmware.

Raspberry Pi Pico I2C Scanner MicroPython Finding the Address of I2C Devices

Already familiar with the Raspberry Pi Pico? Jump to the I2C scanner sketch.

Prerequisites – MicroPython Firmware

To follow this tutorial you need MicroPython firmware installed in your Raspberry Pi Pico board. You also need an IDE to write and upload the code to your board.

The recommended MicroPython IDE for the Raspberry Pi Pico is Thonny IDE. Follow the next tutorial to learn how to install Thonny IDE, flash MicroPython firmware, and upload code to the board.

Raspberry Pi Pico – Default I2C Pins

In the Raspberry Pi Pico, there are two I2C peripherals available, named I2C1 and I2C0. You can use two different buses (I2C1 and I2C2) simultaneously, but you can’t use two I2C1 or two I2C2 at the same time. You can use I2C communication on any of the I2C pins available.

The default I2C pins are GPIO 4 (SDA) and GPIO 5 (SCL)read our Raspberry Pi Pico Pinout.

The following table shows all the pins you can use for I2C communication.

I2C ControllerSDA GPIOsSCL GPIOs
I2C0GPIO0, GPIO4, GPIO8, GPIO12, GPIO16, GPIO20GPIO1, GPIO5, GPIO9, GPIO13, GPIO17, GPIO21
I2C1GPIO2, GPIO6, GPIO10, GPIO14, GPIO18, GPIO26GPIO3, GPIO7, GPIO11, GPIO15, GPIO19, GPIO27

I2C Scanner – MicroPython

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 code provided.

Open Thonny IDE, or the IDE of your choice, and copy the following code.

# I2C Scanner MicroPython
from machine import Pin, SoftI2C

# You can choose any other combination of I2C pins
i2c = SoftI2C(scl=Pin(5), sda=Pin(4))

print('I2C SCANNER')
devices = i2c.scan()

if len(devices) == 0:
  print("No i2c device !")
else:
  print('i2c devices found:', len(devices))

  for device in devices:
    print("I2C hexadecimal address: ", hex(device))

View raw code

Raspberry Pi Pico I2C Scanner MicroPython script code

After copying the code:

  • connect the Raspberry Pi Pico to your computer, if it isn’t already;
  • make sure you have your I2C peripheral properly connected to your board on the right I2C pins (SCL=GPIO5 ; SDA =GPIO4). If you’re using different pins, make sure you adjust that on the code.
i2c = SoftI2C(scl=Pin(5), sda=Pin(4))
  • run the previous code (I2C scanner sketch). If you’re using Thonny IDE, you just need to click on the green run icon.
run Raspberry Pi Pico I2C Scanner MicroPython script

The I2C address of your peripheral will be printed on the shell.

testing example Raspberry Pi Pico I2C Scanner MicroPython script shell output

If you have more than one device connected to the same I2C bus, it will display the address of all devices.

Wrapping Up

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 run the I2C scanner code.

We hope you’ve found this guide useful.

Learn more about the Raspberry Pi Pico with our resources:

We also have guides for other popular microcontroller boards:

Thanks for reading.



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Recommended Resources

Build a Home Automation System from Scratch » With Raspberry Pi, ESP8266, Arduino, and Node-RED.

Home Automation using ESP8266 eBook and video course » Build IoT and home automation projects.

Arduino Step-by-Step Projects » Build 25 Arduino projects with our course, even with no prior experience!

What to Read Next…


Enjoyed this project? Stay updated by subscribing our newsletter!

Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.