SPRESENSE It's hard to put them to sleep (arduino)

Asked 2 years ago, Updated 2 years ago, 290 views

Normally, I put SPRESENSE in a sleep state and try to get up with a tap switch (buttonPower).
In the sketch setup, there are the following steps, and if the button changes, you will reach a routine (read_button) that determines whether you want to click or press long.
attachInterrupt (buttonPower, read_button, CHANGE);
Read_Button is trying to create logic that changes the environment variable by clicking/pressing long, and that if you press long in the loop of the sketch, you sleep, and if you click, you wake up.
LowPower.coldSleep();
They will do cold sleep for now, but the reason for reboot is that buttonPower is pressed.I tried many things, such as trying Serial.flush() or attachInterrupt again, but I couldn't put them to sleep well.
  LowPower.disableBootCause (buttonPower);
If you do something like that, it will be ruined.

Can someone give me some advice?

spresense

2022-09-30 21:49

1 Answers

I don't know how to detect button clicks/push and press/release, but
Since the mode of attachInterrupt() is CHANGE, is it possible to enter Cold Sleep by pressing long press and wake up after detecting the change when released?If the source code is attached, I may be able to give you more specific advice.

This is a simple implementation, but if the press time is more than 3 seconds, I think it will be possible to enter Cold Sleep and wait until Button is released before entering Cold Sleep.For your information.

#include<LowPower.h>

uint8_t buttonPower=PIN_D33;
unsigned long long pressTime = 0;

void read_button()
{
  if(LOW==digitalRead(buttonPower)){
    pressTime=millis();//pushed
  } else{
    pressTime = 0;// released
  }
}

void setup()
{
  Serial.begin (115200);

  Serial.println("Power ON";
  ledOn (LED 0);

  LowPower.begin();

  pinMode (buttonPower, INPUT_PULLUP);
  attachInterrupt(buttonPower, read_button, CHANGE);
}

void loop()
{
  unsigned long long currentTime;
  unsigned long diffTime;

  currentTime = millis();

  if(LOW==digitalRead(buttonPower)){
    diffTime = currentTime-pressTime;//pushed
  } else{
    diffTime = 0;// released
  }

  if((pressTime!=0)&(diffTime>3000)){
    Serial.println("Power Off";
    ledOff (LED 0);
    while (LOW==digitalRead (buttonPower));
    LowPower.coldSleep();
  }
}


2022-09-30 21:49

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.