Deep Dive: Interfacing I2C OLED With Raspberry Pi Pico (The Missing Manual)

by telugu_mad_thinker in Circuits > Raspberry Pi

84 Views, 2 Favorites, 0 Comments

Deep Dive: Interfacing I2C OLED With Raspberry Pi Pico (The Missing Manual)

IMG_20260915_224807913.jpg

Have you ever connected an OLED display to a Raspberry Pi Pico, uploaded the code, and… nothing happened?

That was exactly my problem.

There are many tutorials available for connecting an SSD1306 OLED display to a Raspberry Pi Pico, but when I tried several of the commonly available examples with the Arduino IDE, I couldn't get my OLED working reliably.

Instead of giving up, I decided to test the I2C pin combinations myself.

After testing the available I2C configurations on my Raspberry Pi Pico using the Arduino-Pico core in Arduino IDE, I found the combinations that worked with my setup.

In this tutorial, I'll show you:

  1. How to connect an I2C OLED to Raspberry Pi Pico
  2. How to program the Pico using Arduino IDE
  3. Which libraries you need
  4. The I2C pin combinations I tested successfully
  5. How to manually configure the SDA and SCL pins
  6. How to display text on a 128×64 SSD1306 OLED
  7. How to troubleshoot a blank OLED

The main goal of this tutorial is simple:

Connect the OLED, upload the code, and get it working without wasting time trying random I2C pins.

Supplies

cable_micro.jpg
rpi_front.jpg
oled.jpg
jumperwires.jpg

What You Need

Hardware

  1. Raspberry Pi Pico
  2. 0.96-inch 128×64 I2C OLED display
  3. Breadboard
  4. Male-to-male jumper wires
  5. USB cable
  6. Computer

Software

  1. Arduino IDE
  2. Raspberry Pi Pico/RP2040 Arduino board package
  3. Adafruit GFX Library
  4. Adafruit SSD1306 Library

The Adafruit SSD1306 library is designed for monochrome OLED displays using the SSD1306 controller and supports I2C and SPI communication. It also depends on the Adafruit GFX library.

Identify Your OLED Display

oled.jpg

Before connecting anything, check your OLED module.

I'm using a common 0.96-inch 128×64 SSD1306 I2C OLED.

Most four-pin I2C OLED modules have these connections:

OLED PinFunction

VCC - Power

GND - Ground

SCL - I2C Clock

SDA - I2C Data

I2C is convenient because the display only requires two communication lines:

  1. SDA — Serial Data
  2. SCL — Serial Clock

The SSD1306 controller can communicate using either I2C or SPI, but this project uses I2C.

Note: OLED modules can differ. Check the markings on your particular module before connecting power.

Connect the OLED to the Raspberry Pi Pico

step_3.jpg
step_4.jpg
step_1.jpg
step_2.jpg

For the basic test, we'll use one of the working I2C combinations.

I recommend starting with:

OLEDRaspberry Pi Pico

Wiring

OLED Raspberry Pi Pico

VCC ------> 3V3(OUT)
GND ------> GND
SDA ------> GP4
SCL ------> GP5

This is also a commonly used Pico I2C configuration in Arduino IDE tutorials. Keep the wiring as short as practical while testing.

Working I2C Pin Combinations

pinout_rpi.png

This is the part I added after testing the Pico myself.

Instead of asking you to randomly try different pins, these are the combinations I tested successfully with my Raspberry Pi Pico using Arduino IDE.

Tested working combinations

So you can refer image, all pins are working!

For this tutorial, I'll use GP4 as SDA and GP5 as SCL.

The Arduino-Pico core provides Wire.setSDA() and Wire.setSCL() so the I2C pins can be selected before starting the I2C interface.

Important: These are the pin combinations I tested successfully for this project. They should not be interpreted as a complete list of every possible RP2040 I2C pin mapping.

Downloads

Add the Raspberry Pi Pico Board URL to Arduino IDE

preference_board.png

Instead of searching for the Raspberry Pi Pico board package directly in Arduino IDE, we first need to add the Arduino-Pico board manager URL.

Open Arduino IDE and go to:

File → Preferences

Find:

Additional Boards Manager URLs

Paste the official Arduino-Pico package URL into the field.

https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json

Then click OK.

Install the OLED Libraries

library_mamager.png

Open:

Sketch → Include Library → Manage Libraries

Search for:

Adafruit GFX Library

Install it.

Then search for:

Adafruit SSD1306

Install it.

The SSD1306 library uses the Adafruit GFX library for graphics and text rendering.

After installation, restart Arduino IDE if necessary.

Configure the I2C Pins in Arduino IDE

This is where the important part of this tutorial comes in.

We aren't relying on whatever default I2C pins the library happens to select.

Instead, we'll explicitly tell the Pico which pins we're using.

For my GP4/GP5 setup:

Wire.setSDA(4);
Wire.setSCL(5);
Wire.begin();

The important thing is that setSDA() and setSCL() are called before ****Wire.begin(). The Arduino-Pico documentation specifically provides these functions for selecting the I2C pins.

Upload the OLED Test Code

Here is the complete test program.

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

void setup() {

Serial.begin(115200);

// Select I2C pins
Wire.setSDA(4);
Wire.setSCL(5);

// Start I2C
Wire.begin();

// Initialize OLED
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {

Serial.println("OLED allocation failed");

while (1);
}

display.clearDisplay();

display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);

display.setCursor(0, 10);
display.println("Hello Pico!");

display.setCursor(0, 30);
display.println("I2C OLED Working!");

display.display();
}

void loop() {

}

If you want to use another tested pins combination which comes under i2c0 configuration

Simply change these two lines.

For GP0/GP1:

Wire.setSDA(0);
Wire.setSCL(1);

For GP4/GP5:

Wire.setSDA(4);
Wire.setSCL(5);

For GP8/GP9:

Wire.setSDA(8);
Wire.setSCL(9);

For GP12/GP13:

Wire.setSDA(12);
Wire.setSCL(13);

For GP16/GP17:

Wire.setSDA(16);
Wire.setSCL(17);

For GP20/GP21:

Wire.setSDA(20);
Wire.setSCL(21);

If you want to use another tested pins combination which comes under i2c0 configuration

First Change this code

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire1, -1);

Then change these two lines

For GP2/GP3:

Wire.setSDA(2);
Wire.setSCL(3);

For GP6/GP7:

Wire.setSDA(6);
Wire.setSCL(7);

For GP10/GP11:

Wire.setSDA(10);
Wire.setSCL(11);

For GP14/GP15:

Wire.setSDA(14);
Wire.setSCL(15);

For GP18/GP19:

Wire.setSDA(18);
Wire.setSCL(19);

For GP26/GP27:

Wire.setSDA(26);
Wire.setSCL(27);

Upload the Code

port.png
IMG_20260915_225019727.jpg

Connect your Raspberry Pi Pico to your computer.

Select the correct board and port in Arduino IDE.

Then click:

Upload

After the program finishes uploading, the OLED should display:

Hello Pico!

I2C OLED Working!

If you see the text, congratulations — your Raspberry Pi Pico is communicating with the OLED through I2C.

What If the OLED Is Blank?

Don't immediately assume the OLED is damaged.

There are several things to check.

1. Check the wiring

Make sure:

VCC → 3V3
GND → GND
SDA → SDA pin
SCL → SCL pin

Also make sure SDA and SCL aren't accidentally swapped.

2. Check the I2C address

A common SSD1306 I2C address is:

0x3C

Some modules may use:

0x3D

If your display uses a different address, change:

display.begin(SSD1306_SWITCHCAPVCC, 0x3C)

to the appropriate address.

3. Check the display resolution

This tutorial uses:

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

If you're using a different OLED resolution, change these values accordingly.

4. Check the selected I2C pins

If you're using GP4/GP5:

Wire.setSDA(4);
Wire.setSCL(5);

Make sure your physical wiring matches those pins.

Try the Other Tested Pin Combinations

One of the useful things about the Pico is that the I2C peripheral can be mapped to different GPIO combinations.

If GP4/GP5 doesn't fit your project, you can use one of my other tested combinations.

I2C0 Pin mapping

GP0 + GP1

Wire.setSDA(0);
Wire.setSCL(1);

GP4 + GP5

Wire.setSDA(4);
Wire.setSCL(5);

GP8 + GP9

Wire.setSDA(8);
Wire.setSCL(9);

GP12 + GP13

Wire.setSDA(12);
Wire.setSCL(13);

GP16 + GP17

Wire.setSDA(16);
Wire.setSCL(17);

GP20 + GP21

Wire.setSDA(20);
Wire.setSCL(21);

I2C1 Pin mapping

GP2 + GP3

Wire1.setSDA(2);
Wire1.setSCL(3);

GP6 + GP7

Wire1.setSDA(6);
Wire1.setSCL(7);

GP10 + GP11

Wire1.setSDA(10);
Wire1.setSCL(11);

GP14 + GP15

Wire1.setSDA(14);
Wire1.setSCL(15);

GP18 + GP19

Wire1.setSDA(18);
Wire1.setSCL(19);

GP26 + GP27

Wire1.setSDA(26);
Wire1.setSCL(27);


The Arduino-Pico documentation explains that the RP2040 provides two I2C peripherals, Wire and Wire1, and that the pin assignment can be changed before initialization.

Understand What Is Happening

The OLED isn't being controlled directly through ordinary digital GPIO commands.

The Pico communicates with the OLED using the I2C protocol.

There are two important signals:

SDA

Serial Data

This line carries the data between the Pico and OLED.

SCL

Serial Clock

This provides the clock signal that synchronizes the communication.

The Pico acts as the I2C controller, while the OLED acts as an I2C peripheral.

The SSD1306 library takes care of the lower-level OLED commands, allowing us to use simple functions such as:

display.println("Hello Pico!");

instead of manually sending SSD1306 commands.

Experiment With the OLED

Once the basic example works, you can start experimenting.

Try changing:

display.setTextSize(1);

to:

display.setTextSize(2);

You can also change the text position:

display.setCursor(20, 20);

Draw shapes:

display.drawRect(10, 10, 100, 40, SSD1306_WHITE);

Draw circles:

display.drawCircle(64, 32, 20, SSD1306_WHITE);

And combine text and graphics to create your own Pico projects.

Final Result

After completing this project, you should have a Raspberry Pi Pico communicating with an SSD1306 OLED through I2C using the Arduino IDE.

The important part is that you don't have to randomly try different GPIO combinations.

For my tested setup, these combinations worked:

SDA SCL

GP0 GP1

GP4 GP5

GP16 GP17

GP20 GP21

My recommended starting point is:

SDA → GP4

SCL → GP5

Once the OLED is working, you can use it for sensor dashboards, clocks, mini games, IoT projects, robotics projects and many other Raspberry Pi Pico projects.

Conclusion


Getting a small OLED working should be one of the easiest Raspberry Pi Pico projects, but the combination of board cores, I2C pin configuration, OLED addresses and different libraries can make the first setup surprisingly frustrating.

That's exactly why I created this tutorial.

I tried several approaches before finding a configuration that worked for me. Hopefully, these tested pin combinations and the Arduino IDE setup save you some time.

Now that the basic OLED communication is working, the fun part begins — build something with it!

If you try this project, let me know which Pico pin combination you used and what you built.

Happy making! 🔧