Hi, I have a problem with power consumption.
Im using the HTCC-AB01 with a BME280 sensor.
The board sends values to ESP32 v2 and goes to sleep for 30min.
The issue is I can’t get the battery to last.
I tried powering it with 2 AAA batteries via 3.3v pin and got it to run for 1month.
If I use a 250mAh lipo it runs for 14 days.
Am I doing something wrong?
This is the code:
#include “Seeed_BME280.h”
#include “LoRaWan_APP.h”
#include “Arduino.h”
#include “Wire.h”
/*
set LoraWan_RGB to 1,the RGB active
RGB red means sending;
RGB green means received done;
*/
#define RF_FREQUENCY 868000000 // Hz
#define TX_OUTPUT_POWER 1 // dBm
#define LORA_BANDWIDTH 0 // [0: 125 kHz,
// 1: 250 kHz,
// 2: 500 kHz,
// 3: Reserved]
#define LORA_SPREADING_FACTOR 8 // [SF7…SF12]
#define LORA_CODINGRATE 4 // [1: 4/5,
// 2: 4/6,
// 3: 4/7,
// 4: 4/8]
#define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx
#define LORA_SYMBOL_TIMEOUT 0 // Symbols
#define LORA_FIX_LENGTH_PAYLOAD_ON false
#define LORA_IQ_INVERSION_ON false
#define RX_TIMEOUT_VALUE 1000
#define BUFFER_SIZE 12 // Define the payload size here
#define timetowake 1800000
float voltage;
//Sensor ID//
const int ID = 1;
static TimerEvent_t wakeUp;
uint8_t lowpower = 1;
char txpacket[BUFFER_SIZE];
static RadioEvents_t RadioEvents;
void OnTxDone( void );
void OnTxTimeout( void );
int16_t txNumber;
bool sleepMode = false;
int16_t rssi, rxSize;
BME280 bme280;
void setup() {
boardInitMcu( );
Serial.begin(115200);
pinMode(Vext, OUTPUT);
digitalWrite(Vext, LOW);
delay(500);
TimerInit( &wakeUp, onWakeUp );
//display.flipScreenVertically();
txNumber = 0;
rssi = 0;
RadioEvents.TxDone = OnTxDone;
RadioEvents.TxTimeout = OnTxTimeout;
onWakeUp();
}
void loop()
{
if (lowpower = 1) {
//note that lowPowerHandler() run six times the mcu into lowpower mode;
lowPowerHandler();
}
}
void onWakeUp()
{
lowpower = 0;
digitalWrite(Vext, LOW);
delay(500);
Serial.begin(115200);
float pressure;
Wire.begin(SDA, SCL);
if (!bme280.init()) {
Serial.println(“Device error!”);
}
pinMode(VBAT_ADC_CTL,OUTPUT);
float voltage=getBatteryVoltage();
Serial.println(voltage/1000);
delay(20);
Radio.Init(&RadioEvents);
Radio.SetChannel( RF_FREQUENCY );
Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
LORA_SPREADING_FACTOR, LORA_CODINGRATE,
LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
true, 0, 0, LORA_IQ_INVERSION_ON, 3000 );
double temp, humi;
//get and print temperatures
bme280.getTemperature();
bme280.getHumidity();
delay(500);
temp = bme280.getTemperature()-0.8;
Serial.print(“Temp: “);
Serial.print(temp);
Serial.println(“C”);//The unit for Celsius because original arduino don’t support speical symbols
//get and print humidity data
humi = bme280.getHumidity();
Serial.print(“Humidity: “);
Serial.print(humi);
Serial.println(”%”);
String pack =String(ID) + String(”:”) + String(temp, 1) + String(":") + String(humi, 0) + String(":") + String((voltage/1000));
sprintf(txpacket, “%s”, pack.c_str());
Serial.print(pack);
Serial.printf("\r\nsending packet “%s” , length %d\r\n", txpacket, strlen(txpacket));
Radio.Send( (uint8_t *)txpacket, strlen(txpacket) );
Serial.print(“TX done…”);
delay(1000);
//Serial.printf(“into lowpower mode, %d ms later wake up.\r\n”, timetowake);
onSleep();
}
void onSleep()
{
Serial.printf(“into lowpower mode, %d ms later wake up.\r\n”, timetowake);
lowpower = 1;
Radio.Sleep( );
Wire.end();
Serial.end();
digitalWrite(Vext, HIGH);
TimerSetValue( &wakeUp, timetowake );
TimerStart( &wakeUp );
}
void OnTxDone( void )
{
Serial.print(“TX done…”);
}
void OnTxTimeout( void )
{
Radio.Sleep( );
Serial.print(“TX Timeout…”);
}