Boron Sleep Mode

Hi All,

i am trying to use sleep mode function to my code, but seems it doesn’t like my code, it flashing Magenta after sending data instead of going sleep.
i want to make the boron to sleep for 10 min then wake send me the signal then back,
can you please check if i miss something here in the code below? it used to work perfect on particle electron

const uint32_t msSAMPLE_INTERVAL = 2500;
const uint32_t msMETRIC_PUBLISH  = 5000;

uint32_t msLastMetric;
uint32_t msLastSample;

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  Wire.begin(); 
  pinMode(pump_pin, OUTPUT);
}

void loop {
  float duration, inches, cm;

  // The sensor is triggered by a HIGH pulse of 10 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(trigPin, OUTPUT);
  digitalWrite(trigPin, LOW);

  delayMicroseconds(10);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(15);
  digitalWrite(trigPin, LOW);

  // Read the signal from the sensor: a HIGH pulse whose
  // duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(echoPin, INPUT);
  duration = pulseIn(echoPin, HIGH);

  // convert the time into a distance
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);
  xx= cm;
  Serial.print(inches);
  Serial.print("in, ");
  Serial.print("\t");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
 
 /////////////////////////////////////////////////////////////////
  
  samples.add(xx);
  float l = samples.getLowest();
  float m = samples.getMedian();
  float a = samples.getAverage();
  float h = samples.getHighest();
    
 // lowest =l;
  average = a;
  median = m;
 //////////////////////////////////////////////////////////////
   
  if (millis() - msLastMetric >= msMETRIC_PUBLISH){
    pumpactivator();
    System.sleep(SLEEP_MODE_DEEP,600); 
  }
}

Apart from the suggestions you got about a month ago in another thread but haven't applied yet

You may want to have a look at the docs

Where it states

And at the top of the "classic sleep" reference you also see a link to the modern way of doing it.

We also cannot see what pumpactivator() does, so this might also contribute to your issue.

3 Likes

Thanks a lot, I’ve changed the pinMode() , also the sleeping Mode is working after i added this to the code :

SystemSleepConfiguration config;
config.mode(SystemSleepMode::STOP)
.gpio(WKP, RISING)
.duration(10min);
System.sleep(config);

1 Like

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