Wait function with interrupt



  • Hello everybody,

    Why there is no function wait() with interrupt like sleep(const uint8_t interrupt, const uint8_t mode, const uint32_t sleepingMS = 0, const bool smartSleep = false) ?

    I can't use sleep because it's a repeater noed.
    Should i use basic interrupt function of arduino ?

    Thank you for your help.


  • Mod

    @snyfir said in Wait function with interrupt:

    Should i use basic interrupt function of arduino ?

    Yes

    MySensors handles interrupts during sleep only to be able to wake up again.
    During wait the node stays awake and can use the regular interrupt mechanism.



  • I have in the setup() function:

    attachInterrupt(digitalPinToInterrupt(3), keyboardInterrupt, FALLING);
    

    and in the loop() function:

    wait(60000)
    

    The function keyboardInterrupt() is being call when the pin 3 is set to ground but the wait(60000) is not exit. Or i want the programme to sleep (but still receive mesage) until an interrupt append in the pin 3.

    How can i do that ?


  • Mod

    @snyfir there are many ways to do it, maybe the easiest is something like this: in keyboardInterrupt, set a global variable to true, like this:
    interruptOccurred=true

    Change your wait line to something like this:

    for (uint16_t counter=0; counter++;counter<600&&interruptOccurred==false) {
      wait(100);
    }
    if (interruptOccurred) {
      interruptOccurred = false;
      // Do whatever should happen on interrupt here
      ...
    }
    
    


  • @mfalkvidd i am so surprised there is no function in MySensors to put arduino to sleep without disable receipt function of the NRF24L01+ module.

    Before using MySensors i was using Mirf library. I was able to put arduino to sleep and when a new message arrived, with the IRQ pin and interruption it wake up the arduino to deal with the new message arrived.

    It seems not possible to do that with MySensors library.


  • Mod

    @snyfir the radio uses so much power in listening mode that sleeping the mcu will not help much. To get low power, the radio must be turned off.


Log in to reply
 

Suggested Topics

  • 1
  • 3
  • 2
  • 3
  • 6
  • 5

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts