Go Down

Topic: ESP32 Firebeetle DFrobot (Read 114 times) previous topic - next topic

cbproyectos

Oct 27, 2020, 08:44 am Last Edit: Oct 27, 2020, 09:22 am by cbproyectos
Hi, after testing the esp32 DOIT Devkit v1 and seeing that the battery was very short in deep-sleep mode I decided to try the esp32 from the manufacturer Firebeetle. The difference in battery life is quite considerable but I have a problem that I don't understand and I'm not able to solve.
My project consists of calculating the distance to an object by means of an ultrasound and sending that measurement through Sigfox so that it reaches a web page. In order to save battery power I have to make the emission every hour and after sending it the microcontroller goes into deep-sleep mode. My problem is that when he wakes up, instead of taking a single measurement, there are times when he takes up to 10 or 15 measurements in a row every 10 seconds, consuming a lot of battery power. Does anyone know what could be happening? The only theory I can come up with is that something is interfering with his sleep, but I don't really understand what that is.
I'm enclosing the code in case someone can help me
Code: [Select]
#include <HardwareSerial.h>
#include "esp_sleep.h"
#define uS_TO_S_FACTOR 1000000ULL
#define TIME_TO_SLEEP 3600
#define LECTURAS 10
#define TAM_TRAMA_SIGFOX 4
HardwareSerial Sigfox(1);
int SigfoxBits = 9600;
uint8_t sigfoxMsg[TAM_TRAMA_SIGFOX];
const int
pwPin1 = 13;
long sensor1, cm;

void read_sensor()
{
  int acumulador =0;
  for (int i =0; i<LECTURAS; i++)
  {
    delay(200);
    acumulador=acumulador + ((int)pulseIn(pwPin1, HIGH) / 58); 
  }
  cm=acumulador/LECTURAS;
}

String sendMessage(uint8_t SigfoxMsg[], int bufferSize) {
  String status = "";
  char SigfoxBuffer;
  // Send AT$SF=xx to WISOL to send XX (payload data of size 1 to 12 bytes)
  Sigfox.print("AT$SF=");
  for(int i= 0;i<bufferSize;i++){   
    if (SigfoxMsg[i]<0x10)
    {
      Sigfox.print("0");
    }
    Sigfox.print(String(SigfoxMsg[i], HEX));
  }
  Sigfox.print("\r");
  while (!Sigfox.available()){
     delay(10);
  }
  while(Sigfox.available()){
    SigfoxBuffer = (char)Sigfox.read();
    status += SigfoxBuffer;
    delay(10);
  }
  return status;
}

void setup () {
  Serial.begin(115200);
  pinMode(pwPin1, INPUT);
  Sigfox.begin(9600, SERIAL_8N1, 16, 17);
  delay(300);
  esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP*uS_TO_S_FACTOR); 
}

void loop () {
  esp_sleep_wakeup_cause_t wakeup_reason;
  wakeup_reason = esp_sleep_get_wakeup_cause();
  if (wakeup_reason == ESP_SLEEP_WAKEUP_TIMER)
   {
     read_sensor();
     sigfoxMsg[0] = cm >> 24;
     sigfoxMsg[1] = cm >> 16;
     sigfoxMsg[2] = cm >> 8;
     sigfoxMsg[3] = cm;
     sendMessage(sigfoxMsg, TAM_TRAMA_SIGFOX);
   }
   esp_deep_sleep_start();
}



Idahowalker

#1
Oct 27, 2020, 12:48 pm Last Edit: Oct 27, 2020, 07:14 pm by Idahowalker
To see if the ESP32 is waking up early or something else is in the mix one could use an RTC_Fast ram location.
Declare a RTC_FAST ram global variable:
Code: [Select]
RTC_DATA_ATTR int bootCount = 0; // assign a memory location in RTC FAST RAM
In setup()
Code: [Select]

++bootcount;

In your loop have the boot count print out some words and the boot count. If you see boot counts printing changed numbers, that's a boot. If you see the same number printed several times in a row that means something is wrong.

It is better to place this code directly above the line that calls deep sleep.
Code: [Select]
[color=#222222]esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP*uS_TO_S_FACTOR);


See the ESP32 API https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/index.html[/color]]]https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/index.html][/color]https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/index.html[/color]]https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/index.html[color] for more info on RTC ram.[/color]


You might find it beneficial to, for an hour sleep time, to program the other ESP processor, the ULP, to handle your deep sleep wake ups. To program the ULP under the Arduino IDE see GNU Legacy ULP programming in the ESP32 API. Note the ULP is programmed using macro assembler.
Receiving partial information does not help me help you and wastes my time.

Go Up