Adafruit BME280 SPI frequency
Posted: Wed Aug 27, 2025 1:57 pm
Hi all.
I'm using an ESP32 DOIT DEVKIT V1 development board and the BME280 sensor. Below is the code for reading temperature, pressure, and humidity data via SPI. The code uses the "Adafruit BME280" libraries and works correctly, but the SPI frequency is fixed at 2 MHz. I'd like to know how to change the SPI frequency.
Many Thanks.
Regards
I'm using an ESP32 DOIT DEVKIT V1 development board and the BME280 sensor. Below is the code for reading temperature, pressure, and humidity data via SPI. The code uses the "Adafruit BME280" libraries and works correctly, but the SPI frequency is fixed at 2 MHz. I'd like to know how to change the SPI frequency.
Many Thanks.
Regards
Code: Select all
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define BME_SCK 18
#define BME_MISO 19
#define BME_MOSI 23
#define BME_CS 5
Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK);
void setup() {
Serial.begin(115200);
Serial.println("BME280 test on ESP32 via SPI");
if (!bme.begin()) {
Serial.println("Error! BME280 sensor not found.");
while (1);
}
Serial.println("BME280 ok!");
}
void loop() {
float temperature = bme.readTemperature();
float pressure = bme.readPressure() / 100.0F; // hPa convertion
float humidity = bme.readHumidity();
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Pressure: ");
Serial.print(pressure);
Serial.println(" hPa");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
Serial.println("--------------------");
delay(2000); // Wait 2 seconds
}