Add Sensirion SHT4X sensors (#3792)

* add Sensirion SHT4X sensors

* Update platformio.ini

Fix lib version

* Delete src/mesh/generated/meshtastic/telemetry.pb.h

* Revert "Delete src/mesh/generated/meshtastic/telemetry.pb.h"

This reverts commit 8e5e6a9f6ff4e31ed32775741c03a855e663a5de.

* remove modification on generated file

* Update ScanI2CTwoWire.cpp

Fix copy/paste issue

---------

Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com>
pull/3842/head
pr000t 2024-05-08 14:02:53 +02:00 zatwierdzone przez GitHub
rodzic 8105c0440a
commit 5371f134ba
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
8 zmienionych plików z 110 dodań i 4 usunięć

Wyświetl plik

@ -133,3 +133,4 @@ lib_deps =
https://github.com/lewisxhe/SensorLib#27fd0f721e20cd09e1f81383f0ba58a54fe84a17
adafruit/Adafruit LSM6DS@^4.7.2
mprograms/QMC5883LCompass@^1.2.0
https://github.com/Sensirion/arduino-i2c-sht4x#1.1.0

Wyświetl plik

@ -126,7 +126,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define SHTC3_ADDR 0x70
#define LPS22HB_ADDR 0x5C
#define LPS22HB_ADDR_ALT 0x5D
#define SHT31_ADDR 0x44
#define SHT31_4x_ADDR 0x44
#define PMSA0031_ADDR 0x12
#define RCWL9620_ADDR 0x57

Wyświetl plik

@ -29,6 +29,7 @@ class ScanI2C
INA3221,
MCP9808,
SHT31,
SHT4X,
SHTC3,
LPS22HB,
QMC6310,

Wyświetl plik

@ -292,7 +292,18 @@ void ScanI2CTwoWire::scanPort(I2CPort port)
break;
SCAN_SIMPLE_CASE(SHT31_ADDR, SHT31, "SHT31 sensor found\n")
case SHT31_4x_ADDR:
registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x89), 2);
if (registerValue == 0x11a2) {
type = SHT4X;
LOG_INFO("SHT4X sensor found\n");
} else {
type = SHT31;
LOG_INFO("SHT31 sensor found\n");
}
break;
SCAN_SIMPLE_CASE(SHTC3_ADDR, SHTC3, "SHTC3 sensor found\n")
SCAN_SIMPLE_CASE(RCWL9620_ADDR, RCWL9620, "RCWL9620 sensor found\n")
@ -357,4 +368,4 @@ TwoWire *ScanI2CTwoWire::fetchI2CBus(ScanI2C::DeviceAddress address) const
size_t ScanI2CTwoWire::countDevices() const
{
return foundDevices.size();
}
}

Wyświetl plik

@ -541,6 +541,7 @@ void setup()
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::QMC5883L, meshtastic_TelemetrySensorType_QMC5883L)
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::PMSA0031, meshtastic_TelemetrySensorType_PMSA003I)
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::RCWL9620, meshtastic_TelemetrySensorType_RCWL9620)
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::SHT4X, meshtastic_TelemetrySensorType_SHT4X)
i2cScanner.reset();
@ -1032,4 +1033,4 @@ void loop()
mainDelay.delay(delayMsec);
}
// if (didWake) LOG_DEBUG("wake!\n");
}
}

Wyświetl plik

@ -26,6 +26,7 @@
#include "Sensor/MCP9808Sensor.h"
#include "Sensor/RCWL9620Sensor.h"
#include "Sensor/SHT31Sensor.h"
#include "Sensor/SHT4XSensor.h"
#include "Sensor/SHTC3Sensor.h"
BMP085Sensor bmp085Sensor;
@ -36,6 +37,7 @@ MCP9808Sensor mcp9808Sensor;
SHTC3Sensor shtc3Sensor;
LPS22HBSensor lps22hbSensor;
SHT31Sensor sht31Sensor;
SHT4XSensor sht4xSensor;
RCWL9620Sensor rcwl9620Sensor;
#define FAILED_STATE_SENSOR_READ_MULTIPLIER 10
@ -91,6 +93,8 @@ int32_t EnvironmentTelemetryModule::runOnce()
result = lps22hbSensor.runOnce();
if (sht31Sensor.hasSensor())
result = sht31Sensor.runOnce();
if (sht4xSensor.hasSensor())
result = sht4xSensor.runOnce();
if (ina219Sensor.hasSensor())
result = ina219Sensor.runOnce();
if (ina260Sensor.hasSensor())
@ -246,6 +250,8 @@ bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly)
if (sht31Sensor.hasSensor())
valid = sht31Sensor.getMetrics(&m);
if (sht4xSensor.hasSensor())
valid = sht4xSensor.getMetrics(&m);
if (lps22hbSensor.hasSensor())
valid = lps22hbSensor.getMetrics(&m);
if (shtc3Sensor.hasSensor())

Wyświetl plik

@ -0,0 +1,63 @@
#include "configuration.h"
#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR
#include "../mesh/generated/meshtastic/telemetry.pb.h"
#include "SHT4XSensor.h"
#include "TelemetrySensor.h"
#include <SensirionI2cSht4x.h>
// macro definitions
// make sure that we use the proper definition of NO_ERROR
#ifdef NO_ERROR
#undef NO_ERROR
#endif
#define NO_ERROR 0
static char errorMessage[64];
static int16_t error;
SHT4XSensor::SHT4XSensor() : TelemetrySensor(meshtastic_TelemetrySensorType_SHT4X, "SHT4X") {}
int32_t SHT4XSensor::runOnce()
{
LOG_INFO("Init sensor: %s\n", sensorName);
if (!hasSensor()) {
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
}
uint32_t serialNumber = 0;
sht4x.begin(*nodeTelemetrySensorsMap[sensorType].second, 0x44);
error = sht4x.serialNumber(serialNumber);
LOG_DEBUG("serialNumber : %x\n", serialNumber);
if (error != NO_ERROR) {
LOG_DEBUG("Error trying to execute serialNumber(): ");
errorToString(error, errorMessage, sizeof errorMessage);
LOG_DEBUG(errorMessage);
status = 0;
} else {
status = 1;
}
return initI2CSensor();
}
void SHT4XSensor::setup()
{
// Set up oversampling and filter initialization
}
bool SHT4XSensor::getMetrics(meshtastic_Telemetry *measurement)
{
float aTemperature = 0.0;
float aHumidity = 0.0;
sht4x.measureLowestPrecision(aTemperature, aHumidity);
measurement->variant.environment_metrics.temperature = aTemperature;
measurement->variant.environment_metrics.relative_humidity = aHumidity;
return true;
}
#endif

Wyświetl plik

@ -0,0 +1,23 @@
#include "configuration.h"
#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR
#include "../mesh/generated/meshtastic/telemetry.pb.h"
#include "TelemetrySensor.h"
#include <SensirionI2cSht4x.h>
class SHT4XSensor : public TelemetrySensor
{
private:
SensirionI2cSht4x sht4x;
protected:
virtual void setup() override;
public:
SHT4XSensor();
virtual int32_t runOnce() override;
virtual bool getMetrics(meshtastic_Telemetry *measurement) override;
};
#endif