Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. General Discussion
  3. attachInterrupt and sleep()

attachInterrupt and sleep()

Scheduled Pinned Locked Moved General Discussion
10 Posts 2 Posters 2.4k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • alexsh1A Offline
    alexsh1A Offline
    alexsh1
    wrote on last edited by alexsh1
    #1

    Hi,

    Can anyone tell me if mcu wakes up if IRQ is changing in the following setup? OR do I have to use sleep(digitalPinToInterrupt(IRQ), CHANGE, SLEEP_TIME);

    void setup() {
    pinMode(IRQ, INPUT);
    attachInterrupt(digitalPinToInterrupt(IRQ), wakeup, RISING);
    ....
    }
    
    void loop {
    ...
    sleep(SLEEP_TIME);
    }
    void wakeup()
    {
    detected = true;
    }
    
    YveauxY 1 Reply Last reply
    0
    • alexsh1A alexsh1

      Hi,

      Can anyone tell me if mcu wakes up if IRQ is changing in the following setup? OR do I have to use sleep(digitalPinToInterrupt(IRQ), CHANGE, SLEEP_TIME);

      void setup() {
      pinMode(IRQ, INPUT);
      attachInterrupt(digitalPinToInterrupt(IRQ), wakeup, RISING);
      ....
      }
      
      void loop {
      ...
      sleep(SLEEP_TIME);
      }
      void wakeup()
      {
      detected = true;
      }
      
      YveauxY Offline
      YveauxY Offline
      Yveaux
      Mod
      wrote on last edited by
      #2

      @alexsh1 yes, you should preferably use the MySensors sleep() interface, unless you know exactly what you're doing.
      Furthermore, using the MySensors API will assure compatibility with future versions of the library.

      http://yveaux.blogspot.nl

      alexsh1A 1 Reply Last reply
      2
      • YveauxY Yveaux

        @alexsh1 yes, you should preferably use the MySensors sleep() interface, unless you know exactly what you're doing.
        Furthermore, using the MySensors API will assure compatibility with future versions of the library.

        alexsh1A Offline
        alexsh1A Offline
        alexsh1
        wrote on last edited by
        #3

        @yveaux Thank you|! But does attachInterrupt works with a simple sleep() from MySensors? I cannot call ISR from sleep(attachInterrupt()....)

        YveauxY 1 Reply Last reply
        0
        • alexsh1A alexsh1

          @yveaux Thank you|! But does attachInterrupt works with a simple sleep() from MySensors? I cannot call ISR from sleep(attachInterrupt()....)

          YveauxY Offline
          YveauxY Offline
          Yveaux
          Mod
          wrote on last edited by
          #4

          @alexsh1 not sure what you are trying to achieve here... Is this the same question as in the initial post?

          http://yveaux.blogspot.nl

          alexsh1A 1 Reply Last reply
          0
          • YveauxY Yveaux

            @alexsh1 not sure what you are trying to achieve here... Is this the same question as in the initial post?

            alexsh1A Offline
            alexsh1A Offline
            alexsh1
            wrote on last edited by alexsh1
            #5

            @yveaux

            I am trying to understand if there a difference on how to put a node to sleep. Please see below and compare it to my initial post.
            The node is working fine, but it seems that the sensor on IRQ is not working. This is why I am asking.

            It is sleep() + attachInterrupt vs sleep(attachInterrupt...) question

            void setup() {
            pinMode(IRQ, INPUT);
            ....
            }
            
            void loop {
            ...
            if (detected)
            ....
            sleep(attachInterrupt(digitalPinToInterrupt(IRQ), CHANGE, SLEEP_TIME);
            
            alexsh1A YveauxY 2 Replies Last reply
            0
            • alexsh1A alexsh1

              @yveaux

              I am trying to understand if there a difference on how to put a node to sleep. Please see below and compare it to my initial post.
              The node is working fine, but it seems that the sensor on IRQ is not working. This is why I am asking.

              It is sleep() + attachInterrupt vs sleep(attachInterrupt...) question

              void setup() {
              pinMode(IRQ, INPUT);
              ....
              }
              
              void loop {
              ...
              if (detected)
              ....
              sleep(attachInterrupt(digitalPinToInterrupt(IRQ), CHANGE, SLEEP_TIME);
              
              alexsh1A Offline
              alexsh1A Offline
              alexsh1
              wrote on last edited by
              #6

              @Yveaux Let me tell you want I am doing and perhaps it would be easier for you to understand. I have a node with multiple sensors. Additionally, I have a i2c lightning sensor with IRQ connected to D2 of atmega328p. The node has to wake up every 10-15 mins for send regular information from sensors AND also has to wake up every time there is an interrupt on D2.

              1 Reply Last reply
              0
              • alexsh1A alexsh1

                @yveaux

                I am trying to understand if there a difference on how to put a node to sleep. Please see below and compare it to my initial post.
                The node is working fine, but it seems that the sensor on IRQ is not working. This is why I am asking.

                It is sleep() + attachInterrupt vs sleep(attachInterrupt...) question

                void setup() {
                pinMode(IRQ, INPUT);
                ....
                }
                
                void loop {
                ...
                if (detected)
                ....
                sleep(attachInterrupt(digitalPinToInterrupt(IRQ), CHANGE, SLEEP_TIME);
                
                YveauxY Offline
                YveauxY Offline
                Yveaux
                Mod
                wrote on last edited by
                #7

                @alexsh1 said in attachInterrupt and sleep():

                sleep(attachInterrupt(digitalPinToInterrupt(IRQ), CHANGE, SLEEP_TIME);

                This is invalid, as attachInterrupt returns nothing; ref: https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/

                Just use

                int8_t cause = sleep( digitalPinToInterrupt( IRQ ), CHANGE, SLEEP_TIME );
                

                and have MySensors handle the wakeup by interrupt and sleep timeout for you.

                The cause will tell you if it woke from interrupt or because of a timeout, as described by https://www.mysensors.org/apidocs-beta/group__MySensorsCoregrp.html#ga57a5217aff45276f40018165d2fb10a1

                http://yveaux.blogspot.nl

                alexsh1A 1 Reply Last reply
                1
                • YveauxY Yveaux

                  @alexsh1 said in attachInterrupt and sleep():

                  sleep(attachInterrupt(digitalPinToInterrupt(IRQ), CHANGE, SLEEP_TIME);

                  This is invalid, as attachInterrupt returns nothing; ref: https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/

                  Just use

                  int8_t cause = sleep( digitalPinToInterrupt( IRQ ), CHANGE, SLEEP_TIME );
                  

                  and have MySensors handle the wakeup by interrupt and sleep timeout for you.

                  The cause will tell you if it woke from interrupt or because of a timeout, as described by https://www.mysensors.org/apidocs-beta/group__MySensorsCoregrp.html#ga57a5217aff45276f40018165d2fb10a1

                  alexsh1A Offline
                  alexsh1A Offline
                  alexsh1
                  wrote on last edited by
                  #8

                  @yveaux said in attachInterrupt and sleep():

                  @alexsh1 said in attachInterrupt and sleep():

                  sleep(attachInterrupt(digitalPinToInterrupt(IRQ), CHANGE, SLEEP_TIME);

                  This is invalid, as attachInterrupt returns nothing; ref: https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/

                  Thank you for spotting it - this was my mistake.
                  I meant

                  sleep(digitalPinToInterrupt(IRQ), CHANGE, SLEEP_TIME);
                  
                  1 Reply Last reply
                  0
                  • alexsh1A Offline
                    alexsh1A Offline
                    alexsh1
                    wrote on last edited by alexsh1
                    #9

                    @Yveaux this is what you mean, right?
                    I need to refactor my code a bit to try it.

                    void loop() {
                      int8_t cause = sleep( digitalPinToInterrupt( IRQ ), CHANGE, SLEEP_TIME );
                      switch (cause) {
                        case MY_WAKE_UP_BY_TIMER:
                    //Take measurements from sensor and msg to GW.  
                        break;
                           case digitalPinToInterrupt(IRQ):
                       // Lightning sensor interrupt 
                          break;
                    
                    YveauxY 1 Reply Last reply
                    0
                    • alexsh1A alexsh1

                      @Yveaux this is what you mean, right?
                      I need to refactor my code a bit to try it.

                      void loop() {
                        int8_t cause = sleep( digitalPinToInterrupt( IRQ ), CHANGE, SLEEP_TIME );
                        switch (cause) {
                          case MY_WAKE_UP_BY_TIMER:
                      //Take measurements from sensor and msg to GW.  
                          break;
                             case digitalPinToInterrupt(IRQ):
                         // Lightning sensor interrupt 
                            break;
                      
                      YveauxY Offline
                      YveauxY Offline
                      Yveaux
                      Mod
                      wrote on last edited by
                      #10

                      @alexsh1 yes, correct! :+1:

                      http://yveaux.blogspot.nl

                      1 Reply Last reply
                      1
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      12

                      Online

                      11.7k

                      Users

                      11.2k

                      Topics

                      113.1k

                      Posts


                      Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • MySensors
                      • OpenHardware.io
                      • Categories
                      • Recent
                      • Tags
                      • Popular