Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » How to use I2C Pins in Raspberry Pi Pico | I2C Scanner Code
Raspberry Pi Raspberry Pi Pico Projects

How to use I2C Pins in Raspberry Pi Pico | I2C Scanner Code

Mamtaz AlamBy Mamtaz AlamUpdated:October 21, 20223 Comments3 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
in Raspberry Pi Pico I2C Scanner
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

Overview

In this tutorial, we will learn how to use I2C Pins in Raspberry Pi Pico & go through the I2C Scanner Code. The Raspberry Pi Pico is built using an RP2040 microcontroller. The board exposes 26 multi-function GPIO pins from a total of 36 GPIO pins. The 10 GPIO Pins are not exposed, hence they can’t be used. Out of the 26 usable GPIO pins, there are 2 pairs of I2C Pins which will be discussed in this post.

We will see what is I2C Communication protocol and how does it work. We will also learn in detail about the I2C Pin of Raspberry Pi Pico. We will take I2C Scanner Code as an example and check how the I2C Address of a few I2C enabled sensors & modules. Before that, you can check our Raspberry Pi Pico Getting Started Tutorial to learn more about the module.



What is I2C Communication Protocol

I2C (Inter-Integrated Circuit) is a synchronous, multi-master, multi-slave, packet-switched, single-ended, serial communication bus. It is widely used for attaching lower-speed peripheral ICs to processors and microcontrollers in short-distance, intra-board communication.

Like UART communication, I2C only uses two wires to transmit data between devices.

The two wires are named Serial Clock Line (SCL) and Serial Data Line (SDA). The data to be transferred is sent through the SDA wire and is synchronized with the clock signal from SCL. All the devices/ICs on the I2C network are connected to the same SCL and SDA lines as shown above.

The devices connected to the I2C bus are either masters or slaves. At any instant of time, only a single master stays active on the I2C bus. It controls the SCL clock line and decides what operation is to be done on the SDA data line.

All the devices that respond to instructions from this master device are slaves. For differentiating between multiple slave devices connected to the same I2C bus, each slave device is physically assigned a permanent 7-bit address.

When a master device wants to transfer data to or from a slave device, it specifies this particular slave device address on the SDA line and then proceeds with the transfer. So Effective communication takes place between the master device and a particular slave device. All the other slave devices don’t respond unless their address is specified by the master device on the SDA line.




I2C Pins in Raspberry Pi Pico

The microcontroller RP2040 chip has two I2C controllers. You can access both I2C controllers through GPIO pins of Raspberry Pi Pico. The following table shows the connection of GPIO pins with both I2C controllers.

I2C Controller GPIO Pins
I2C0 – SDA GP0/GP4/GP8/GP12/GP16/GP20
I2C0 – SCL GP1/GP5/GP9/GP13/GP17/GP21
I2C1 – SDA GP2/GP6/GP10/GP14/GP18/GP26
I2C1 – SCL GP3/GP7/GP11/GP15/GP19/GP27

Each connection of the controller can be configured through multiple GPIO pins as shown in the figure. But before using an I2C controller, you should configure in software which GPIO pins you want to use with a specific I2C controller.


Features of Raspberry Pi Pico I2C Pins

The Raspberry Pi Pico has RP2040 Chip which supports the following features:
1. Device can work in Master or Slave Mode with a default salve address = 0x055
2. I2C Pins have 3 speed modes: Standard (0 to 100 Kb/s), Fast(<= 400 Kb/s) & Fast Plus mode (<= 1000 Kb/s)
3. It can both transmit and Receive Buffers
4. It can also be used in interrupt and DMA mode



How to use I2C Pins of Raspberry Pi Pico with I2C Sensors or Modules?

Now let us learn how we can use the I2C Pin of Raspberry Pi Pico with any other I2C Based Sensors or Modules. In this case, we can use Raspberry Pi Pico as a Mater Device & other external sensors or modules as a Slave Device.

Here is a circuit where we have attached 3 different I2C Devices to the Pico Board. The 3 devices are BME680 Sensor, MPU6050 Sensor & 0.96″ OLED Display.

In this example, we will connect the SDA & SCL pin of MPU6050, BME680 & OLED Display to the common I2C line of Raspberry Pi Pico. Since there are multiple I2C Pins, we will use only a single pair of I2C pins of Raspberry Pi Pico. We will use GPIO8 as SDA0 & GPIO9 as SCL0.

Raspberry Pi Pico I2C Example


Raspberry Pi Pico I2C Scanner Code

Now let us see the Raspberry Pi Pico I2C Scanner Code. The code is written in MicroPython. You can either use Thonny IDE or uPyCraft IDE to connect the Raspberry Pi Pico to your computer.

The following code will scan the I2C Address of all the Sensors connected to the I2C pin of Raspberry Pi Pico. Copy the code and then Download & Run.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import machine
sda=machine.Pin(8)
scl=machine.Pin(9)
i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)
print('Scan i2c bus...')
devices = i2c.scan()
if len(devices) == 0:
  print("No i2c device !")
else:
  print('i2c devices found:',len(devices))
  for device in devices:  
    print("Decimal address: ",device," | Hexa address: ",hex(device))


Once you run the code, the Micropython will try scanning the I2C devices connected to Pico Board. You can connect up to 127 I2C Slave devices. The device will scan the address and will show it in the Shell Window.

Raspberry Pi Pico I2C Example Code

1. The I2C Address of OLED Display is 60 which in Hexadecimal is 0x3C
2. The I2C Address of MPU6050 is 104 which in Hexadecimal is 0x68
3. The I2C Address of BME680 is 119 which in Hexadecimal is 0x77


Video Tutorial & Guide

Raspberry Pi Pico Complete Guide| Pinout+Features+ADC+I2C+OLED+Internal Temperature Sensor+DHT11
Watch this video on YouTube.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleRaspberry Pi Pico Getting Started Tutorial with MicroPython
Next Article How to use ADC in Raspberry Pi Pico | ADC Example Code

Related Posts

ADXL375 Accelerometer with Raspberry Pi Pico & MicroPython

ADXL375 Accelerometer with Raspberry Pi Pico & MicroPython

Updated:July 24, 2025
Interface BMI160 with Raspberry Pi Pico & MicroPython

Interface BMI160 with Raspberry Pi Pico & MicroPython

Updated:February 2, 20253K
Shift Register 74HC595 with Raspberry Pi Pico & MicroPython

Shift Register 74HC595 with Raspberry Pi Pico & MicroPython

Updated:February 2, 202513K
Interfacing XBee Module with Raspberry Pi Pico & MicroPython

Interfacing XBee Module with Raspberry Pi Pico & MicroPython

Updated:February 2, 20253K
Modbus RTU with Raspberry Pi Pico & Micropython

Modbus RTU with Raspberry Pi Pico & MicroPython

Updated:February 2, 20258K
Fever Detector with MLX90640 & OpenCV Raspberry Pi

Thermal Fever Detector with MLX90640 & OpenCV Raspberry Pi

Updated:February 2, 20256K
View 3 Comments

3 Comments

  1. Chas Large on April 22, 2021 9:23 PM

    Hello, great tutorial, thank you.

    Could you expand to show how to DISPLAY the sensor readings from the MPU6050 and the BME680 on the OLED display.

    Many thanks

    Reply
    • Alex Newton on April 22, 2021 9:24 PM

      Will make these tutorials in coming future

      Reply
  2. Harsh Mirdhwal on August 1, 2021 10:19 AM

    How do we do it for seven pin monochrome display with spi ?? ssd13306 oled module

    Reply

CommentsCancel reply

Latest Posts
ESP32 Fingerprint Attendance System with Live Web Dashboard

ESP32 Fingerprint Attendance System with Live Web Dashboard

June 21, 2026
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

June 14, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
Top Posts & Pages
  • ESP32 Fingerprint Attendance System with Live Web Dashboard
    ESP32 Fingerprint Attendance System with Live Web Dashboard
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • How to use Modbus RTU with ESP32 to read Sensor Data
    How to use Modbus RTU with ESP32 to read Sensor Data
  • ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
    ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
  • How to use INA226 DC Current Sensor with Arduino
    How to use INA226 DC Current Sensor with Arduino
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
  • IoT Based ECG Monitoring with AD8232 ECG Sensor & ESP32
    IoT Based ECG Monitoring with AD8232 ECG Sensor & ESP32
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (205)
    • ESP32 MicroPython (7)
    • ESP32 Projects (82)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.