ArduinoGeneral

DFR0478 and Arduino IDE, problems with Deepsleep

userHead Account cancelled 2020-10-30 08:12:47 1449 Views0 Replies
Hello!

I am doing a development with the Firebeetle ESP32 board DFR0478. This is a device to measure the amount in a tank. For this, I use an ultrasonic sensor (MB7052), a Firebeetle DFR0475 development board, a Wisol SFM10R1 chip to transmit the information through Sigfox and two Saft 17500 batteries in parallel. The device is powered by the XHT 2.0 lithium battery connector built into the development board.

The operation is as follows:

1. The sensor reads the value indicated by the ultrasonic sensor. Take 20 readings and calculate the average.
2. The value read is sent via Sigfox
3. The device sleeps for 60 minutes. Then, upon waking, we start on step 1.

However, the device does not always go into deepsleep. In many cases it works again after a few seconds, performing a new measurement and a new emission

Components:
1 x https://www.dfrobot.com/product-1590.html
1 x MB7052 Ultrasonic sensor: https://www.maxbotix.com/ultrasonic_sensors/mb7052.htm
2 x SAFT 3.6V 17500 https://es.rs-online.com/web/p/baterias ... s/4199536/
1 x Wisol Sigfox SFM10R1 https://arduino-shop.eu/arduino-platfor ... -node.html

Example:
Problems start at 19:23
Image
Image
Image

It is an example, but it happens many times

Code:
Code: Select all
#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

// Global vars
HardwareSerial Sigfox(1);
int SigfoxBits = 9600;
uint8_t sigfoxMsg[TAM_TRAMA_SIGFOX];
const int pwPin1 = 13;
long sensor1, cm;

// 20 Reads from sensor and calculate the media
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;

	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();
}
What could be happening? It happens often and I can't find the problem. Thank you very much.