ESP32 Deep sleep

I am trying to incorporate deepsleep mode in my project that uses an Esp32, temperature sensor, and a Gps sensor. When I run the code, the temperature sensor stops for the declared deep sleep time, however, the GPS sensor continues to run through the deep sleep declaration. Can someone help? Code is posted below.

#include <Wire.h>
#include <Adafruit_MLX90614.h>
#include <esp_sleep.h>
#include <TinyGPS++.h>
#include<HardwareSerial.h>
#define RXD2 26
#define TXD2 27

Adafruit_MLX90614 mlx = Adafruit_MLX90614();
TinyGPSPlus gps;

void GotoSleep(){
Serial.println(“Going to sleep…”);

esp_sleep_enable_timer_wakeup(60*1000000);
esp_deep_sleep_start();
}

void setup()
{
Serial.begin(9600);
mlx.begin();
Serial2.begin(9600, SERIAL_8N1,RXD2,TXD2);
delay(1000);

Serial.print(“Ambient = “);
Serial.print(mlx.readAmbientTempC());
Serial.print(”*C\tObject = “);
Serial.print(mlx.readObjectTempC());
Serial.println(”*C”);
Serial.print(“Ambient = “);
Serial.print(mlx.readAmbientTempF());
Serial.print(”*F\tObject = “);
Serial.print(mlx.readObjectTempF());
Serial.println(”*F”);
Serial.println();

while (Serial2.available() > 0)
if (gps.encode(Serial2.read()))
displayInfo();

if (millis() > 5000 && gps.charsProcessed() < 10)
{
Serial.println(F(“No GPS detected: check wiring.”));
while(true);
}

displayInfo();

GotoSleep();
}

void displayInfo()
{
Serial.print(F(“Location: “));
if (gps.location.isValid())
{
Serial.print(gps.location.lat(), 6);
Serial.print(F(”,”));
Serial.print(gps.location.lng(), 6);
}
else
{
Serial.print(F(“INVALID”));
}

Serial.print(F(" Date/Time: “));
if (gps.date.isValid())
{
Serial.print(gps.date.month());
Serial.print(F(”/"));
Serial.print(gps.date.day());
Serial.print(F("/"));
Serial.print(gps.date.year());
}
else
{
Serial.print(F(“INVALID”));
}

Serial.print(F(" “));
if (gps.time.isValid())
{
if (gps.time.hour() < 10) Serial.print(F(“0”));
Serial.print(gps.time.hour());
Serial.print(F(”:"));
if (gps.time.minute() < 10) Serial.print(F(“0”));
Serial.print(gps.time.minute());
Serial.print(F(":"));
if (gps.time.second() < 10) Serial.print(F(“0”));
Serial.print(gps.time.second());
Serial.print(F("."));
if (gps.time.centisecond() < 10) Serial.print(F(“0”));
Serial.print(gps.time.centisecond());
}
else
{
Serial.print(F(“INVALID”));
}

Serial.println();
}

void loop()
{

}

You’ll have to remove power to the devices when the ESP32 goes to deep sleep. During startup, enable the power to the devices, wait for a short moment, then set them up as normal. You would want to consider how long the GPS unit will take to reacquire at power up before you can use its info. During that time a component of some sort will be consuming power.

Will deenergizing the GPS unit save more power then what it will take to have a circuit that powers the GPS and draws extra current during sending power to the GPS?

I’m a bit confused by your question.

Putting the ESP32 into deep sleep will not magically put all connected devices, such as your GPS, into deep sleep as well.

Each connected device needs to be put into sleep seperatly.

Please explain the project in more detail, what its doing and in particular how often you will be putting the project into sleep and why …

I’ll try to rephrase my question.

You have a GPS device. You have an ESP32.

The GPS device does not go to sleep with code. The ESP32 does go to sleep with code.

When the ESP32 is sleeping it uses less current. The GPS does not sleep with code. You want to put the GPS to sleep right?

Then you will need to power the GPS device down when the ESP32 goes to sleep. With me so far?

To put the GPS to sleep, I am assuming you want to save on power consumption, and you want to put the GPS to sleep and the GPS does not use code to go to sleep, then you’ll want to power down the GPS, which means you’ll need to use another circuit to apply power to the GPS and remove power from the GPS. With me so far?

How long does it take your GPS to acquire a fix after being powered up? Let’s say 1 minute. lets say you are going to use a relay to power the GPS. The relay will draw additional power when the GPS is on, with me so far? The GPS will draw additional power reacquiring a fix.

The question is will the relay, when on, draw more power then if you had just left the GPS on during ESP32 sleep cycle?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.