sleep with timer and level interrupt



  • 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


  • Hardware Contributor

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



  • 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


  • Mod

    @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.


  • Hardware Contributor

    @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.



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

    Thanks so far.


Log in to reply
 

Suggested Topics

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts