How can I reset my sodaq through its button?

HEllo

I was wondering, how can I force a sw reset when I push the button of the sodaq?

I would like to create a handler for the interruption but I don’t know how to attach the interruption to it.
Any suggestions?

thanks!!

Hi,

What Sodaq do you use?

Take a look at there examples:

Regards,
Jan van Loenen
SODAQ

I use SODAQ ONE

Thanks for the link!

Hi
I didn’t manage to make a reboot when pushing the button, could you tell me what example should I look at? I have created a handler like this

void buttonPushedHandler() {

  if (digitalRead(BUTTON) == HIGH) {
    itWasPushed = true;
  }

}

and in my setup() I have something like this

  //Enabling the button for reset
  pinMode(BUTTON, INPUT_PULLUP);

but I miss the instruction to perform a reboot in my main loop where I handle the interruption of the button.
thanks indvance,

I am making use of SystemReset() in my main loop, but it seems just to freeze instead of restarting, a beter solution for the SAMD architecture?

if (itWasPushed) {
itWasPushed = false;
debugSerial.flush();
NVIC_SystemReset();//resetting the board
}

You also need to attach the interrupt to the BUTTON pin.

e.g. attachInterrupt(BUTTON, CHANGE)

Also, you have specified the pin as input pullup but you are testing for HIGH in the ISR. That will only work in CHANGE mode on the rising edge after the button is released.

@GabrielNotman

Thanks for replying,

I have change the setup a bit I have done this

pinMode(BUTTON, INPUT_PULLUP);
attachInterrupt(BUTTON, buttonPushedHandler, LOW);

my handler

void buttonPushedHandler() {

    if (digitalRead(BUTTON)) {
        itWasPushed = true;
    }   }

handling the interruption in the main loop

if (itWasPushed) {
    itWasPushed = false;
    debugSerial.flush();
    NVIC_SystemReset();//resetting the board
}

Is this solution better?

Thanks

Your ISR should look something like this:

void buttonPushedHandler() {
    itWasPushed = true;
}

Currently, you are setting the interrupt to fire when the pin reads a LOW state, but you are then checking in the ISR if the state is HIGH.

itWasPushed = false;

This is unnecessary as the value will be lost during a reset. Also I’m not sure if you need to flush the serial either.

Then I have to change the pin mode to low?

pinMode(BUTTON, INPUT);

I believe the buttoncircuit is already attached to a pull-up resistor, so using INPUT mode if fine. The pin will read HIGH when the button is not pressed.

Pressing the button grounds that circuit, at which point the pin will read LOW.

Attaching the interrupt to detect LOW is correct. You don’t need to test anything further in the ISR, simply set the flag which indicates that the interrupt was fired (i.e. itWasPushed).