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. Troubleshooting
  3. Leaving sleep() with interrupt, prevents going back to sleep() properly

Leaving sleep() with interrupt, prevents going back to sleep() properly

Scheduled Pinned Locked Moved Troubleshooting
8 Posts 2 Posters 2.4k Views 2 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.
  • EfflonE Offline
    EfflonE Offline
    Efflon
    wrote on last edited by
    #1

    I'm trying building a sensor using the standard motion sketch but are having some issues.

    1. After waking up from sleep without any interrupts triggering, sleep is entered and immediately exited. In the next loop, sleep is entered correctly.
    2. The wake-up seems to trigger the PIR or at least do something with the interrupt pin after sleep. The sensor is modded to only send a very short output.

    In the sketch I have added some debug prints where each loop() starts with a "---->" and then 5 reads of the tripped state with a delay(100) in-between. I have also commented out the send() part for a less verbose log.
    In the log bellow the sensor is coming out of a 30s sleep with no interrupts triggering. The sensor seems to trigger after 100ms and then resumes to un-triggered and the node goes to sleep to immediately wake up. Then it goes back to sleep as it should...
    My main concern is the instant wake-up after sleep since I have seen it in my fire alarm hack. Is it a MYS bug or something with my mini-pros?
    [MYS 2.1.1, Arduino 1.8.1]

    ...
    Tripped: 0
    13207 MCO:SLP:MS=30000,SMS=0,I1=1,M1=3,I2=255,M2=255
    13213 MCO:SLP:TPD
    13217 MCO:SLP:WUP=-1
    --->
    Tripped: 0
    Tripped: 1
    Tripped: 1
    Tripped: 1
    Tripped: 1
    --->
    Tripped: 1
    Tripped: 0
    Tripped: 0
    Tripped: 0
    Tripped: 0
    14024 MCO:SLP:MS=30000,SMS=0,I1=1,M1=3,I2=255,M2=255
    14032 MCO:SLP:TPD
    14034 MCO:SLP:WUP=1
    --->
    Tripped: 0
    Tripped: 0
    Tripped: 0
    Tripped: 0
    Tripped: 0
    14440 MCO:SLP:MS=30000,SMS=0,I1=1,M1=3,I2=255,M2=255
    14446 MCO:SLP:TPD
    --->
    Tripped: 0
    ...
    
    YveauxY 1 Reply Last reply
    0
    • EfflonE Efflon

      I'm trying building a sensor using the standard motion sketch but are having some issues.

      1. After waking up from sleep without any interrupts triggering, sleep is entered and immediately exited. In the next loop, sleep is entered correctly.
      2. The wake-up seems to trigger the PIR or at least do something with the interrupt pin after sleep. The sensor is modded to only send a very short output.

      In the sketch I have added some debug prints where each loop() starts with a "---->" and then 5 reads of the tripped state with a delay(100) in-between. I have also commented out the send() part for a less verbose log.
      In the log bellow the sensor is coming out of a 30s sleep with no interrupts triggering. The sensor seems to trigger after 100ms and then resumes to un-triggered and the node goes to sleep to immediately wake up. Then it goes back to sleep as it should...
      My main concern is the instant wake-up after sleep since I have seen it in my fire alarm hack. Is it a MYS bug or something with my mini-pros?
      [MYS 2.1.1, Arduino 1.8.1]

      ...
      Tripped: 0
      13207 MCO:SLP:MS=30000,SMS=0,I1=1,M1=3,I2=255,M2=255
      13213 MCO:SLP:TPD
      13217 MCO:SLP:WUP=-1
      --->
      Tripped: 0
      Tripped: 1
      Tripped: 1
      Tripped: 1
      Tripped: 1
      --->
      Tripped: 1
      Tripped: 0
      Tripped: 0
      Tripped: 0
      Tripped: 0
      14024 MCO:SLP:MS=30000,SMS=0,I1=1,M1=3,I2=255,M2=255
      14032 MCO:SLP:TPD
      14034 MCO:SLP:WUP=1
      --->
      Tripped: 0
      Tripped: 0
      Tripped: 0
      Tripped: 0
      Tripped: 0
      14440 MCO:SLP:MS=30000,SMS=0,I1=1,M1=3,I2=255,M2=255
      14446 MCO:SLP:TPD
      --->
      Tripped: 0
      ...
      
      YveauxY Offline
      YveauxY Offline
      Yveaux
      Mod
      wrote on last edited by
      #2

      @Efflon Cheap PIR sensors sometimes trigger just by fluctiations on the power supply. Waking the MCU or sending a wireless message can be enough to create a false trigger...
      You could try powering your sensor directly from a pair of AA batteries (no step-up/-down converter) and see if things improve.

      http://yveaux.blogspot.nl

      EfflonE 2 Replies Last reply
      0
      • YveauxY Yveaux

        @Efflon Cheap PIR sensors sometimes trigger just by fluctiations on the power supply. Waking the MCU or sending a wireless message can be enough to create a false trigger...
        You could try powering your sensor directly from a pair of AA batteries (no step-up/-down converter) and see if things improve.

        EfflonE Offline
        EfflonE Offline
        Efflon
        wrote on last edited by
        #3

        @Yveaux Great tip but in this case I have tried the PIR with "plain" arduino code and with mysensors. To explain even better, this is the only change I have introduced compared to the online example:

        void loop()
        {
            // Read digital motion value
            bool tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
        
            Serial.print("tripped: ");
            Serial.println(tripped);
            //send(msg.set(tripped?"1":"0"));  // Send tripped value to gw
            
            // Sleep until interrupt comes in on motion sensor. Send update every two minute.
            sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), RISING, SLEEP_TIME);
        }
        

        Sleep is triggeered by RISING since change triggers both in up and down of the sensor. The log is like this when no trigger occurs:

        4950 TSF:MSG:READ,0-0-2,s=255,c=3,t=27,pt=1,l=1,sg=0:1
        4956 MCO:PIM:NODE REG=1
        4960 MCO:BGN:STP
        4962 MCO:BGN:INIT OK,TSP=1
        tripped: 0
        4964 MCO:SLP:MS=30000,SMS=0,I1=1,M1=3,I2=255,M2=255
        4970 MCO:SLP:TPD
        4972 MCO:SLP:WUP=1
        tripped: 1
        4974 MCO:SLP:MS=30000,SMS=0,I1=1,M1=3,I2=255,M2=255
        4980 MCO:SLP:TPD
        # Here it actually sleeps 30s
        4982 MCO:SLP:WUP=-1
        tripped: 0
        4984 MCO:SLP:MS=30000,SMS=0,I1=1,M1=3,I2=255,M2=255
        4990 MCO:SLP:TPD
        4993 MCO:SLP:WUP=1
        tripped: 1
        4995 MCO:SLP:MS=30000,SMS=0,I1=1,M1=3,I2=255,M2=255
        5001 MCO:SLP:TPD 
        # Here it actually sleeps 30s
        

        So after a long sleep it wakes up, then enters sleep and interrupt is somehow triggered and the pinout reads triggeered. The next long sleep is the same..
        If i add a pulldown resistor from 3 to GND and disconnects the sensor pin after a -1 (wakeup) it enters sleep properly. I'm a complete n00b in electronics but to me it seems like some sort of signal bouncing after wakup. Then sensor is powered by vcc...

        YveauxY 1 Reply Last reply
        0
        • EfflonE Efflon

          @Yveaux Great tip but in this case I have tried the PIR with "plain" arduino code and with mysensors. To explain even better, this is the only change I have introduced compared to the online example:

          void loop()
          {
              // Read digital motion value
              bool tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
          
              Serial.print("tripped: ");
              Serial.println(tripped);
              //send(msg.set(tripped?"1":"0"));  // Send tripped value to gw
              
              // Sleep until interrupt comes in on motion sensor. Send update every two minute.
              sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), RISING, SLEEP_TIME);
          }
          

          Sleep is triggeered by RISING since change triggers both in up and down of the sensor. The log is like this when no trigger occurs:

          4950 TSF:MSG:READ,0-0-2,s=255,c=3,t=27,pt=1,l=1,sg=0:1
          4956 MCO:PIM:NODE REG=1
          4960 MCO:BGN:STP
          4962 MCO:BGN:INIT OK,TSP=1
          tripped: 0
          4964 MCO:SLP:MS=30000,SMS=0,I1=1,M1=3,I2=255,M2=255
          4970 MCO:SLP:TPD
          4972 MCO:SLP:WUP=1
          tripped: 1
          4974 MCO:SLP:MS=30000,SMS=0,I1=1,M1=3,I2=255,M2=255
          4980 MCO:SLP:TPD
          # Here it actually sleeps 30s
          4982 MCO:SLP:WUP=-1
          tripped: 0
          4984 MCO:SLP:MS=30000,SMS=0,I1=1,M1=3,I2=255,M2=255
          4990 MCO:SLP:TPD
          4993 MCO:SLP:WUP=1
          tripped: 1
          4995 MCO:SLP:MS=30000,SMS=0,I1=1,M1=3,I2=255,M2=255
          5001 MCO:SLP:TPD 
          # Here it actually sleeps 30s
          

          So after a long sleep it wakes up, then enters sleep and interrupt is somehow triggered and the pinout reads triggeered. The next long sleep is the same..
          If i add a pulldown resistor from 3 to GND and disconnects the sensor pin after a -1 (wakeup) it enters sleep properly. I'm a complete n00b in electronics but to me it seems like some sort of signal bouncing after wakup. Then sensor is powered by vcc...

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

          @Efflon pir trigger won't bounce. mechanical switches typically do.
          The sleep() function returns a boolean, telling you if the sensor woke by trigger or timeout. You could use that info instead of reading it yourself and maybe introduce some delay (e. G. 10 sconds) to have a dead time before going to sleep again.

          http://yveaux.blogspot.nl

          EfflonE 1 Reply Last reply
          0
          • YveauxY Yveaux

            @Efflon pir trigger won't bounce. mechanical switches typically do.
            The sleep() function returns a boolean, telling you if the sensor woke by trigger or timeout. You could use that info instead of reading it yourself and maybe introduce some delay (e. G. 10 sconds) to have a dead time before going to sleep again.

            EfflonE Offline
            EfflonE Offline
            Efflon
            wrote on last edited by
            #5

            @Yveaux Introducing a delay() causes the interrupt to to be triggered immediately with a triggered:0 , with a wait() same thing except triggered: 1 . Super strange imho...

            1 Reply Last reply
            0
            • YveauxY Yveaux

              @Efflon Cheap PIR sensors sometimes trigger just by fluctiations on the power supply. Waking the MCU or sending a wireless message can be enough to create a false trigger...
              You could try powering your sensor directly from a pair of AA batteries (no step-up/-down converter) and see if things improve.

              EfflonE Offline
              EfflonE Offline
              Efflon
              wrote on last edited by
              #6

              @Yveaux I finally did what you said. I powered the sensor by it self and have just GND and input connected. Now I don't get a false trigger after a sleep! Is there anything I could do to prevent this, a capacitor or something?

              After a trigger, it seems impossible to enter sleep no matter how long I delay etc. It always takes one sleep() with a immediate wake up before going to sleep. Is there someway to clear the interrupt flag?

              YveauxY 1 Reply Last reply
              0
              • EfflonE Efflon

                @Yveaux I finally did what you said. I powered the sensor by it self and have just GND and input connected. Now I don't get a false trigger after a sleep! Is there anything I could do to prevent this, a capacitor or something?

                After a trigger, it seems impossible to enter sleep no matter how long I delay etc. It always takes one sleep() with a immediate wake up before going to sleep. Is there someway to clear the interrupt flag?

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

                @Efflon what mysensors version do you use? There are some fixes in this area for 2.1.0

                http://yveaux.blogspot.nl

                EfflonE 1 Reply Last reply
                0
                • YveauxY Yveaux

                  @Efflon what mysensors version do you use? There are some fixes in this area for 2.1.0

                  EfflonE Offline
                  EfflonE Offline
                  Efflon
                  wrote on last edited by
                  #8

                  @Yveaux I'm using the latest 2.1.1 . The retriggering is possible to handle in the code and all seems possible to run on batteries so I am happy.

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


                  17

                  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