Last active
June 21, 2022 09:39
-
-
Save woodif/8bbbbd14daeeac6119e2b9a847d8fde5 to your computer and use it in GitHub Desktop.
ESP32_BMP280
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This code is to use with Adafruit BMP280 (Metric) | |
* It measures both temperature and pressure and it displays them on the Serial monitor with the altitude | |
* It's a modified version of the Adafruit example code | |
* Refer to www.surtrtech.com or SurtrTech Youtube channel | |
*/ | |
#include <Wire.h> | |
#include <Adafruit_BMP280.h> | |
Adafruit_BMP280 bmp; // I2C Interface | |
void setup() { | |
Serial.begin(9600); | |
Serial.println(F("BMP280 test")); | |
Wire.begin(21,22); | |
//if (!bmp.begin()) { | |
if (!bmp.begin(0x76,0x58)) { | |
Serial.println(F("Could not find a valid BMP280 sensor, check wiring!")); | |
while (1); | |
} | |
/* 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()/100); //displaying the Pressure in hPa, you can change the unit | |
Serial.println(" hPa"); | |
Serial.print(F("Approx altitude = ")); | |
Serial.print(bmp.readAltitude(1019.66)); //The "1019.66" is the pressure(hPa) at sea level in day in your region | |
Serial.println(" m"); //If you don't know it, modify it until you get your current altitude | |
Serial.println(); | |
delay(2000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment