PuceBaboon / ESP8266-DS3231

Using a DS3231 to supply power to an ESP8266 ("no-power" deep sleep)
The Unlicense
9 stars 6 forks source link

Having trouble determining the circuit employed #1

Open bprobbins opened 5 years ago

bprobbins commented 5 years ago

Very intriguing idea you have here, but I am having no luck with figuring out the specific wiring connections as well as the correct p-channel mosfet. Could you elaborate on the hardware you used?

PuceBaboon commented 5 years ago

Hi B.P.,

I've been trying to find the original board with this circuit on it, but no luck so far (it was an ESP-03 module and that seems like such a long time ago now). Anyway, the circuit is basically very, very similar to this one:- https://hackaday.io/project/12866/gallery#c051a7ad3baecf8c373875721df75253

Ignore the large, obvious N-channel at the bottom; it's not required in the DS3231 circuit. The key part is the smaller, P-channel MOSFET Q1, just above C1. You can use this circuit pretty much as-is. You don't need R4, R5 or Q2 (the N-channel MOSFET) at all. Simply connect R3 to the SQW/INT pin of the DS3231 module instead. The P-channel MOSFET must be one with a fairly low gate switching voltage (similar, or better, than the AO3415 shown in the diagram... it's other properties aren't too important, as long as it can handle in excess of 500ma of current).

It's important to note that there needs to be a 3v3 regulator (preferably a low-quiescent current variety) between the output (marked as "PAD3" on the schematic) and the ESP8266/DS3231.

Let me know if you have any other questions about this and, in the meantime, I'll try to make some time to add a schematic to the project sometime in the not-too-distant future.

                      -John-
bprobbins commented 5 years ago

Hello John, Thank you very much, that helps quite a bit. Brian

bprobbins commented 5 years ago

Thanks to your guidance, I put together this working circuit: image

But I ran into trouble compiling your code with the rodan library, which must have changed since your code, so I tried out another DS3231 library as below and seems to work well:

#include <DS3232RTC.h>        // https://github.com/JChristensen/DS3232RTC
#include <Wire.h>
// For non-AVR boards only. Not needed for AVR boards.
DS3232RTC myRTC(false);     // tell constructor not to initialize the I2C bus.

void setup()
{
  Wire.begin(4,5);    
  pinMode(2,OUTPUT); //alive indicator
  tmElements_t tm;
  tm.Hour = 00;               // set the RTC to an arbitrary time
  tm.Minute = 00;
  tm.Second = 00;
  tm.Day = 16;
  tm.Month = 9;
  tm.Year = 2017 - 1970;      // tmElements_t.Year is the offset from 1970
  myRTC.write(tm);              // set the RTC from the tm structure

  // set Alarm 1 to occur at 5 seconds after every minute
  myRTC.setAlarm(ALM1_MATCH_SECONDS, 5, 0, 0, 0);
  // configure the INT/SQW pin for "interrupt" operation (disable square wave output)
  myRTC.squareWave(SQWAVE_NONE);
  // enable interrupt output for Alarm 1
  myRTC.alarmInterrupt(ALARM_1, true);

  //*****************************************************//
  //This is where to put code that you want to run every
  //timed reset of the ESP
  //Optionally, show that ESP8266 is alive by flashing LED.
  for (int i = 0; i < 100; i++) {
    digitalWrite(2, LOW);
    delay(50); 
    digitalWrite(2, HIGH);
    delay(50); 
  }
  //*****************************************************//

  //Finally, clear the alarm flag which causes the DS3231 INT/SQW pin to 
  //go high-z. As a result, the connected p-channel mosfet stops providing
  //power to ESP8266 and the ESP turns off, only to be reconnected to power
  //again when the DS3231 INT/SQW alarms and goes LOW one minute later
  myRTC.alarm(ALARM_1);

}//setup

void loop()
{
//NOTHING HERE 
}//loop

Thanks again

bprobbins commented 5 years ago

Actually, there is a big error in my schematic above. Sorry. Below is the correct (I think) setup: image

PuceBaboon commented 5 years ago

Excellent job, Brian. Thanks for all of your work making that available.

Your choice of P-MOSFET looks interesting, too. I just had a quick look at the data sheet; it seems just right for this application. Where are you sourcing them and what's the tens-to-fifties pricing like?

Thanks for the update to your schematic. I come from the old school (actually, "ancient school" is probably closer to the mark) where teacher insisted that you read a schematic left-to-right, just like a book, so the inputs were always on the left and the outputs on the right (this was in the days where there might be twenty sheets for a tape drive and fifty odd for a disk drive, so it made life a lot easier). Anyway, your schematic is very much appreciated, especially as I've been meaning to re-visit this project with some ESP-Now sensors to push battery life even further (with an ESP32-to-ethernet gateway to handle the MQTT interfacing).

I've already "pinned" this issue and I'll add a reference to it in the README now.

Thanks again,

                             -John-
bprobbins commented 5 years ago

Thanks for your comments. I'm a bit ancient myself, but only in age. I'm just an unschooled hobbyist looking to learn more, so thanks for the tip on schematic drawing. I purchased the DMP2045U-7 mosfets from Mouser.com for $0.29 each (10 or more). I really know nothing about mosfets, so when I saw that someone was reporting it as good to combine with a TPL5110, I decided to try it with the ds3231. Brian

1CM69 commented 5 years ago

Thanks to your guidance, I put together this working circuit: image

But I ran into trouble compiling your code with the rodan library, which must have changed since your code, so I tried out another DS3231 library as below and seems to work well:

#include <DS3232RTC.h>        // https://github.com/JChristensen/DS3232RTC
#include <Wire.h>
// For non-AVR boards only. Not needed for AVR boards.
DS3232RTC myRTC(false);     // tell constructor not to initialize the I2C bus.

void setup()
{
  Wire.begin(4,5);    
  pinMode(2,OUTPUT); //alive indicator
  tmElements_t tm;
  tm.Hour = 00;               // set the RTC to an arbitrary time
  tm.Minute = 00;
  tm.Second = 00;
  tm.Day = 16;
  tm.Month = 9;
  tm.Year = 2017 - 1970;      // tmElements_t.Year is the offset from 1970
  myRTC.write(tm);              // set the RTC from the tm structure

  // set Alarm 1 to occur at 5 seconds after every minute
  myRTC.setAlarm(ALM1_MATCH_SECONDS, 5, 0, 0, 0);
  // configure the INT/SQW pin for "interrupt" operation (disable square wave output)
  myRTC.squareWave(SQWAVE_NONE);
  // enable interrupt output for Alarm 1
  myRTC.alarmInterrupt(ALARM_1, true);

  //*****************************************************//
  //This is where to put code that you want to run every
  //timed reset of the ESP
  //Optionally, show that ESP8266 is alive by flashing LED.
  for (int i = 0; i < 100; i++) {
    digitalWrite(2, LOW);
    delay(50); 
    digitalWrite(2, HIGH);
    delay(50); 
  }
  //*****************************************************//

  //Finally, clear the alarm flag which causes the DS3231 INT/SQW pin to 
  //go high-z. As a result, the connected p-channel mosfet stops providing
  //power to ESP8266 and the ESP turns off, only to be reconnected to power
  //again when the DS3231 INT/SQW alarms and goes LOW one minute later
  myRTC.alarm(ALARM_1);

}//setup

void loop()
{
//NOTHING HERE 
}//loop

Thanks again

I had similar issues trying to compile & upload this code but I made a few alterations and it now works with the 'rodan' lib.

I inserted the missing reference: #define RTC_BUFF_SIZE 256 just below the includes

references to DS3231_INTCN had to be changed to DS3231_CONTROL_INTCN

the reference to DS3231_A2IE had to be changed to DS3231_CONTROL_A2IE

;)