Replace BMP280 with BME280: remove BMP280 files and implement BME280 initialization and reading functions
This commit is contained in:
7
hardware/include/BME280.hpp
Normal file
7
hardware/include/BME280.hpp
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#include <Wire.h>
|
||||||
|
#include <BME280I2C.h>
|
||||||
|
|
||||||
|
#define I2C_BMP280_ADDRESS 0x76
|
||||||
|
|
||||||
|
void BME280_Init();
|
||||||
|
bool BME280_Read(float &pressure, float &temperature, float &humidity);
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#include <Wire.h>
|
|
||||||
#include <BMP280_DEV.h>
|
|
||||||
|
|
||||||
#define I2C_BMP280_ADDRESS 0x76
|
|
||||||
|
|
||||||
void BMP280_Init();
|
|
||||||
bool BMP280_Read(float &temperature, float &pressure, float &altitude);
|
|
||||||
@@ -9,6 +9,6 @@
|
|||||||
#include "RestClient.hpp"
|
#include "RestClient.hpp"
|
||||||
#include "WifiConnection.hpp"
|
#include "WifiConnection.hpp"
|
||||||
#include "MqttClient.hpp"
|
#include "MqttClient.hpp"
|
||||||
#include "BMP280.hpp"
|
#include "BME280.hpp"
|
||||||
|
|
||||||
uint32_t getChipID();
|
uint32_t getChipID();
|
||||||
@@ -16,4 +16,4 @@ lib_deps =
|
|||||||
knolleary/PubSubClient@^2.8
|
knolleary/PubSubClient@^2.8
|
||||||
mikalhart/TinyGPSPlus@^1.0.2
|
mikalhart/TinyGPSPlus@^1.0.2
|
||||||
bblanchon/ArduinoJson@^6.17.3
|
bblanchon/ArduinoJson@^6.17.3
|
||||||
martinl1/BMP280_DEV@^1.0.21
|
finitespace/BME280@^3.0.0
|
||||||
|
|||||||
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);
|
getRequest(httpClient, "http://172.20.10.7:8082/api/v1/sensors/1/values", response);
|
||||||
deserializeSensorValue(httpClient, httpClient.GET()); */
|
deserializeSensorValue(httpClient, httpClient.GET()); */
|
||||||
|
|
||||||
BMP280_Init();
|
BME280_Init();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
if (BMP280_Read(temperature, pressure, altitude))
|
Serial.println(temperature);
|
||||||
{
|
Serial.println(pressure);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user