Skip to content

WIP:T1000E some ideas for power usage improvements #596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions variants/t1000-e/T1000eBoard.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <Arduino.h>
#include "T1000eBoard.h"
#include <Wire.h>
// #include <Wire.h>

#include <bluefruit.h>

Expand All @@ -18,12 +18,12 @@ void T1000eBoard::begin() {
#endif

#if defined(PIN_BOARD_SDA) && defined(PIN_BOARD_SCL)
Wire.setPins(PIN_BOARD_SDA, PIN_BOARD_SCL);
// Wire.setPins(PIN_BOARD_SDA, PIN_BOARD_SCL);
#endif

Wire.begin();
// Wire.begin();

delay(10); // give sx1262 some time to power up
delay(10); // give LR11x0 some time to power up
}

#if 0
Expand Down
6 changes: 5 additions & 1 deletion variants/t1000-e/T1000eBoard.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class T1000eBoard : public mesh::MainBoard {
digitalWrite(PIN_3V3_EN, LOW);
#endif

analogReference(AR_DEFAULT); // put back to default
// reset ADC reference to default to save power
analogReference(AR_DEFAULT);
analogReadResolution(10);

return volts * 1000;
Expand Down Expand Up @@ -87,6 +88,9 @@ class T1000eBoard : public mesh::MainBoard {
#ifdef LED_PIN
digitalWrite(LED_PIN, LOW);
#endif

radio.sleep();
Copy link
Collaborator

Choose a reason for hiding this comment

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

On my platformio setup, it won't compile if I let this ... don't know about radio on board


#ifdef BUTTON_PIN
nrf_gpio_cfg_sense_input(digitalPinToInterrupt(BUTTON_PIN), NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_HIGH);
#endif
Expand Down
8 changes: 8 additions & 0 deletions variants/t1000-e/t1000e_sensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ float t1000e_get_temperature( void )
digitalWrite(PIN_3V3_EN, LOW);
digitalWrite(SENSOR_EN, LOW);

// reset ADC reference to default to save power
analogReference(AR_DEFAULT);
analogReadResolution(10);

return get_heater_temperature (vcc_v, ntc_v);
}

Expand All @@ -114,6 +118,10 @@ uint32_t t1000e_get_light( void )
lux_v = 1000 * analogRead(LUX_SENSOR) * AREF_VOLTAGE / 4096;
lux = get_light_lv( lux_v );
digitalWrite(SENSOR_EN, LOW);

// reset ADC reference to default to save power
analogReference(AR_DEFAULT);
analogReadResolution(10);

return lux;
}
20 changes: 16 additions & 4 deletions variants/t1000-e/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ bool radio_init() {
if (status != RADIOLIB_ERR_NONE) {
Serial.print("ERROR: radio init failed: ");
Serial.println(status);
SPI.end();
return false; // fail
}

Expand All @@ -71,6 +72,8 @@ bool radio_init() {
radio.setRxBoostedGainMode(RX_BOOSTED_GAIN);
#endif

radio.sleep();

return true; // success
}

Expand All @@ -79,23 +82,34 @@ uint32_t radio_get_rng_seed() {
}

void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
radio.standby();
delayMicroseconds(100);
radio.setFrequency(freq);
radio.setSpreadingFactor(sf);
radio.setBandwidth(bw);
radio.setCodingRate(cr);
radio.sleep();
}

void radio_set_tx_power(uint8_t dbm) {
radio.standby();
delayMicroseconds(100);
radio.setOutputPower(dbm);
radio.sleep();
}

mesh::LocalIdentity radio_new_identity() {
radio.standby();
delayMicroseconds(100);
RadioNoiseListener rng(radio);
return mesh::LocalIdentity(&rng); // create new random identity
mesh::LocalIdentity identity = mesh::LocalIdentity(&rng); // create new random identity
radio.sleep();
return identity;
}

void T1000SensorManager::start_gps() {
gps_active = true;
Serial1.begin(115200);
//_nmea->begin();
// this init sequence should be better
// comes from seeed examples and deals with all gps pins
Expand Down Expand Up @@ -132,6 +146,7 @@ void T1000SensorManager::sleep_gps() {

void T1000SensorManager::stop_gps() {
gps_active = false;
Serial1.end();
digitalWrite(GPS_VRTC_EN, LOW);
digitalWrite(GPS_EN, LOW);
digitalWrite(GPS_RESET, HIGH);
Expand All @@ -144,9 +159,6 @@ void T1000SensorManager::stop_gps() {


bool T1000SensorManager::begin() {
// init GPS
Serial1.begin(115200);

// make sure gps pin are off
digitalWrite(GPS_VRTC_EN, LOW);
digitalWrite(GPS_RESET, LOW);
Expand Down
14 changes: 6 additions & 8 deletions variants/t1000-e/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,12 @@ const uint32_t g_ADigitalPinMap[PINS_COUNT + 1] =

void initVariant()
{
// All pins output HIGH by default.
// https://github.com/Seeed-Studio/Adafruit_nRF52_Arduino/blob/fab7d30a997a1dfeef9d1d59bfb549adda73815a/cores/nRF5/wiring.c#L65-L69

pinMode(BATTERY_PIN, INPUT);
pinMode(EXT_CHRG_DETECT, INPUT);
pinMode(EXT_PWR_DETECT, INPUT);
pinMode(GPS_RESETB, INPUT);
pinMode(PIN_BUTTON1, INPUT);
// Battery optimization: Input pins with appropriate pull resistors to prevent floating
pinMode(BATTERY_PIN, INPUT); // ADC input, no pull needed
pinMode(EXT_CHRG_DETECT, INPUT_PULLDOWN); // Battery optimization: Pull down to prevent floating
pinMode(EXT_PWR_DETECT, INPUT_PULLDOWN); // Battery optimization: Pull down to prevent floating
pinMode(GPS_RESETB, INPUT_PULLUP); // Battery optimization: Pull up for GPS reset
pinMode(PIN_BUTTON1, INPUT_PULLUP); // Battery optimization: Pull up for button (active low)

pinMode(PIN_3V3_EN, OUTPUT);
pinMode(PIN_3V3_ACC_EN, OUTPUT);
Expand Down