To fix the gps power rail issue on RAK 19007 when RAK12023+RAK12035 is installed (#9409)

* asked claude to fix the gps power rail issue when the io slot is in use.. this fixes the gps when both the RAK12500 GPS module and the RAK12035 soil sensor modules are being used.

* remove do { ... } while(0) from RESTORE_3V3_POWER() Macro

* remove some comments

* cleaner macro

* removed more excessive comments

---------

Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
This commit is contained in:
Justin E. Mann
2026-01-24 04:16:36 -07:00
committed by GitHub
parent d407ec1975
commit 6b88d37b73

View File

@@ -4,6 +4,15 @@
#include "../mesh/generated/meshtastic/telemetry.pb.h"
#include "RAK12035Sensor.h"
// The RAK12035 library's sensor_sleep() sets WB_IO2 (GPIO 34) LOW, which controls
// the 3.3V switched power rail (PIN_3V3_EN). This turns off power to ALL peripherals
// including GPS. We need to restore power after the library turns it off.
#ifdef PIN_3V3_EN
#define RESTORE_3V3_POWER() digitalWrite(PIN_3V3_EN, HIGH)
#else
#define RESTORE_3V3_POWER()
#endif
RAK12035Sensor::RAK12035Sensor() : TelemetrySensor(meshtastic_TelemetrySensorType_RAK12035, "RAK12035") {}
bool RAK12035Sensor::initDevice(TwoWire *bus, ScanI2C::FoundDevice *dev)
@@ -13,7 +22,6 @@ bool RAK12035Sensor::initDevice(TwoWire *bus, ScanI2C::FoundDevice *dev)
delay(100);
sensor.begin(dev->address.address);
// Get sensor firmware version
uint8_t data = 0;
sensor.get_sensor_version(&data);
if (data != 0) {
@@ -21,8 +29,8 @@ bool RAK12035Sensor::initDevice(TwoWire *bus, ScanI2C::FoundDevice *dev)
LOG_INFO("RAK12035Sensor Init Succeed \nSensor1 Firmware version: %i, Sensor Name: %s", data, sensorName);
status = true;
sensor.sensor_sleep();
RESTORE_3V3_POWER();
} else {
// If we reach here, it means the sensor did not initialize correctly.
LOG_INFO("Init sensor: %s", sensorName);
LOG_ERROR("RAK12035Sensor Init Failed");
status = false;
@@ -38,8 +46,6 @@ bool RAK12035Sensor::initDevice(TwoWire *bus, ScanI2C::FoundDevice *dev)
void RAK12035Sensor::setup()
{
// Set the calibration values
// Reading the saved calibration values from the sensor.
// TODO:: Check for and run calibration check for up to 2 additional sensors if present.
uint16_t zero_val = 0;
uint16_t hundred_val = 0;
@@ -71,6 +77,7 @@ void RAK12035Sensor::setup()
LOG_INFO("Wet calibration reset complete. New value is %d", hundred_val);
}
sensor.sensor_sleep();
RESTORE_3V3_POWER();
delay(200);
LOG_INFO("Dry calibration value is %d", zero_val);
LOG_INFO("Wet calibration value is %d", hundred_val);
@@ -79,10 +86,6 @@ void RAK12035Sensor::setup()
bool RAK12035Sensor::getMetrics(meshtastic_Telemetry *measurement)
{
// TODO:: read and send metrics for up to 2 additional soil monitors if present.
// -- how to do this.. this could get a little complex..
// ie - 1> we combine them into an average and send that, 2> we send them as separate metrics
// ^-- these scenarios would require different handling of the metrics in the receiving end and maybe a setting in the
// device ui and an additional proto for that?
measurement->variant.environment_metrics.has_soil_temperature = true;
measurement->variant.environment_metrics.has_soil_moisture = true;
@@ -97,6 +100,7 @@ bool RAK12035Sensor::getMetrics(meshtastic_Telemetry *measurement)
success &= sensor.get_sensor_temperature(&temp);
delay(200);
sensor.sensor_sleep();
RESTORE_3V3_POWER();
if (success == false) {
LOG_ERROR("Failed to read sensor data");