Board and part

Raspberry Pi Pico BMP280 Simulator: Wiring, Code and a Live Circuit

This is a BMP280 barometric pressure and temperature sensor wired to a Raspberry Pi Pico over I2C, read live with the Adafruit BMP280 library: temperature, pressure and altitude once a second.

  • 3.3 V logic
  • Library: Adafruit_BMP280.h
  • I2C address 0x76
  • SDA 4, SCL 5
Raspberry Pi Pico · BMP280live0.000 s 0.00x
Click to open it in the editor
The circuit itself, running on the simulator with the sketch below. Press what can be pressed; click anything else to open it in the editor.
Connections

Wiring the BMP280 to the Raspberry Pi Pico

Four wires: 3.3 V, GND, SDA to GP4 (physical pin 6) and SCL to GP5 (physical pin 7). In the editor, drag the sensor’s pressure slider and the altitude moves with it.

Every connection in the circuit above, with the board’s own pin names.

BMP280 pinRaspberry Pi Pico pinWhy
VIN3V3(OUT)The BMP280 chip is a 3.3 V part; many breakouts have no regulator.
GNDGNDCommon ground.
SCLGP5 (physical pin 7)I2C clock.
SDAGP4 (physical pin 6)I2C data.

Power

On the Pico, Wire.begin() puts SDA on GP4 and SCL on GP5, physical pins 6 and 7. The Raspberry Pi Pico and the BMP280 are both 3.3 V parts, so this is the simplest wiring there is: no regulator and no level shifter.

Pins to leave alone on the Raspberry Pi Pico

The numbers in the code are GP numbers, not the physical pin numbers printed beside the header: GP15 is pin 20. GP23 to GP25 are used on the board itself, and GP25 is the LED.

On a real bench

Solder headers on the Pico and press it into the breadboard across the center channel; the BMP280 goes in beside it. GND pins sit every fifth pin down both sides (pins 3, 8, 13, 18 and so on), so there is always one close. The first upload needs BOOTSEL held while plugging in.

The sketch

The code, and what it does.

The sketch the circuit above runs. Open it in the editor, change a line and press Run: it compiles in your browser.

BMP280 on Raspberry Pi Pico I2C
#include <Wire.h>
#include <Adafruit_BMP280.h>

Adafruit_BMP280 bmp;   // on I2C: SDA GP4 (physical pin 6), SCL GP5 (physical pin 7)

void setup() {
  Serial.begin(115200);
  if (!bmp.begin(0x76)) {
    Serial.println("No BMP280 at 0x76");
    for (;;) {}
  }
  Serial.println("BMP280 found");
}

void loop() {
  Serial.print("Temperature: ");
  Serial.print(bmp.readTemperature(), 1);
  Serial.print(" C  Pressure: ");
  Serial.print(bmp.readPressure() / 100.0F, 1);
  Serial.print(" hPa  Altitude: ");
  Serial.print(bmp.readAltitude(1013.25), 0);
  Serial.println(" m");
  delay(1000);
}

bmp.begin(0x76) reads the chip’s ID and its factory calibration, which every reading needs. It returns false when nothing answers at that address; boards with SDO tied high answer at 0x77 instead.

readTemperature() is degrees Celsius and readPressure() is pascals, so dividing by 100 gives hectopascals, the unit weather reports use. readAltitude(1013.25) turns pressure into meters above the level where it would be 1013.25 hPa; give it your local sea-level pressure for a true altitude.

Serial.begin(115200) opens the serial monitor. Serial is the USB port at 115200 baud in this sketch; on a real Pico it appears once the board has enumerated.

Pitfalls

Common mistakes with the BMP280 on the Raspberry Pi Pico

The wrong address

Adafruit’s own board answers at 0x77, the cheap purple ones at 0x76, and bmp.begin() with no argument tries 0x77. If it fails, try the other address before suspecting the wiring.

Powering it from VBUS (5 V from USB)

A breakout without a regulator is a bare 3.3 V chip: 5 V on VIN can kill it. Use 3V3, which on this board is also the right level for I2C.

Confusing it with a BME280

The BME280 looks the same and adds humidity. A BMP280 reports a chip ID of 0x58, a BME280 0x60, and each library refuses the other. If begin() fails at both addresses, check which chip you have.

FAQ

Questions and answers

Can I simulate a BMP280 with a Raspberry Pi Pico?

Yes. The circuit at the top of this page is a Raspberry Pi Pico with a BMP280, running in your browser on a simulated RP2040. The temperature and pressure sliders set what the simulated chip measures, and the library applies the real calibration math to it. Press Run it in the editor to change the wiring or the code; it is free and needs no account.

Where does the BMP280 connect on the Raspberry Pi Pico?

On the Pico, Wire.begin() puts SDA on GP4 and SCL on GP5, physical pins 6 and 7.

How accurate is the altitude?

Pressure changes with the weather by more than it changes over a few floors, so readAltitude() is only as good as the sea-level pressure you give it. Relative changes over a few minutes are accurate to about a meter.

Can I use the BMP280 over SPI?

The chip supports SPI, but this simulated part speaks I2C. Most breakouts are wired for I2C out of the box anyway.

Build your own BMP280 project

Open this circuit in the editor, change the wiring or the code, and keep your version in a free account.