Introduction: BMP280 Interfacing With STM32F401CCU(Black Pill) Arduino IDE
Hello, in this tutorial I use the BMP280 to measure temperature, pressure, and also altitude, with the help of an STM32F401CCU board and Serial Monitor.
Supplies
1.STM32F401CCU6
2.BMP280
3.Jumper Wire
Step 1: Connect the Wires As Shown in the Diagram
NOTE: I've used Black Pill in my case but used a Blue Pill to show the wiring diagram because there was no Black Pill available in fritzing.Wiring will be the same for both boards.
Step 2: Install Adafruit BMP280 Library, Write the Code.
#include <Wire.h>
#include <Adafruit_BMP280.h>
Adafruit_BMP280 bmp;
void setup() {
Serial.begin(9600);
Wire.setSDA(PB9);
Wire.setSCL(PB8);
Wire.begin();
Serial.println(F("BMP280 test"));
if (!bmp.begin()) {
Serial.println(F("Could not find a valid BMP280 sensor, check wiring or "
"try a different address!"));
while (1) delay(10);
}
/* Default settings from datasheet. */
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
Adafruit_BMP280::FILTER_X16, /* Filtering. */
Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
}
void loop() {
Serial.print(F("Temperature = "));
Serial.print(bmp.readTemperature());
Serial.println(" *C");
Serial.print(F("Pressure = "));
Serial.print(bmp.readPressure());
Serial.println(" Pa");
Serial.print(F("Approx altitude = "));
Serial.print(bmp.readAltitude(1013.25)); /* Adjusted to local forecast! */
Serial.println(" m");
Serial.println();
delay(2000);
}Attachments
Step 3: Before Uploading the Code.
Go to your library c++ file, library is usually installed in the “Documents/Arduino/Libraries”, open Adafruit_BMP280.cpp file using Notepad++, Then go to the line “41” and _i2caddr change the “addr” with the address of your BMP280 Device(Usually 0x76):
Step 4: Connect STM32 With PC and Upload the Code.
Follow this link to know how to upload the code to STM32 from Arduino IDE using USB:
https://www.sgbotic.com/index.php?dispatch=pages.view&page_id=49






