Skip to content
Open
Show file tree
Hide file tree
Changes from 10 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
71 changes: 27 additions & 44 deletions src/helpers/sensors/EnvironmentSensorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,15 @@ static RAK12035_SoilMoisture RAK12035;
#endif

#ifdef RAK_WISBLOCK_GPS
static uint32_t gpsResetPin = 0;
static bool i2cGPSFlag = false;
static bool serialGPSFlag = false;
#ifndef TELEM_RAK12500_ADDRESS
#define TELEM_RAK12500_ADDRESS 0x42 //RAK12500 Ublox GPS via i2c
#define TELEM_RAK12500_ADDRESS 0x42 // RAK12500 u-blox ZOE-M8Q GPS via i2c
#endif
#include <SparkFun_u-blox_GNSS_Arduino_Library.h>
static SFE_UBLOX_GNSS ublox_GNSS;
static SFE_UBLOX_GNSS ublox_GNSS; // RAK12500 u-blox ZOE-M8Q GPS via UART

class RAK12500LocationProvider : public LocationProvider {
class RAKI2CLocationProvider : public LocationProvider {
long _lat = 0;
long _lng = 0;
long _alt = 0;
Expand Down Expand Up @@ -207,7 +206,7 @@ class RAK12500LocationProvider : public LocationProvider {
bool isEnabled() override { return true; }
};

static RAK12500LocationProvider RAK12500_provider;
static RAKI2CLocationProvider RAK12500_provider;
#endif

// ============================================================
Expand Down Expand Up @@ -775,7 +774,6 @@ void EnvironmentSensorManager::initBasicGPS() {
// or make a new location provider ...
#ifdef RAK_WISBLOCK_GPS
void EnvironmentSensorManager::rakGPSInit(){

Serial1.setPins(PIN_GPS_TX, PIN_GPS_RX);

#ifdef GPS_BAUD_RATE
Expand All @@ -784,14 +782,14 @@ void EnvironmentSensorManager::rakGPSInit(){
Serial1.begin(9600);
#endif

//search for the correct IO standby pin depending on socket used
if(gpsIsAwake(WB_IO2)){
}
else if(gpsIsAwake(WB_IO4)){
}
else if(gpsIsAwake(WB_IO5)){
}
else{
#ifdef PIN_3V3_EN

@IoTThinks IoTThinks Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except for RAK3401 with 1W with required PIN_3V3_EN at start, most of the RAK boards should have PIN_3V3_EN as INPUT to save power.
This is same as start_gps() too.

And we only need to set it HIGH as this is Power switch, not a GPS RESET.

Please change this:

  #ifdef PIN_3V3_EN
  digitalWrite(PIN_3V3_EN,LOW);
  delay(1000);
  digitalWrite(PIN_3V3_EN,HIGH);
  delay(2000);
  #endif

to this

  #ifdef PIN_3V3_EN
  pinMode(PIN_3V3_EN, OUTPUT);
  digitalWrite(PIN_3V3_EN, HIGH);
  delay(500);
  #endif

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except for RAK3401 with 1W with required PIN_3V3_EN at start, most of the RAK boards should have PIN_3V3_EN as INPUT to save power.

And RAK Ethernet (RAK13800) ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And RAK Ethernet (RAK13800) ?

I have no idea.
However, putting pinMode(PIN_3V3_EN, OUTPUT); in front is better than without it.
We can call it as many times without impact.

If the boards have PIN_3V3_EN as INPUT such as RA4631 and may be other RAK-based boards, digitalWrite(PIN_3V3_EN,HIGH); will not be effective.

We can see in start_gps(), we also call pinMode(PIN_3V3_EN, OUTPUT); before digitalWrite(PIN_3V3_EN,HIGH);

@YoshiWalsh YoshiWalsh Aug 1, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you link documentation that states that keeping PIN_3V3_EN as INPUT saves power? My understanding is that setting the pin as HIGH shouldn't take power because it's pulled high by default.

re: removing the code to pulse PIN_3V3_EN low for 1s at startup, that code appears to be recommended by RAK so I'm hesitant to remove it. I think it ensures that the GPS is in a consistent state when our code initialises.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. You can check the code for T096 and see initVariantShutdown.

RAK boards are no magic, but NRF52 boards. They follow the same rules.

  1. You can check the code for RAK4631 and other RAK-based boards, then imaging what digitalWrite does without pinMode OUT?

Currently, RAK4631 doesnot have pinMode for 3v3 en.

Assume you can turn off LoRa for RAK3401, try to remove pin Mode OUT for 3v3 en.
Then try to bring up GPS via Uart.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least, we have to put pinMode OUT.
RAK4631 does not have it.

You can keep the delay or you can explore what are best values.

RAK is a hardware vendor. Their code is sample and on safest side only.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now resolved by setting the pin to write mode in RAK4631Board.cpp.

digitalWrite(PIN_3V3_EN,LOW);
delay(1000);
digitalWrite(PIN_3V3_EN,HIGH);
delay(2000);
#endif

if(!gpsIsAwake()){
MESH_DEBUG_PRINTLN("No GPS found");
gps_active = false;
gps_detected = false;
Expand All @@ -805,25 +803,10 @@ void EnvironmentSensorManager::rakGPSInit(){
#endif
}

bool EnvironmentSensorManager::gpsIsAwake(uint8_t ioPin){

#if defined(ETHERNET_ENABLED) && defined(RAK_BOARD)
if (ioPin == WB_IO2) {
// WB_IO2 powers the Ethernet module on RAK baseboards.
return false;
}
#endif

//set initial waking state
pinMode(ioPin,OUTPUT);
digitalWrite(ioPin,LOW);
delay(500);
digitalWrite(ioPin,HIGH);
delay(500);

bool EnvironmentSensorManager::gpsIsAwake(){
//Try to init RAK12500 on I2C
if (ublox_GNSS.begin(Wire) == true){
MESH_DEBUG_PRINTLN("RAK12500 GPS init correctly with pin %i",ioPin);
MESH_DEBUG_PRINTLN("RAK12500 I2C GPS init");
ublox_GNSS.setI2COutput(COM_TYPE_UBX);
ublox_GNSS.enableGNSS(true, SFE_UBLOX_GNSS_ID_GPS);
ublox_GNSS.enableGNSS(true, SFE_UBLOX_GNSS_ID_GALILEO);
Expand All @@ -834,37 +817,29 @@ bool EnvironmentSensorManager::gpsIsAwake(uint8_t ioPin){
ublox_GNSS.enableGNSS(true, SFE_UBLOX_GNSS_ID_QZSS);
ublox_GNSS.setMeasurementRate(1000);
ublox_GNSS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT);
gpsResetPin = ioPin;
i2cGPSFlag = true;
gps_active = true;
gps_detected = true;

_location = &RAK12500_provider;
return true;
} else if (Serial1.available()) {
MESH_DEBUG_PRINTLN("Serial GPS init correctly and is turned on");
#ifdef PIN_GPS_EN
if(PIN_GPS_EN){
gpsResetPin = PIN_GPS_EN;
}
#endif
MESH_DEBUG_PRINTLN("Serial GPS init correctly");
serialGPSFlag = true;
gps_active = true;
gps_detected = true;
return true;
}

pinMode(ioPin, INPUT);
MESH_DEBUG_PRINTLN("GPS did not init with this IO pin... try the next");
return false;
}
#endif

void EnvironmentSensorManager::start_gps() {
gps_active = true;
#ifdef RAK_WISBLOCK_GPS
pinMode(gpsResetPin, OUTPUT);
digitalWrite(gpsResetPin, HIGH);
pinMode(PIN_3V3_EN, OUTPUT);
digitalWrite(PIN_3V3_EN, HIGH);
return;
#endif

Expand All @@ -879,8 +854,16 @@ void EnvironmentSensorManager::start_gps() {
void EnvironmentSensorManager::stop_gps() {
gps_active = false;
#ifdef RAK_WISBLOCK_GPS
pinMode(gpsResetPin, OUTPUT);
digitalWrite(gpsResetPin, LOW);
#ifdef ETHERNET_ENABLED
MESH_DEBUG_PRINTLN("GPS cannot be disabled as this would also disable Ethernet.");
return;
#endif
#ifdef SKY66122
MESH_DEBUG_PRINTLN("GPS cannot be disabled as this would also disable SKY66122.");
return;
#endif
pinMode(PIN_3V3_EN, OUTPUT);
digitalWrite(PIN_3V3_EN, LOW);
return;
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/sensors/EnvironmentSensorManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class EnvironmentSensorManager : public SensorManager {
void initBasicGPS();
#ifdef RAK_BOARD
void rakGPSInit();
bool gpsIsAwake(uint8_t ioPin);
bool gpsIsAwake();
#endif
#endif

Expand Down
14 changes: 7 additions & 7 deletions variants/gat562_30s_mesh_kit/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ extern "C"
{
#endif // __cplusplus

/*
/*
* WisBlock Base GPIO definitions
*/
static const uint8_t WB_IO1 = 17; // SLOT_A SLOT_B
static const uint8_t WB_IO2 = 34; // SLOT_A SLOT_B
static const uint8_t WB_IO3 = 21; // SLOT_C
static const uint8_t WB_IO4 = 4; // SLOT_C
static const uint8_t WB_IO5 = 9; // SLOT_D
static const uint8_t WB_IO6 = 10; // SLOT_D
static const uint8_t WB_IO1 = 17; // SLOT_A P.12 / SLOT_B P.10
static const uint8_t WB_IO2 = 34; // SLOT_A P.10 / SLOT_B P.12
static const uint8_t WB_IO3 = 21; // SLOT_C P.12
static const uint8_t WB_IO4 = 4; // SLOT_C P.10
static const uint8_t WB_IO5 = 9; // SLOT_D P.12
static const uint8_t WB_IO6 = 10; // SLOT_D P.10
static const uint8_t WB_SW1 = 33; // IO_SLOT
static const uint8_t WB_A0 = 5; // IO_SLOT
static const uint8_t WB_A1 = 31; // IO_SLOT
Expand Down
14 changes: 7 additions & 7 deletions variants/gat562_mesh_evb_pro/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ extern "C"
{
#endif // __cplusplus

/*
/*
* WisBlock Base GPIO definitions
*/
static const uint8_t WB_IO1 = 17; // SLOT_A SLOT_B
static const uint8_t WB_IO2 = 34; // SLOT_A SLOT_B
static const uint8_t WB_IO3 = 21; // SLOT_C
static const uint8_t WB_IO4 = 4; // SLOT_C
static const uint8_t WB_IO5 = 9; // SLOT_D
static const uint8_t WB_IO6 = 10; // SLOT_D
static const uint8_t WB_IO1 = 17; // SLOT_A P.12 / SLOT_B P.10
static const uint8_t WB_IO2 = 34; // SLOT_A P.10 / SLOT_B P.12
static const uint8_t WB_IO3 = 21; // SLOT_C P.12
static const uint8_t WB_IO4 = 4; // SLOT_C P.10
static const uint8_t WB_IO5 = 9; // SLOT_D P.12
static const uint8_t WB_IO6 = 10; // SLOT_D P.10
static const uint8_t WB_SW1 = 33; // IO_SLOT
static const uint8_t WB_A0 = 5; // IO_SLOT
static const uint8_t WB_A1 = 31; // IO_SLOT
Expand Down
14 changes: 7 additions & 7 deletions variants/gat562_mesh_tracker_pro/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ extern "C"
{
#endif // __cplusplus

/*
/*
* WisBlock Base GPIO definitions
*/
static const uint8_t WB_IO1 = 17; // SLOT_A SLOT_B
static const uint8_t WB_IO2 = 34; // SLOT_A SLOT_B
static const uint8_t WB_IO3 = 21; // SLOT_C
static const uint8_t WB_IO4 = 4; // SLOT_C
static const uint8_t WB_IO5 = 9; // SLOT_D
static const uint8_t WB_IO6 = 10; // SLOT_D
static const uint8_t WB_IO1 = 17; // SLOT_A P.12 / SLOT_B P.10
static const uint8_t WB_IO2 = 34; // SLOT_A P.10 / SLOT_B P.12
static const uint8_t WB_IO3 = 21; // SLOT_C P.12
static const uint8_t WB_IO4 = 4; // SLOT_C P.10
static const uint8_t WB_IO5 = 9; // SLOT_D P.12
static const uint8_t WB_IO6 = 10; // SLOT_D P.10
static const uint8_t WB_SW1 = 33; // IO_SLOT
static const uint8_t WB_A0 = 5; // IO_SLOT
static const uint8_t WB_A1 = 31; // IO_SLOT
Expand Down
14 changes: 7 additions & 7 deletions variants/gat562_mesh_watch13/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ extern "C"
{
#endif // __cplusplus

/*
/*
* WisBlock Base GPIO definitions
*/
static const uint8_t WB_IO1 = 17; // SLOT_A SLOT_B
static const uint8_t WB_IO2 = 34; // SLOT_A SLOT_B
static const uint8_t WB_IO3 = 21; // SLOT_C
static const uint8_t WB_IO4 = 4; // SLOT_C
static const uint8_t WB_IO5 = 9; // SLOT_D
static const uint8_t WB_IO6 = 10; // SLOT_D
static const uint8_t WB_IO1 = 17; // SLOT_A P.12 / SLOT_B P.10
static const uint8_t WB_IO2 = 34; // SLOT_A P.10 / SLOT_B P.12
static const uint8_t WB_IO3 = 21; // SLOT_C P.12
static const uint8_t WB_IO4 = 4; // SLOT_C P.10
static const uint8_t WB_IO5 = 9; // SLOT_D P.12
static const uint8_t WB_IO6 = 10; // SLOT_D P.10
static const uint8_t WB_SW1 = 33; // IO_SLOT
static const uint8_t WB_A0 = 5; // IO_SLOT
static const uint8_t WB_A1 = 31; // IO_SLOT
Expand Down
1 change: 1 addition & 0 deletions variants/rak3401/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ build_flags = ${nrf52_base.build_flags}
${sensor_base.build_flags}
-I variants/rak3401
-D RAK_3401
-D RAK_BOARD
-D NRF52_POWER_MANAGEMENT
-D RADIO_CLASS=CustomSX1262
-D WRAPPER_CLASS=CustomSX1262Wrapper
Expand Down
42 changes: 26 additions & 16 deletions variants/rak3401/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,27 @@ extern "C"
{
#endif // __cplusplus

/*
* WisBlock Base GPIO definitions
*/
static const uint8_t WB_IO1 = 17; // SLOT_A P.12 / SLOT_B P.10
static const uint8_t WB_IO2 = 34; // SLOT_A P.10 / SLOT_B P.12
static const uint8_t WB_IO3 = 21; // SLOT_C P.12
static const uint8_t WB_IO4 = 4; // SLOT_C P.10
static const uint8_t WB_IO5 = 9; // SLOT_D P.12
static const uint8_t WB_IO6 = 10; // SLOT_D P.10
static const uint8_t WB_SW1 = 33; // IO_SLOT
static const uint8_t WB_A0 = 5; // IO_SLOT
static const uint8_t WB_A1 = 31; // IO_SLOT
static const uint8_t WB_I2C1_SDA = 13; // SENSOR_SLOT IO_SLOT
static const uint8_t WB_I2C1_SCL = 14; // SENSOR_SLOT IO_SLOT
static const uint8_t WB_I2C2_SDA = 24; // IO_SLOT
static const uint8_t WB_I2C2_SCL = 25; // IO_SLOT
static const uint8_t WB_SPI_CS = 26; // IO_SLOT
static const uint8_t WB_SPI_CLK = 3; // IO_SLOT
static const uint8_t WB_SPI_MISO = 29; // IO_SLOT
static const uint8_t WB_SPI_MOSI = 30; // IO_SLOT

// Number of pins defined in PinDescription array
#define PINS_COUNT (48)
#define NUM_DIGITAL_PINS (48)
Expand Down Expand Up @@ -92,8 +113,6 @@ extern "C"

#define PIN_AREF (2)
#define PIN_NFC1 (9)
#define WB_IO5 PIN_NFC1
#define WB_IO4 (4)
#define PIN_NFC2 (10)

static const uint8_t AREF = PIN_AREF;
Expand Down Expand Up @@ -162,6 +181,7 @@ static const uint8_t AREF = PIN_AREF;
// in hardware via SetDIO2AsRfSwitchCtrl (microsecond-accurate, no GPIO needed).
// The 5V boost for the PA is enabled by WB_IO2 (P0.34 = PIN_3V3_EN).
#define SX126X_POWER_EN (21) // P0.21 = IO3 -> SKY66122 CSD+CPS (FEM enable)
#define SKY66122

// CTX is driven by SX1262 DIO2, not a GPIO
#define SX126X_DIO2_AS_RF_SWITCH
Expand All @@ -175,23 +195,13 @@ static const uint8_t AREF = PIN_AREF;
#define P_LORA_BUSY SX126X_BUSY
#define P_LORA_RESET SX126X_RESET

// enables 3.3V periphery like GPS or IO Module
// Do not toggle this for GPS power savings
// enables 3.3V periphery like GPS, the IO Module, and the SKY66122 5V boost
// Do NOT use this for GPS power savings as this will interfere with LoRa functionality
#define PIN_3V3_EN (34)
#define WB_IO2 PIN_3V3_EN

// RAK1910 GPS module
// If using the wisblock GPS module and pluged into Port A on WisBlock base
// IO1 is hooked to PPS (pin 12 on header) = gpio 17
// IO2 is hooked to GPS RESET = gpio 34, but it can not be used to this because IO2 is ALSO used to control 3V3_S power (1 is on).
// Therefore must be 1 to keep peripherals powered
// Power is on the controllable 3V3_S rail
#define PIN_GPS_PPS (17) // Pulse per second input from the GPS

#define PIN_GPS_RX PIN_SERIAL1_RX
#define PIN_GPS_TX PIN_SERIAL1_TX
#define PIN_GPS_TX PIN_SERIAL1_RX
#define PIN_GPS_RX PIN_SERIAL1_TX

#define PIN_GPS_1PPS PIN_GPS_PPS
#define GPS_BAUD_RATE 9600
#define GPS_ADDRESS 0x42 //i2c address for GPS

Expand Down
2 changes: 0 additions & 2 deletions variants/rak4631/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ build_flags = ${nrf52_base.build_flags}
-D NRF52_POWER_MANAGEMENT
-D PIN_BOARD_SCL=14
-D PIN_BOARD_SDA=13
-D PIN_GPS_TX=PIN_SERIAL1_RX
-D PIN_GPS_RX=PIN_SERIAL1_TX
-D PIN_GPS_EN=-1
-D PIN_OLED_RESET=-1
-D USE_SX1262
Expand Down
16 changes: 9 additions & 7 deletions variants/rak4631/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ extern "C"
/*
* WisBlock Base GPIO definitions
*/
static const uint8_t WB_IO1 = 17; // SLOT_A SLOT_B
static const uint8_t WB_IO2 = 34; // SLOT_A SLOT_B
static const uint8_t WB_IO3 = 21; // SLOT_C
static const uint8_t WB_IO4 = 4; // SLOT_C
static const uint8_t WB_IO5 = 9; // SLOT_D
static const uint8_t WB_IO6 = 10; // SLOT_D
static const uint8_t WB_IO1 = 17; // SLOT_A P.12 / SLOT_B P.10
static const uint8_t WB_IO2 = 34; // SLOT_A P.10 / SLOT_B P.12
static const uint8_t WB_IO3 = 21; // SLOT_C P.12
static const uint8_t WB_IO4 = 4; // SLOT_C P.10
static const uint8_t WB_IO5 = 9; // SLOT_D P.12
static const uint8_t WB_IO6 = 10; // SLOT_D P.10
static const uint8_t WB_SW1 = 33; // IO_SLOT
static const uint8_t WB_A0 = 5; // IO_SLOT
static const uint8_t WB_A1 = 31; // IO_SLOT
Expand Down Expand Up @@ -182,7 +182,9 @@ extern "C"
#define EXTERNAL_FLASH_DEVICES IS25LP080D
#define EXTERNAL_FLASH_USE_QSPI

#define PIN_GPS_1PPS 17 //GPS PPS pin
#define PIN_GPS_TX PIN_SERIAL1_RX

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add

// enables 3.3V periphery like GPS and the IO Module
#define PIN_3V3_EN (34)

Like this

// enables 3.3V periphery like GPS and the IO Module
#define PIN_3V3_EN (34)

#define PIN_GPS_TX PIN_SERIAL1_RX
#define PIN_GPS_RX PIN_SERIAL1_TX

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PIN_3V3_EN is currently missing in RAK4631.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah good point! I'll fix it

#define PIN_GPS_RX PIN_SERIAL1_TX

#define GPS_BAUD_RATE 9600
#define GPS_ADDRESS 0x42 //i2c address for GPS

Expand Down