Replace BMP280 with BME280: remove BMP280 files and implement BME280 initialization and reading functions
This commit is contained in:
24
hardware/src/BME280.cpp
Normal file
24
hardware/src/BME280.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "BME280.hpp"
|
||||
|
||||
BME280I2C bme;
|
||||
|
||||
void BME280_Init()
|
||||
{
|
||||
Wire.setPins(21, 22);
|
||||
Wire.begin();
|
||||
while(!bme.begin())
|
||||
{
|
||||
Serial.println("Could not find BME280 sensor!");
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
bool BME280_Read(float &pressure, float &temperature, float &humidity)
|
||||
{
|
||||
BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
|
||||
BME280::PresUnit presUnit(BME280::PresUnit_Pa);
|
||||
bme.read(pressure, temperature, humidity, tempUnit, presUnit);
|
||||
|
||||
return (temperature != 0.0f && pressure != 0.0f);
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
#include "BMP280.hpp"
|
||||
|
||||
BMP280_DEV bme;
|
||||
|
||||
void BMP280_Init()
|
||||
{
|
||||
Wire.setPins(21, 22);
|
||||
if (!bme.begin(NORMAL_MODE, I2C_BMP280_ADDRESS))
|
||||
{
|
||||
Serial.println("BMP280 no detectado o error en la inicialización");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("BMP280 inicializado correctamente");
|
||||
}
|
||||
bme.setTimeStandby(TIME_STANDBY_2000MS);
|
||||
bme.startNormalConversion();
|
||||
}
|
||||
|
||||
bool BMP280_Read(float &temperature, float &pressure, float &altitude)
|
||||
{
|
||||
bme.getCurrentMeasurements(temperature, pressure, altitude);
|
||||
return (temperature != 0.0f && pressure != 0.0f);
|
||||
}
|
||||
|
||||
@@ -38,24 +38,12 @@ void setup()
|
||||
getRequest(httpClient, "http://172.20.10.7:8082/api/v1/sensors/1/values", response);
|
||||
deserializeSensorValue(httpClient, httpClient.GET()); */
|
||||
|
||||
BMP280_Init();
|
||||
BME280_Init();
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (BMP280_Read(temperature, pressure, altitude))
|
||||
{
|
||||
Serial.print("Temperature: ");
|
||||
Serial.println(temperature);
|
||||
Serial.print("Pressure: ");
|
||||
Serial.println(pressure);
|
||||
Serial.print("Altitude: ");
|
||||
Serial.println(altitude);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("❌ Lectura fallida del BMP280");
|
||||
}
|
||||
|
||||
delay(2000);
|
||||
}
|
||||
Serial.println(temperature);
|
||||
Serial.println(pressure);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user