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. Development
  3. sleep with timer and level interrupt

sleep with timer and level interrupt

Scheduled Pinned Locked Moved Development
6 Posts 4 Posters 2.7k Views 4 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.
  • eboE Offline
    eboE Offline
    ebo
    wrote on last edited by
    #1

    Hi,

    I have a question on how to use the sleep with the timer and with a level interrupt.

    I want to use a level interrupt to catch a tipping bucket
    and want to do periodic checks (battery, temperature, etc)

    I''m looking at the sleep function from mysensors, but could not find a way to catch the level interrupt when it is falling.
    also I need to do some debouncing..

    What is your advice?
    Regards,
    Edward

    sundberg84S 1 Reply Last reply
    0
    • eboE ebo

      Hi,

      I have a question on how to use the sleep with the timer and with a level interrupt.

      I want to use a level interrupt to catch a tipping bucket
      and want to do periodic checks (battery, temperature, etc)

      I''m looking at the sleep function from mysensors, but could not find a way to catch the level interrupt when it is falling.
      also I need to do some debouncing..

      What is your advice?
      Regards,
      Edward

      sundberg84S Offline
      sundberg84S Offline
      sundberg84
      Hardware Contributor
      wrote on last edited by
      #2

      @ebo - have a look at some rain sensors sketches.
      Also check https://www.mysensors.org/download/sensor_api_20#sleeping

      Controller: Proxmox VM - Home Assistant
      MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
      MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
      RFLink GW - Arduino Mega + RFLink Shield, 433mhz

      1 Reply Last reply
      2
      • eboE Offline
        eboE Offline
        ebo
        wrote on last edited by
        #3

        I did already, but none is implementing the time and the level interrupt with falling.
        could be that I'm not understanding it right... ;)

        if I use the sleep function with level interrupt I can not specify the function to run when awaking from the level interrupt.
        maybe i'm missing something?
        in my current sketch with only level interrupt I have the following:

        void enterSleep(void)
        {
        
        	/* Setup tipInterrupt as an interrupt and attach handler. */
        	attachInterrupt(tipInterrupt, awake, FALLING);
        	delay(100);
        	set_sleep_mode(SLEEP_MODE_PWR_DOWN);
        	sleep_enable();
        	sleep_mode();
        	/* The program will continue from here. */
        	sleep_disable();
        }
        
        
        void awake(void)
        {
        	detachInterrupt(tipInterrupt);
        	tipCount++;
        	attachInterrupt(tipInterrupt, tip, FALLING);
        	tipped = true;
        }
        
        

        how to convert this to mysensors sleep with a timer?
        Thanks,
        Edward

        mfalkviddM Nca78N 2 Replies Last reply
        0
        • eboE ebo

          I did already, but none is implementing the time and the level interrupt with falling.
          could be that I'm not understanding it right... ;)

          if I use the sleep function with level interrupt I can not specify the function to run when awaking from the level interrupt.
          maybe i'm missing something?
          in my current sketch with only level interrupt I have the following:

          void enterSleep(void)
          {
          
          	/* Setup tipInterrupt as an interrupt and attach handler. */
          	attachInterrupt(tipInterrupt, awake, FALLING);
          	delay(100);
          	set_sleep_mode(SLEEP_MODE_PWR_DOWN);
          	sleep_enable();
          	sleep_mode();
          	/* The program will continue from here. */
          	sleep_disable();
          }
          
          
          void awake(void)
          {
          	detachInterrupt(tipInterrupt);
          	tipCount++;
          	attachInterrupt(tipInterrupt, tip, FALLING);
          	tipped = true;
          }
          
          

          how to convert this to mysensors sleep with a timer?
          Thanks,
          Edward

          mfalkviddM Offline
          mfalkviddM Offline
          mfalkvidd
          Mod
          wrote on last edited by
          #4

          @ebo when the MySensors sleep function returns, the return value will tell you whether it woke up because of the timer or because of the external interrupt. Just use an if clause to do different things based on that return value.

          1 Reply Last reply
          0
          • eboE ebo

            I did already, but none is implementing the time and the level interrupt with falling.
            could be that I'm not understanding it right... ;)

            if I use the sleep function with level interrupt I can not specify the function to run when awaking from the level interrupt.
            maybe i'm missing something?
            in my current sketch with only level interrupt I have the following:

            void enterSleep(void)
            {
            
            	/* Setup tipInterrupt as an interrupt and attach handler. */
            	attachInterrupt(tipInterrupt, awake, FALLING);
            	delay(100);
            	set_sleep_mode(SLEEP_MODE_PWR_DOWN);
            	sleep_enable();
            	sleep_mode();
            	/* The program will continue from here. */
            	sleep_disable();
            }
            
            
            void awake(void)
            {
            	detachInterrupt(tipInterrupt);
            	tipCount++;
            	attachInterrupt(tipInterrupt, tip, FALLING);
            	tipped = true;
            }
            
            

            how to convert this to mysensors sleep with a timer?
            Thanks,
            Edward

            Nca78N Offline
            Nca78N Offline
            Nca78
            Hardware Contributor
            wrote on last edited by
            #5

            @ebo said:

            in my current sketch with only level interrupt I have the following:

            Hello, you should not use your own interrupt function, check the link sundberg84 gave you in his reply and you will see the MySensors sleep function can manage RAISING, FALLING and CHANGE level interrupts, and timer interrupt at the same time.
            It will stop your code and restart it when an interrupt is triggered, and then you just have to check the integer value that is returned to know if it's because of level interrupt 1, level interrupt 2, or timer interrupt. Then you can call your function according to the value.

            1 Reply Last reply
            1
            • eboE Offline
              eboE Offline
              ebo
              wrote on last edited by
              #6

              ok, that make things clear!
              I will give that a try.

              Thanks so far.

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


              13

              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