Add support MS5837

This commit is contained in:
Theo Arends 2024-11-08 18:16:26 +01:00
parent a35bb5a5c9
commit df293dad82
7 changed files with 33 additions and 23 deletions

View File

@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
- Support for I2C over Serial (#22444)
- Support KNX for scripts (#22429)
- Support deep sleep (standby) for VL53L0X (#22441)
- Support for MS5837 pressure and temperature sensor (#22376)
### Breaking Changed

View File

@ -128,5 +128,6 @@ Index | Define | Driver | Device | Address(es) | Bus2 | Descrip
88 | USE_QMP6988 | xsns_28 | QMP6988 | 0x56, 0x70 | Yes | Pressure and temperature sensor
89 | USE_HX711_M5SCALES | xsns_34 | M5SCALES | 0x26 | Yes | M5Unit (Mini)Scales(HX711 STM32) U177
90 | USE_RX8010 | xdrv_56 | RX8010 | 0x32 | Yes | RX8010 RTC from IOTTIMER
91 | USE_MS5837 | xsns_116 | MS5837 | 0x76 | | Pressure and temperature sensor
NOTE: Bus2 supported on ESP32 only.

View File

@ -129,6 +129,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl https://ota.tasm
- Support for Shelly DALI Dimmer Gen3
- Support for HLK-LD2410S 24GHz smart wave motion sensor [#22253](https://github.com/arendst/Tasmota/issues/22253)
- Support for US AQI and EPA AQI in PMS5003x sensors [#22294](https://github.com/arendst/Tasmota/issues/22294)
- Support for MS5837 pressure and temperature sensor [#22376](https://github.com/arendst/Tasmota/issues/22376)
- HLK-LD2410 Engineering mode [#21880](https://github.com/arendst/Tasmota/issues/21880)
- Mitsubishi Electric HVAC Operation time for MiElHVAC [#22334](https://github.com/arendst/Tasmota/issues/22334)
- Mitsubishi Electric HVAC Outdoor Temperature for MiElHVAC [#22345](https://github.com/arendst/Tasmota/issues/22345)

View File

@ -173,7 +173,7 @@
//#define USE_MAX17043 // [I2cDriver83] Enable MAX17043 fuel-gauge systems Lipo batteries sensor (I2C address 0x36) (+0k9 code)
//#define USE_AMSX915 // [I2CDriver86] Enable AMS5915/AMS6915 pressure/temperature sensor (+1k2 code)
//#define USE_SPL06_007 // [I2cDriver87] Enable SPL06_007 pressure and temperature sensor (I2C addresses 0x76) (+2k5 code)
//#define USE_MS5837
//#define USE_MS5837 // [I2cDriver91] Enable MS5837 sensor (I2C address 0x76) (+2k7 code)
//#define USE_RTC_CHIPS // Enable RTC chip support and NTP server - Select only one
// #define USE_DS3231 // [I2cDriver26] Enable DS3231 RTC (I2C address 0x68) (+1k2 code)

View File

@ -450,7 +450,7 @@
//#define USE_LUXV30B // [I2CDriver70] Enable RFRobot SEN0390 LuxV30b ambient light sensor (I2C address 0x4A) (+0k5 code)
//#define USE_PMSA003I // [I2cDriver78] Enable PMSA003I Air Quality Sensor (I2C address 0x12) (+1k8 code)
//#define USE_GDK101 // [I2cDriver79] Enable GDK101 sensor (I2C addresses 0x18 - 0x1B) (+1k2 code)
// #define USE_MS5837
//#define USE_MS5837 // [I2cDriver91] Enable MS5837 sensor (I2C address 0x76) (+2k7 code)
//#define USE_RTC_CHIPS // Enable RTC chip support and NTP server - Select only one
// #define USE_DS3231 // [I2cDriver26] Enable DS3231 RTC (I2C address 0x68) (+1k2 code)
@ -693,7 +693,7 @@
//#define USE_LUXV30B // [I2CDriver70] Enable RFRobot SEN0390 LuxV30b ambient light sensor (I2C address 0x4A) (+0k5 code)
//#define USE_PMSA003I // [I2cDriver78] Enable PMSA003I Air Quality Sensor (I2C address 0x12) (+1k8 code)
//#define USE_GDK101 // [I2cDriver79] Enable GDK101 sensor (I2C addresses 0x18 - 0x1B) (+1k2 code)
// #define USE_MS5837
//#define USE_MS5837 // [I2cDriver91] Enable MS5837 sensor (I2C address 0x76) (+2k7 code)
//#define USE_RTC_CHIPS // Enable RTC chip support and NTP server - Select only one
// #define USE_DS3231 // [I2cDriver26] Enable DS3231 RTC (I2C address 0x68) (+1k2 code)

View File

@ -750,7 +750,7 @@
// #define USE_AMSX915 // [I2CDriver86] Enable AMS5915/AMS6915 pressure/temperature sensor (+1k2 code)
// #define USE_SPL06_007 // [I2cDriver87] Enable SPL06_007 pressure and temperature sensor (I2C addresses 0x76) (+2k5 code)
// #define USE_QMP6988 // [I2cDriver88] Enable QMP6988 pressure and temperature sensor (I2C address 0x56 or 0x70) (+2k9 code)
// #define USE_MS5837
// #define USE_MS5837 // [I2cDriver91] Enable MS5837 sensor (I2C address 0x76) (+2k7 code)
// #define USE_RTC_CHIPS // Enable RTC chip support and NTP server - Select only one
// #define USE_DS3231 // [I2cDriver26] Enable DS3231 RTC - used by Ulanzi TC001 (I2C address 0x68) (+1k2 code)

View File

@ -19,25 +19,27 @@
#ifdef USE_I2C
#ifdef USE_MS5837
#define MS5837_ADDR 0x76
#define XSNS_116 116
#define XI2C_91 91 // See I2CDEVICES.md
/*********************************************************************************************\
* BlueRobotics Pressure Sensor
*
* This driver supports the following sensors:
* - BlueRobotics MS5837
*
* I2C Address: 0x76
\*********************************************************************************************/
#define XSNS_116 116
#define XI2C_91 91 // See I2CDEVICES.md
#define MS5837_ADDR 0x76
#include <Wire.h>
#include <MS5837.h>
MS5837 sensor_ms5837;
MS5837 ms5837_sensor;
uint8_t ms5837Start = 0;
float pressure_offset = 2.85f;
bool ms5837_start = false;
float ms5837_pressure_offset = 2.85f;
/********************************************************************************************/
@ -46,10 +48,10 @@ void MS5837init(void) {
if (I2cSetDevice(0x76)) {
TwoWire& myWire = I2cGetWire();
if(sensor_ms5837.init(myWire)) {
sensor_ms5837.setModel(sensor_ms5837.MS5837_02BA);
sensor_ms5837.setFluidDensity(997); // kg/m^3 (freshwater, 1029 for seawater)
ms5837Start = 1;
if(ms5837_sensor.init(myWire)) {
ms5837_sensor.setModel(ms5837_sensor.MS5837_02BA);
ms5837_sensor.setFluidDensity(997); // kg/m^3 (freshwater, 1029 for seawater)
ms5837_start = true;
I2cSetActiveFound(MS5837_ADDR, "MS5837");
}
}
@ -69,22 +71,24 @@ void MS5837Show(bool json) {
char cmWater_str[8];
if (I2cEnabled(XI2C_91)) {
sensor_ms5837.read();
ms5837Temp = ConvertTemp(sensor_ms5837.temperature());
ms5837Pres = ConvertPressure(sensor_ms5837.pressure() + pressure_offset);
ms5837_sensor.read();
ms5837Temp = ConvertTemp(ms5837_sensor.temperature());
ms5837Pres = ConvertPressure(ms5837_sensor.pressure() + ms5837_pressure_offset);
ext_snprintf_P(temperature_str, sizeof(temperature_str), PSTR("%1_f"), &ms5837Temp);
ext_snprintf_P(pressure_str, sizeof(pressure_str), PSTR("%1_f"), &ms5837Pres);
if (json) {
ResponseAppend_P(PSTR(",\"MS5837\":{\"" D_JSON_TEMPERATURE "\":%s,\"" D_JSON_PRESSURE "\":%s"), temperature_str, pressure_str);
}
#ifdef USE_BMP
if (I2cEnabled(XI2C_10)) {
pressure_delta = (sensor_ms5837.pressure() + pressure_offset) - bmp_sensors[0].bmp_pressure;
pressure_delta = (ms5837_sensor.pressure() + ms5837_pressure_offset) - bmp_sensors[0].bmp_pressure;
cm_water = pressure_delta*0.401463078662f*2.54f; // changes from inches to cm after read using 2.54cm/in conversion
ext_snprintf_P(cmWater_str, sizeof(cmWater_str), PSTR("%1_f"), &cm_water);
if (json) {
ResponseAppend_P(PSTR(",\"" D_JSON_WATER_DEPTH "\":%s"),cmWater_str);
}
}
#endif // USE_BMP
if (json) {
ResponseAppend_P(PSTR("}"));
@ -92,9 +96,11 @@ void MS5837Show(bool json) {
} else {
WSContentSend_PD(HTTP_SNS_F_TEMP, name_str, Settings->flag2.temperature_resolution, &ms5837Temp, TempUnit());
WSContentSend_PD(HTTP_SNS_PRESSURE, name_str, pressure_str, PressureUnit().c_str());
#ifdef USE_BMP
if (I2cEnabled(XI2C_10)) {
WSContentSend_PD(HTTP_SNS_WATER_DEPTH, name_str, &cmWater_str);
}
#endif // USE_BMP
#endif // USE_WEBSERVER
}
}
@ -105,7 +111,9 @@ bool ms5837CommandSensor() {
switch (XdrvMailbox.payload) {
case 0:
MS5837Show(0);
pressure_offset = bmp_sensors[0].bmp_pressure - sensor_ms5837.pressure();
#ifdef USE_BMP
ms5837_pressure_offset = bmp_sensors[0].bmp_pressure - ms5837_sensor.pressure();
#endif // USE_BMP
break;
}
return serviced;
@ -119,12 +127,11 @@ bool Xsns116(uint32_t function) {
if (!I2cEnabled(XI2C_91)) { return false; }
bool result = false;
//I2cScan();
if (FUNC_INIT == function) {
MS5837init();
}
else if (ms5837Start) {
else if (ms5837_start) {
switch (function) {
case FUNC_COMMAND_SENSOR:
if (XSNS_116 == XdrvMailbox.index) {