PCB lives now in its own git repo https://git.la10cy.net/DeltaLima/CanGrow-12V-PCB
54 lines
1.8 KiB
C
54 lines
1.8 KiB
C
/*
|
|
*
|
|
* include/Sensor/00_ADC_builtin.h - sensor header for BME280 I2C sensor
|
|
*
|
|
*
|
|
*
|
|
*/
|
|
|
|
|
|
#include <Adafruit_BME280.h>
|
|
|
|
|
|
#define SENSOR_02_NAME "BME280"
|
|
//#define SENSOR_02_MAXUNITS 2
|
|
|
|
/* available addresses in byte array, default is at 0 */
|
|
const byte Sensor_02_BME280_Addr[] = { 0x76, 0x77 };
|
|
|
|
Adafruit_BME280 BME280[sizeof(Sensor_02_BME280_Addr)];
|
|
|
|
/* creation of BME280 Value Struct, as many as addresses */
|
|
//Sensor_02_BME280 Sensor_02_BME280_Data[sizeof(Sensor_02_BME280_Addr)];
|
|
|
|
/* main data array */
|
|
float Sensor_02_BME280[sizeof(Sensor_02_BME280_Addr)][4];
|
|
|
|
void Sensor_02_BME280_Update(const byte AddrId) {
|
|
/* Temp */
|
|
Sensor_02_BME280[AddrId][0] = BME280[AddrId].readTemperature();
|
|
/* Humidity */
|
|
Sensor_02_BME280[AddrId][1] = BME280[AddrId].readHumidity();
|
|
/* Pressure */
|
|
Sensor_02_BME280[AddrId][2] = BME280[AddrId].readPressure() / 1000.00;
|
|
/* Altitude */
|
|
Sensor_02_BME280[AddrId][3] = BME280[AddrId].readAltitude(SEALEVELPRESSURE_HPA);
|
|
}
|
|
|
|
|
|
bool Sensor_02_BME280_Init(const byte AddrId) {
|
|
const static char LogLoc[] PROGMEM = "[Sensor:02_BME280:Init]";
|
|
bool returnCode;
|
|
//Log.notice(F("%s Init at addr 0x%x (%d)" CR), LogLoc, Sensor_02_BME280_Addr[AddrId], AddrId);
|
|
if(BME280[AddrId].begin(Sensor_02_BME280_Addr[AddrId])) {
|
|
Log.notice(F("%s found at addr 0x%x" CR), LogLoc, Sensor_02_BME280_Addr[AddrId]);
|
|
//Log.notice(F("%s Temp: %F°C Humidity: %F % Pressure: %FhPa, Appr. Altitude %Fm" CR), LogLoc, BME280[AddrId].readTemperature(), BME280[AddrId].readHumidity(), BME280[AddrId].readPressure() / 1000.00, BME280[AddrId].readAltitude(SEALEVELPRESSURE_HPA));
|
|
Sensor_02_BME280_Update(AddrId);
|
|
returnCode = true;
|
|
} else {
|
|
Log.error(F("%s FAILED! Not found at addr 0x%x" CR), LogLoc, Sensor_02_BME280_Addr[AddrId]);
|
|
returnCode = false;
|
|
}
|
|
|
|
return returnCode;
|
|
}
|