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)
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:
- How to connect an I2C OLED to Raspberry Pi Pico
- How to program the Pico using Arduino IDE
- Which libraries you need
- The I2C pin combinations I tested successfully
- How to manually configure the SDA and SCL pins
- How to display text on a 128×64 SSD1306 OLED
- 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
What You Need
Hardware
- Raspberry Pi Pico
- 0.96-inch 128×64 I2C OLED display
- Breadboard
- Male-to-male jumper wires
- USB cable
- Computer
Software
- Arduino IDE
- Raspberry Pi Pico/RP2040 Arduino board package
- Adafruit GFX Library
- 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
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:
- SDA — Serial Data
- 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
For the basic test, we'll use one of the working I2C combinations.
I recommend starting with:
OLEDRaspberry Pi Pico
Wiring
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
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
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
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:
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.
If you want to use another tested pins combination which comes under i2c0 configuration
Simply change these two lines.
For GP0/GP1:
For GP4/GP5:
For GP8/GP9:
For GP12/GP13:
For GP16/GP17:
For GP20/GP21:
If you want to use another tested pins combination which comes under i2c0 configuration
First Change this code
Then change these two lines
For GP2/GP3:
For GP6/GP7:
For GP10/GP11:
For GP14/GP15:
For GP18/GP19:
For GP26/GP27:
Upload the Code
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:
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:
Also make sure SDA and SCL aren't accidentally swapped.
2. Check the I2C address
A common SSD1306 I2C address is:
Some modules may use:
If your display uses a different address, change:
to the appropriate address.
3. Check the display resolution
This tutorial uses:
If you're using a different OLED resolution, change these values accordingly.
4. Check the selected I2C pins
If you're using GP4/GP5:
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
GP4 + GP5
GP8 + GP9
GP12 + GP13
GP16 + GP17
GP20 + GP21
I2C1 Pin mapping
GP2 + GP3
GP6 + GP7
GP10 + GP11
GP14 + GP15
GP18 + GP19
GP26 + GP27
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:
instead of manually sending SSD1306 commands.
Experiment With the OLED
Once the basic example works, you can start experimenting.
Try changing:
to:
You can also change the text position:
Draw shapes:
Draw circles:
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! 🔧