Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for barometer BMP3xx #120

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 76 additions & 2 deletions lib/Baro/Baro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,42 @@ Baro::Baro(){
//FilterAlt(1.0f, 1.0f, 0.01f);
}

bool Baro::initBMP3XX(void){
uint8_t error;
bool ret = false;
for (sensorAdr = 0x76; sensorAdr <= 0x77; sensorAdr++)
{
log_i("check device at address 0x%X !",sensorAdr);
pI2c->beginTransmission(sensorAdr);
error = pI2c->endTransmission();
if (error == 0){
log_i("I2C device found at address 0x%X !",sensorAdr);
ret = bmp3xx.begin_I2C(sensorAdr,pI2c);
log_i("check sensor on adr 0x%X ret=%d",sensorAdr,ret);
if (ret){
log_i("found sensor BMP3XX on adr 0x%X",sensorAdr);
break;
}
}
else
{
log_i("Checking device at address 0x%X returned error %X", sensorAdr, error);
}
}

if (!ret) return false;

uint8_t chipId = bmp3xx.chipID();
if ((chipId == BMP3_CHIP_ID) || (chipId == BMP390_CHIP_ID))
log_i("found sensor BMP3xx on adr 0x%X",sensorAdr);
sensorType = SENSORTYPE_BMP3XX; //init to no sensor connected
//sensor found --> set sampling
bmp3xx.setPressureOversampling(BMP3_OVERSAMPLING_8X);
bmp3xx.setTemperatureOversampling(BMP3_NO_OVERSAMPLING);
bmp3xx.setIIRFilterCoeff(BMP3_IIR_FILTER_DISABLE);
return true;
}

bool Baro::initBME280(void){
uint8_t error;
sensorAdr = 0x76;
Expand Down Expand Up @@ -185,7 +221,7 @@ bool Baro::calibrate(bool bInit,uint8_t* calibstate){
preferences.putFloat("axScale", ax_scale);
preferences.putFloat("ayScale", ay_scale);
preferences.putFloat("azScale", az_scale);

logData.temp = getMpuTemp();
log_i("temp=%.1f",logData.temp);
preferences.putFloat("t[0]",logData.temp); //set temp from calibrating
Expand Down Expand Up @@ -525,6 +561,9 @@ uint8_t Baro::begin(TwoWire *pi2c){
}else if (initMS5611()){
log_i("found MS5611");
ret = 2; //GY-86-Board
}else if (initBMP3XX()){
log_i("found BMP3xx");
ret = 3; //BMP3xx;
}else{
return 0;
}
Expand Down Expand Up @@ -943,6 +982,39 @@ void Baro::runBME280(uint32_t tAct){
}
}

void Baro::runBMP3XX(uint32_t tAct){
static uint32_t tOld = millis();
//if ((tAct - tOld) >= 10)
{
if (!bmp3xx.performReading()) {
log_e("Failed to perform reading :(");
initBMP3XX();
return;
}
if (countReadings < 10){
countReadings++;
}else{
if (countReadings == 10){
logData.newData = 0x80;
countReadings++;
}
logData.temp = static_cast<float>(bmp3xx.temperature);
logData.pressure = static_cast<float>(bmp3xx.pressure);
logData.altitude = ms5611.getAltitude(bmp3xx.pressure);
logData.loopTime = tAct - tOld;
calcClimbing();
if (logData.newData == 0x80){
logData.newData = 0;
bNewValues = false;
}else{
copyValues();
logData.newData = 1;
bNewValues = true;
}
}
}
}

void Baro::run(void){
//static uint32_t tOld;
uint32_t tAct = millis();
Expand All @@ -951,6 +1023,8 @@ void Baro::run(void){
runMS5611(tAct);
}else if (sensorType == SENSORTYPE_BME280){
runBME280(tAct);
}else if (sensorType == SENSORTYPE_BMP3XX){
runBMP3XX(tAct);
}

#ifdef BARO_DEBUG
Expand Down Expand Up @@ -978,4 +1052,4 @@ void Baro::end(void){
mpu.setDMPEnabled(false);
mpu.setSleepEnabled(true);
}
}
}
9 changes: 6 additions & 3 deletions lib/Baro/Baro.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


/*!
* @file Baro.h
*
Expand All @@ -21,6 +19,7 @@
#include <math.h>
#include <kalmanvert.h>
#include <Adafruit_BME280.h>
#include <Adafruit_BMP3XX.h>
#include <Preferences.h>
#include "helper_3dmath.h"
#include "InterpolationLib.h"
Expand All @@ -41,6 +40,7 @@
#define SENSORTYPE_NONE 0
#define SENSORTYPE_MS5611 1
#define SENSORTYPE_BME280 2
#define SENSORTYPE_BMP3XX 3

class Baro {
struct udpData{
Expand Down Expand Up @@ -94,8 +94,10 @@ class Baro {
void copyValues(void);
bool initMS5611(void);
bool initBME280(void);
bool initBMP3XX(void);
void runMS5611(uint32_t tAct);
void runBME280(uint32_t tAct);
void runBMP3XX(uint32_t tAct);
bool mpuDrdy(void);
float getGravityCompensatedAccel(float temp);
void scaleAccel(VectorInt16 *accel,float temp);
Expand All @@ -107,6 +109,7 @@ class Baro {
uint8_t sensorAdr;
bool bNewValues;
Adafruit_BME280 bme;
Adafruit_BMP3XX bmp3xx;
MS5611 ms5611;
HMC5883L mag;
udpData logData;
Expand Down Expand Up @@ -138,4 +141,4 @@ class Baro {



#endif
#endif
2 changes: 2 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ build_flags = -D CORE_DEBUG_LEVEL=3
lib_deps =
h2zero/NimBLE-Arduino @ ~1.4.1
paulstoffregen/OneWire @ ~2.3.7
adafruit/Adafruit BusIO @ ^1.14.1
adafruit/Adafruit BMP3XX Library @ ^2.1.2
board_build.partitions = min_spiffs.csv
monitor_speed = 115200
upload_speed = 921600
Expand Down
11 changes: 9 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
#include "driver/rtc_io.h"
#endif

#define uS_TO_S_FACTOR 1000000uL /* Conversion factor for micro seconds to seconds */

#ifdef GSMODULE

Expand All @@ -83,7 +84,6 @@
#include <WeatherUnderground.h>
#include <Windy.h>

#define uS_TO_S_FACTOR 1000000uL /* Conversion factor for micro seconds to seconds */
//#define uS_TO_ms_FACTOR 1000000uL /* Conversion factor for micro seconds to seconds */
//#define TIME_TO_SLEEP 5uL //5 seconds
//#define TIME_TO_SLEEP 1800uL //1/2 Stunde
Expand Down Expand Up @@ -398,12 +398,15 @@ void handleUpdate(uint32_t tAct);
void printChipInfo(void);
void setAllTime(tm &timeinfo);
void checkExtPowerOff(uint32_t tAct);
#ifdef GSMODULE
void sendFanetWeatherData2WU(FanetLora::weatherData *weatherData,uint8_t wuIndex);
void sendFanetWeatherData2WI(FanetLora::weatherData *weatherData,uint8_t wiIndex);
#endif
#ifdef AIRMODULE
bool setupUbloxConfig(void);
#endif

#ifdef GSMODULE
void sendFanetWeatherData2WU(FanetLora::weatherData *weatherData,uint8_t wuIndex){
if ((status.bInternetConnected) && (status.bTimeOk)){
WeatherUnderground wu;
Expand Down Expand Up @@ -450,6 +453,7 @@ void sendFanetWeatherData2WI(FanetLora::weatherData *weatherData,uint8_t wiIndex
wi.sendData(setting.FntWiUpload[wiIndex].ID,setting.FntWiUpload[wiIndex].KEY,&wiData);
}
}
#endif

void readFuelSensor(uint32_t tAct){
static uint32_t tRead = millis();
Expand Down Expand Up @@ -4614,6 +4618,8 @@ void taskStandard(void *pvParameters){
}
}
}

#ifdef GSMODULE
FanetLora::weatherData weatherData;
if (fanet.getWeatherData(&weatherData)){
//check if we forward the weather-data to WU
Expand Down Expand Up @@ -4653,7 +4659,8 @@ void taskStandard(void *pvParameters){
}

}
}
}
#endif
if (fanet.getTrackingData(&tFanetData)){
//log_i("new Tracking-Data");
if (tFanetData.type == 0x11){ //online-tracking
Expand Down