STM32 Blue Pill I2C BMP280 with Wire: Wiring, Code and Simulator
To build this STM32 Blue Pill I2C BMP280 with Wire project you need an STM32 Blue Pill (STM32F103C8) and a pressure sensor BMP280. Wire on I2C1 (SDA PB7, SCL PB6) talks to a BMP280 through the STM32’s I2C peripheral and reads its chip ID (0x58). Make the 4 connections in the wiring table, upload the Arduino C++ code, and change the address to 0x77 and run again to see the error path, or read the temperature registers 0xFA–0xFC.
Open this circuit in the free STM32 Blue Pill (STM32F103C8) simulator
Parts list
| Qty | Part | What it does |
|---|---|---|
| 1 | STM32 Blue Pill (STM32F103C8) | the microcontroller board |
| 1 | Pressure Sensor BMP280 | Temperature and air pressure on I²C (0x76; 0x77 with SDO high): bmp.begin(0x76), readTemperature(), readPressure(), readAltitude(1013.25). |
Wiring
| # | From | To |
|---|---|---|
| 1 | STM32 Blue Pill (STM32F103C8) 3V3 | Pressure Sensor BMP280 VCC |
| 2 | STM32 Blue Pill (STM32F103C8) GND | Pressure Sensor BMP280 GND |
| 3 | STM32 Blue Pill (STM32F103C8) PB7 | Pressure Sensor BMP280 SDA |
| 4 | STM32 Blue Pill (STM32F103C8) PB6 | Pressure Sensor BMP280 SCL |
Step by step
- Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the STM32 Blue Pill (STM32F103C8). No install or account is needed.
- Add the parts. Add a pressure sensor BMP280 from the parts palette.
- Wire 1. Connect STM32 Blue Pill (STM32F103C8) 3V3 to Pressure Sensor BMP280 VCC.
- Wire 2. Connect STM32 Blue Pill (STM32F103C8) GND to Pressure Sensor BMP280 GND.
- Wire 3. Connect STM32 Blue Pill (STM32F103C8) PB7 to Pressure Sensor BMP280 SDA.
- Wire 4. Connect STM32 Blue Pill (STM32F103C8) PB6 to Pressure Sensor BMP280 SCL.
- Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
- Run it. Press Run. Change the address to 0x77 and run again to see the error path, or read the temperature registers 0xFA–0xFC.
Arduino C++ code
// I2C with Wire on I2C1 (SDA PB7, SCL PB6): read a BMP280's chip ID
// (register 0xD0 answers 0x58), then its raw temperature.
#include <Wire.h>
void setup() {
Serial.begin(115200);
Wire.begin();
}
uint8_t readReg(uint8_t reg) {
Wire.beginTransmission(0x76);
Wire.write(reg);
Wire.endTransmission(false);
Wire.requestFrom(0x76, 1);
return Wire.read();
}
void loop() {
Wire.beginTransmission(0x76);
if (Wire.endTransmission() != 0) {
Serial.println("No answer from 0x76");
} else {
Serial.print("BMP280 chip ID: 0x");
Serial.println(readReg(0xD0), HEX);
}
delay(1000);
}
What to try
Change the address to 0x77 and run again to see the error path, or read the temperature registers 0xFA–0xFC.
Frequently asked questions
How do I wire the I2C BMP280 with Wire project on an STM32 Blue Pill (STM32F103C8)?
Make 4 connections: STM32 Blue Pill (STM32F103C8) 3V3 to Pressure Sensor BMP280 VCC; STM32 Blue Pill (STM32F103C8) GND to Pressure Sensor BMP280 GND; STM32 Blue Pill (STM32F103C8) PB7 to Pressure Sensor BMP280 SDA; STM32 Blue Pill (STM32F103C8) PB6 to Pressure Sensor BMP280 SCL.
What parts do I need for this STM32 Blue Pill project?
An STM32 Blue Pill (STM32F103C8) and a pressure sensor BMP280.
Can I simulate this STM32 Blue Pill project online for free?
Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is built with the STM32duino core and runs on an STM32F103 emulated instruction by instruction: its ARM Cortex-M3 core, NVIC and peripherals (GPIO, EXTI, USART, timers, ADC and I²C).
What does the code do?
Wire on I2C1 (SDA PB7, SCL PB6) talks to a BMP280 through the STM32’s I2C peripheral and reads its chip ID (0x58).
More STM32 Blue Pill (STM32F103C8) projects
- STM32 Blue Pill HC-05 Bluetooth on USART2: Wiring, Code and Simulator
- STM32 Blue Pill LED Blink and Serial: Wiring, Code and Simulator
- STM32 Blue Pill Button Interrupt (EXTI): Wiring, Code and Simulator
- STM32 Blue Pill ADC Potentiometer and PWM LED: Wiring, Code and Simulator
- STM32 Blue Pill Serial UART Echo: Wiring, Code and Simulator
- STM32 Blue Pill Servo Motor Sweep: Wiring, Code and Simulator