-->
Page 1 of 2

ESP8266-01 Module Deep Sleep Questions

PostPosted: Sun Mar 04, 2018 9:04 pm
by hfletch
Hi all,

Im working on a simple temperature and humidity logger for monitoring my beehive. Im having a hard time figuring out why the deep sleep function is not working correctly with my project. The following is a summary of what is happening.

My circuit is as follows.

Image

I also have an external connection between the RST pin and GPIO16 on the actual ESP8266 chip

Image

My code is flashed with Adruino IDE using a USB to TTL converter. When the code boots, it connects to Wi-Fi, takes and posts a sample to ThingSpeak and enters deep sleep. However after the specified time has elapsed, the device does not successfully re-execute the code. The RST pin is high (3.3V) when in deepSleep and drops low (0V) after the RTC has counted one minute. After this happens GPIO 0 is measured to be ~1.5V with a DMM and GPIO 2 is measured to be high. I have done quite a bit of experimenting with software and circuit changes to no avail. Any thought or guidance would be very appreciated

Thank you.


Code

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <DHT.h>

#define DHTtype DHT11
DHT dht(2, DHTtype, 11);

const char* ssid = "XXXX";
const char* password = "XXXXX";

float temp,humidity;

WiFiClient client;

const int channelID = 392543;
String APIkey = "XXXXXXXXXXXXXXXX";
const char* server = "api.thingspeak.com";
const int sleepDuration = 1; //Deep Sleep Duration in minutes

void setup() {

Serial.begin(115200);
Serial.println("Serial Test"); //Test Serial Output
dht.begin();
WiFi.begin(ssid, password);
Serial.print("\n\r \n\rWorking to connect");

while (WiFi.status() != WL_CONNECTED) { //Wait for connectiom
delay(500);
Serial.print(".");
}

//Serial Output
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());

if (client.connect(server, 80)) {
delay(2000);
readDHT();//collect humidity and temperature data

// Construct API request body
String body = "field1=";
body += String(temp);
body += "&field2=";
body += String(humidity);

client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: " + APIkey + "\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(body.length());
client.print("\n\n");
client.print(body);
client.print("\n\n");

}
client.stop();
// pinMode(0, OUTPUT);
// digitalWrite(0, HIGH);
// digitalWrite(0, LOW);
Serial.println("sleeping");
delay(15000);
ESP.deepSleep(sleepDuration*60000000,WAKE_RF_DEFAULT);//Enter deep sleep, code executes from beginning on reboot
}


void loop() {

}

void readDHT(){

humidity = dht.readHumidity(); // Read humidity (percent)
temp = dht.readTemperature(0); // Read temperature as Fahrenheit
// Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(temp)) {
delay(2000);
Serial.println("Failed to read from DHT sensor");
readDHT();
}
}


Serial Output Generated


⸮Serial Test




Working to connect......Connected to Fletcher_2.4G
IP address: 192.168.50.8
Failed to read from DHT sensor
sleeping

Re: ESP8266-01 Module Deep Sleep Questions

PostPosted: Mon Mar 05, 2018 4:20 am
by jankop
On RST and GPIO0 pin put pullup resistors (to Vcc) about 10K.

Change the 3k3 resistor from GPIO0 to ground on 330R.

After serial flash restart the ESP8266.

Re: ESP8266-01 Module Deep Sleep Questions

PostPosted: Tue Mar 06, 2018 12:37 am
by hfletch
jankop,
Thank you for your suggestion. My circuit now looks like as follows

Image

After reflashing the software and resetting the board, the code was executed once and sleep mode was entered. After the elapsed time the blue led blinked once and RST was driven low, GPIO 2 stayed high while GPIO 0 was measured at 1.5 Vdc.

Must still be missing something. i have tried the same circuit with a different module to no avail.

Re: ESP8266-01 Module Deep Sleep Questions

PostPosted: Tue Mar 06, 2018 11:56 am
by jankop
What about DHT11?
51-fjA52JRL._SL1000_.jpg