Author Topic: Deep Sleep usage  (Read 5300 times)

who

  • Newbie
  • *
  • Posts: 12
Deep Sleep usage
« on: March 22, 2016, 08:22:49 am »
Hi,

I want to use the DeepSleep function of the Oak for testing purpose in the Start Example:
Code: [Select]
void setup() {               
  pinMode(1, OUTPUT);
}

void loop() {
  digitalWrite(1, HIGH);
  delay(1000);             
  digitalWrite(1, LOW);
  delay(1000);             
}

I have seen the example code in the wiki, but this implementation is not working for me.
Best wishes

exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: Deep Sleep usage
« Reply #1 on: March 22, 2016, 09:50:20 am »
Try this... Be sure to connect WAKE to RST on the Oak. Also pin 5 is set pinMode(5, INPUT_PULLUP) as way to control whether you want it to sleep or not.

Hopefully the code comments are sufficient to explain. This is the essence of the code I created for sketches that deep sleep.

Code: [Select]
/*
  Digistump Oak deep sleep example
 
  Requires:
   * Particle.io account
   * Digistump Oak with current firmware and active on particle.io
  Does:
   * Support sleep and non-sleep modes
   * Publishes events and data to particle.io
   * Enters deep sleep when Sleep_pin = HIGH (set INPUT_PULLUP)
   * Watches Sleep_pin to determine whether or not to go into deep sleep.
     HIGH = sleep, At wakeup resets and runs setup() again and does not enter loop()
     LOW  = enters Loop() and non sleep mode
     
     NOTE: Non sleep mode will allow for new sketch uploads
*/

/* 
 *   WARNING: Pin 10 (WAKE) must be connected to the reset pin (RST) for wakeup to occur
 */

int Sleep_pin = 5;   // (Configure as INPUT_PULLUP to default HIGH)
int OakLEDpin = 1;   // Oak onboard LED pin 1
int sleepTimeS = 30; // 30 seconds - adjust a needed

void setup(void) {
  pinMode(Sleep_pin, INPUT_PULLUP); // Use pullup mode to default HIGH
  pinMode(OakLEDpin, OUTPUT);
  digitalWrite(OakLEDpin,HIGH); // Turn on onboard LED
 
  Particle.publish("Oak Setup", "Started", 60, PRIVATE);

  // Put your code here to do  work like read a value or set a pin
  Particle.publish("Oak Setup", "Working", 60, PRIVATE);
   
  Particle.publish("Oak Setup", "Complete", 60, PRIVATE);
 
  delay(2000); // Long pluse stretch onboard LED for visual effect
  digitalWrite(OakLEDpin,LOW);

  // Check to see if sleep mode selected
  if (digitalRead(Sleep_pin) == HIGH) {
     Particle.publish("Oak Setup", "Entering Deep Sleep", 60, PRIVATE);
     ESP.deepSleep(sleepTimeS*1000000, WAKE_RF_DEFAULT); // Sleep
  }
  else {
     Particle.publish("Oak Setup","Entering Non Sleep Mode",60,PRIVATE);
  }
} //END setup()

void loop(void) {

  // We are here because Non Sleep Mode has been selected.
  // Will remain in loop() until reset or power cycle occurs.

  digitalWrite(OakLEDpin,HIGH); // Turn on onboard LED
     
  Particle.publish("Oak Loop", "Working", 60, PRIVATE);
  // Put your code here to do work like read a value or set a pin
 
  delay(500); // Short pluse stretch onboard LED for visual effect
  digitalWrite(OakLEDpin,LOW); // Turn off onboard LED

  // Delay - don't flood Particle.io
  for(int i=0; i<sleepTimeS; i++) {
     delay(1000); // This delay * sleepTimeS slows updates to particle.io log
  }
} //END loop()
« Last Edit: March 22, 2016, 09:59:27 am by exeng »

who

  • Newbie
  • *
  • Posts: 12
Re: Deep Sleep usage
« Reply #2 on: March 23, 2016, 07:46:14 am »
Thank you for the code!

Am I right, that I don't need any code in the loop function? So I can call my functions (read and write something) between the "Started" and "Working"?

Edit: in deep sleep mode, is fetching the variable with Particle cloud possible? Without the deep sleep mode I am fetching the variables set on my Oak with a Python script, should this work also?

Edit2: is it possible, that when the Oak is in the sleed modus, flashing is quite hard?
« Last Edit: March 23, 2016, 09:32:45 am by who »

exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: Deep Sleep usage
« Reply #3 on: March 23, 2016, 10:30:56 am »
You don't need and code in loop. You can remove the code that determines whether to sleep or not, and just use the pin 1 to GND method to enter safe mode when you want to upload a new sketch.

Haven't tried fetching variables with Particle Cloud. I have only used publish.

"flashing"...if you mean uploading sketches while in sleep mode, just connect the pin 1 to GND (for a few seconds) at power cycle to put the Oak in safe mode.

who

  • Newbie
  • *
  • Posts: 12
Re: Deep Sleep usage
« Reply #4 on: March 23, 2016, 12:39:02 pm »
Thanks for the tip with Pin1!
I have to use publish instead of variable, because the variables are not stored in the particle cloud

who

  • Newbie
  • *
  • Posts: 12
Re: Deep Sleep usage
« Reply #5 on: March 24, 2016, 09:33:56 am »
I have read, that we could disable the LED to save power. Erik said, that this is done by cutting the solder bridge - but in my case, the SJ LED_EN is not bridged. So how to disable the LED?

exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: Deep Sleep usage
« Reply #6 on: March 24, 2016, 12:36:23 pm »
Are you sure there is not a fine trace across the LED_EN jumper?

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Deep Sleep usage
« Reply #7 on: March 24, 2016, 10:52:06 pm »
It isn't a solder bridge per say, but a trace on the circuit board. use a scalpel, box cutter or other sharp instrument to score between the two copper pads for 'LED EN' to cut the trace. And if you want to use the LED again, you can just solder the pads to re-join it.