Skip to content

Commit 27f7326

Browse files
authored
Added RAK12035 Soil Moisture and Temperature Sensor (#2223)
1 parent f5c0a74 commit 27f7326

5 files changed

Lines changed: 691 additions & 2 deletions

File tree

src/helpers/sensors/EnvironmentSensorManager.cpp

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ static Adafruit_MLX90614 MLX90614;
101101
static Adafruit_VL53L0X VL53L0X;
102102
#endif
103103

104+
#if ENV_INCLUDE_RAK12035
105+
#define TELEM_RAK12035_ADDRESS 0x20 // RAK12035 Soil Moisture sensor I2C address
106+
#include "RAK12035_SoilMoisture.h"
107+
static RAK12035_SoilMoisture RAK12035;
108+
#endif
109+
104110
#if ENV_INCLUDE_GPS && defined(RAK_BOARD) && !defined(RAK_WISMESH_TAG)
105111
#define RAK_WISBLOCK_GPS
106112
#endif
@@ -331,6 +337,17 @@ bool EnvironmentSensorManager::begin() {
331337
}
332338
#endif
333339

340+
#if ENV_INCLUDE_RAK12035
341+
RAK12035.setup(*TELEM_WIRE);
342+
if (RAK12035.begin(TELEM_RAK12035_ADDRESS)) {
343+
MESH_DEBUG_PRINTLN("Found sensor RAK12035 at address: %02X", TELEM_RAK12035_ADDRESS);
344+
RAK12035_initialized = true;
345+
} else {
346+
RAK12035_initialized = false;
347+
MESH_DEBUG_PRINTLN("RAK12035 was not found at I2C address %02X", TELEM_RAK12035_ADDRESS);
348+
}
349+
#endif
350+
334351
return true;
335352
}
336353

@@ -483,8 +500,36 @@ bool EnvironmentSensorManager::querySensors(uint8_t requester_permissions, Cayen
483500
}
484501
#endif
485502

486-
}
503+
#if ENV_INCLUDE_RAK12035
504+
if (RAK12035_initialized) {
505+
506+
// RAK12035 Telemetry is Channel 2
507+
telemetry.addTemperature(2, RAK12035.get_sensor_temperature());
508+
telemetry.addPercentage(2, RAK12035.get_sensor_moisture());
509+
510+
// RAK12035 CALIBRATION Telemetry is Channel 3, if enabled
487511

512+
#ifdef ENABLE_RAK12035_CALIBRATION
513+
// Calibration Data Screen is Channel 3
514+
float cap = RAK12035.get_sensor_capacitance();
515+
float _wet = RAK12035.get_humidity_full();
516+
float _dry = RAK12035.get_humidity_zero();
517+
518+
telemetry.addFrequency(3, cap);
519+
telemetry.addTemperature(3, _wet);
520+
telemetry.addPower(3, _dry);
521+
522+
if(cap > _dry){
523+
RAK12035.set_humidity_zero(cap);
524+
}
525+
526+
if(cap < _wet){
527+
RAK12035.set_humidity_full(cap);
528+
}
529+
#endif
530+
}
531+
#endif
532+
}
488533
return true;
489534
}
490535

@@ -665,7 +710,7 @@ bool EnvironmentSensorManager::gpsIsAwake(uint8_t ioPin){
665710
gps_detected = true;
666711
return true;
667712
}
668-
713+
669714
pinMode(ioPin, INPUT);
670715
MESH_DEBUG_PRINTLN("GPS did not init with this IO pin... try the next");
671716
return false;

src/helpers/sensors/EnvironmentSensorManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class EnvironmentSensorManager : public SensorManager {
2222
bool SHT4X_initialized = false;
2323
bool BME680_initialized = false;
2424
bool BMP085_initialized = false;
25+
bool RAK12035_initialized = false;
2526

2627
bool gps_detected = false;
2728
bool gps_active = false;

0 commit comments

Comments
 (0)