Advertisement
Tywais

BME280_ESP32C6_TEST

Jul 19th, 2025
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <Adafruit_Sensor.h>
  3. #include <Adafruit_BME280.h>
  4.  
  5. #define sda    22  //ESP32C6
  6. #define scl    21
  7. #define SEALEVELPRESSURE_HPA (1013.25)
  8. unsigned long delayTime;
  9.  
  10. Adafruit_BME280 bme; // I2C
  11.  
  12. void setup() {
  13.    Wire.begin(sda, scl);
  14.    Serial.begin(115200);
  15.     while(!Serial);    // time to get serial running
  16.     Serial.println(F("BME280 test"));
  17.  
  18.     unsigned status;
  19.    
  20.     // default settings
  21.     status = bme.begin(0x76);  
  22.     if (!status) {
  23.         Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
  24.         Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16);
  25.         Serial.print("        ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
  26.         Serial.print("   ID of 0x56-0x58 represents a BMP 280,\n");
  27.         Serial.print("        ID of 0x60 represents a BME 280.\n");
  28.         Serial.print("        ID of 0x61 represents a BME 680.\n");
  29.         while (1) delay(10);
  30.     }
  31.    
  32.     Serial.println("-- Default Test --");
  33.     delayTime = 1000;
  34.     Serial.println();
  35. }
  36.  
  37. void loop() {
  38.     printValues();
  39.     delay(delayTime);
  40. }
  41.  
  42. void printValues() {
  43.     Serial.print("Temperature = ");
  44.     Serial.print(bme.readTemperature());
  45.     Serial.println(" °C");
  46.  
  47.     Serial.print("Pressure = ");
  48.  
  49.     Serial.print(bme.readPressure() / 100.0F);
  50.     Serial.println(" hPa");
  51.  
  52.     Serial.print("Approx. Altitude = ");
  53.     Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
  54.     Serial.println(" m");
  55.  
  56.     Serial.print("Humidity = ");
  57.     Serial.print(bme.readHumidity());
  58.     Serial.println(" %");
  59.  
  60.     Serial.println();
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement