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. Using Sensebender gateway MYSX_D3_INT Interrupts

Using Sensebender gateway MYSX_D3_INT Interrupts

Scheduled Pinned Locked Moved Troubleshooting
14 Posts 4 Posters 708 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.
  • D Didou

    @didou I have also noticed that in the MyHwSAMD.cpp there are some functions like hwSleep(....) that are in "ToDo" state. Is that related ?

    tbowmoT Offline
    tbowmoT Offline
    tbowmo
    Admin
    wrote on last edited by
    #3

    @didou

    I sort of decided that a GW never has to sleep, as it is usually connected to a good powersource (usb, wallplug etc), so we do not need to conserve power by going into sleep..

    D 1 Reply Last reply
    2
    • scalzS Offline
      scalzS Offline
      scalz
      Hardware Contributor
      wrote on last edited by scalz
      #4

      Hello,

      • if you're planning to use it as a gateway, then don't use sleep function else it will miss messages..it won't wake up on receive like you said.

      • as you noticed sleep is not implemented for SAMD mcus, like sensebendergw

      • mapping of SAMD does not work like well known avr8 328p for example. Did you use digitalPinToInterrupt ?
        https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/
        like attachInterrupt(digitalPinToInterrupt(3), myisr, CHANGE ) for your "D3.

      D 1 Reply Last reply
      1
      • tbowmoT tbowmo

        @didou

        I sort of decided that a GW never has to sleep, as it is usually connected to a good powersource (usb, wallplug etc), so we do not need to conserve power by going into sleep..

        D Offline
        D Offline
        Didou
        wrote on last edited by
        #5

        @tbowmo I have seen that no issue but it still should be able to catch interrupt when in wait state ?

        mfalkviddM 1 Reply Last reply
        0
        • D Didou

          @tbowmo I have seen that no issue but it still should be able to catch interrupt when in wait state ?

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

          @didou could you clarify what you mean by "wait state"?

          1 Reply Last reply
          0
          • scalzS scalz

            Hello,

            • if you're planning to use it as a gateway, then don't use sleep function else it will miss messages..it won't wake up on receive like you said.

            • as you noticed sleep is not implemented for SAMD mcus, like sensebendergw

            • mapping of SAMD does not work like well known avr8 328p for example. Did you use digitalPinToInterrupt ?
              https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/
              like attachInterrupt(digitalPinToInterrupt(3), myisr, CHANGE ) for your "D3.

            D Offline
            D Offline
            Didou
            wrote on last edited by
            #7

            @scalz Yes I did try even with something different as CHANGE like FALLING

            But seems I was tracking the debug message :white_frowning_face: which it is never displayed in that case !
            But the Serial message is sent (0;255;3;0;5;1)

            It is working only one time after a GW reset, further test do not fire up the interruption

            loop()
            {
            attachInterrupt(digitalPinToInterrupt(MYSX_D4_INT), myInterrupt , FALLING);
            wait(60*1000); // Wait one minute between each probe (60 * 1000)
            }

            void myInterrupt()
            {
            detachInterrupt(digitalPinToInterrupt(MYSX_D4_INT));
            #ifdef MY_DEBUG
            Serial.println("Motion Interrupt");
            #endif
            send(MotionMsg.set("1"));
            attachInterrupt(digitalPinToInterrupt(MYSX_D4_INT), myInterrupt , FALLING);
            }

            D 1 Reply Last reply
            0
            • D Didou

              @scalz Yes I did try even with something different as CHANGE like FALLING

              But seems I was tracking the debug message :white_frowning_face: which it is never displayed in that case !
              But the Serial message is sent (0;255;3;0;5;1)

              It is working only one time after a GW reset, further test do not fire up the interruption

              loop()
              {
              attachInterrupt(digitalPinToInterrupt(MYSX_D4_INT), myInterrupt , FALLING);
              wait(60*1000); // Wait one minute between each probe (60 * 1000)
              }

              void myInterrupt()
              {
              detachInterrupt(digitalPinToInterrupt(MYSX_D4_INT));
              #ifdef MY_DEBUG
              Serial.println("Motion Interrupt");
              #endif
              send(MotionMsg.set("1"));
              attachInterrupt(digitalPinToInterrupt(MYSX_D4_INT), myInterrupt , FALLING);
              }

              D Offline
              D Offline
              Didou
              wrote on last edited by
              #8

              @didou I have also noticed thta I have to wait for a (0;255;3;0;5;0) reset message to be able to capture a new interrupt. I do not send it I guess it is sent by the core ?

              D 1 Reply Last reply
              0
              • D Didou

                @didou I have also noticed thta I have to wait for a (0;255;3;0;5;0) reset message to be able to capture a new interrupt. I do not send it I guess it is sent by the core ?

                D Offline
                D Offline
                Didou
                wrote on last edited by
                #9

                @didou It is reset after 2 minutes then I can send a new interrupt. Where does come from the 120 sec hold time ?

                1 Reply Last reply
                0
                • scalzS Offline
                  scalzS Offline
                  scalz
                  Hardware Contributor
                  wrote on last edited by scalz
                  #10

                  seems arduino learning related ;)

                  you mentioned sleep in your first post, and I think wait might delay your irq processing too

                  • is it your full loop() function ? if so, why do you place attachinterrupt inside of it? looks weird, it would be better in setup for instance
                  • "ok" for debug but serial.print in isr is bad.. ideally, it's better to trigger a boolean (volatile) and process its value in loop() . Same for sending msg from isr, not good..
                  • are you saying that you get one interrupt at least? which would mean the attachinterrupt(digitalpintointerrupt...) mapping is working, and your sketch logic is wrong (like above mentioned points)

                  just in case, in theory (no time for testing), D3=PA05(gpio name under the hood)=IRQNUM is 5 so you could replace the digitalTointerrupt function by the irq mapping name; 5 for D3, or 7 for D4.

                  so just as an example, revamping your example, the logic should look something like this

                  volatile bool myIsrTriggerVar = false
                  
                  setup() {
                  	attachInterrupt(digitalPinToInterrupt(MYSX_D4_INT), myInterrupt , FALLING); // means attachInterrupt(7, myInterrupt , FALLING);	
                  }
                  
                  loop() {	
                  	if (myIsrTriggerVar) {
                  		// process your irq here
                  		#ifdef MY_DEBUG
                  		Serial.println("Motion Interrupt");
                  		#endif
                  		send(MotionMsg.set("1"));
                  		
                  		// reset flag
                  		myIsrTriggerVar = false
                  	}
                  	
                  	// wait(60*1000); // Wait one minute between each probe (60 * 1000)
                  }
                  
                  void myInterrupt()
                  {
                  	detachInterrupt(digitalPinToInterrupt(MYSX_D4_INT));
                  	myIsrTriggerVar = true
                  	attachInterrupt(digitalPinToInterrupt(MYSX_D4_INT), myInterrupt , FALLING);
                  }
                  
                  D 1 Reply Last reply
                  1
                  • scalzS scalz

                    seems arduino learning related ;)

                    you mentioned sleep in your first post, and I think wait might delay your irq processing too

                    • is it your full loop() function ? if so, why do you place attachinterrupt inside of it? looks weird, it would be better in setup for instance
                    • "ok" for debug but serial.print in isr is bad.. ideally, it's better to trigger a boolean (volatile) and process its value in loop() . Same for sending msg from isr, not good..
                    • are you saying that you get one interrupt at least? which would mean the attachinterrupt(digitalpintointerrupt...) mapping is working, and your sketch logic is wrong (like above mentioned points)

                    just in case, in theory (no time for testing), D3=PA05(gpio name under the hood)=IRQNUM is 5 so you could replace the digitalTointerrupt function by the irq mapping name; 5 for D3, or 7 for D4.

                    so just as an example, revamping your example, the logic should look something like this

                    volatile bool myIsrTriggerVar = false
                    
                    setup() {
                    	attachInterrupt(digitalPinToInterrupt(MYSX_D4_INT), myInterrupt , FALLING); // means attachInterrupt(7, myInterrupt , FALLING);	
                    }
                    
                    loop() {	
                    	if (myIsrTriggerVar) {
                    		// process your irq here
                    		#ifdef MY_DEBUG
                    		Serial.println("Motion Interrupt");
                    		#endif
                    		send(MotionMsg.set("1"));
                    		
                    		// reset flag
                    		myIsrTriggerVar = false
                    	}
                    	
                    	// wait(60*1000); // Wait one minute between each probe (60 * 1000)
                    }
                    
                    void myInterrupt()
                    {
                    	detachInterrupt(digitalPinToInterrupt(MYSX_D4_INT));
                    	myIsrTriggerVar = true
                    	attachInterrupt(digitalPinToInterrupt(MYSX_D4_INT), myInterrupt , FALLING);
                    }
                    
                    D Offline
                    D Offline
                    Didou
                    wrote on last edited by
                    #11

                    @scalz Great help yes I get one at least but need to wait 120 sec to get an other one ?

                    Agree for the attachInterrupt in setup

                    My loop does also have few sensors read every minutes so I need to both wait for one minute and also been able to catch interrupts

                    scalzS 1 Reply Last reply
                    0
                    • D Didou

                      @scalz Great help yes I get one at least but need to wait 120 sec to get an other one ?

                      Agree for the attachInterrupt in setup

                      My loop does also have few sensors read every minutes so I need to both wait for one minute and also been able to catch interrupts

                      scalzS Offline
                      scalzS Offline
                      scalz
                      Hardware Contributor
                      wrote on last edited by scalz
                      #12

                      @didou
                      then check your sensors in an async way, far better than using wait.
                      there are different way of writing this, but here an example, maybe easier to read when new to programming : https://www.arduino.cc/en/tutorial/BlinkWithoutDelay
                      In this example, instead of toggling leds, process your sensors.
                      Also, maybe start simple, like a sketch processing your sensors as you wish, then once it's working well, add MySensors lib

                      D 1 Reply Last reply
                      0
                      • scalzS scalz

                        @didou
                        then check your sensors in an async way, far better than using wait.
                        there are different way of writing this, but here an example, maybe easier to read when new to programming : https://www.arduino.cc/en/tutorial/BlinkWithoutDelay
                        In this example, instead of toggling leds, process your sensors.
                        Also, maybe start simple, like a sketch processing your sensors as you wish, then once it's working well, add MySensors lib

                        D Offline
                        D Offline
                        Didou
                        wrote on last edited by
                        #13

                        @scalz will try that as proposed ovoiding wait and let you know. Thanks again.

                        D 1 Reply Last reply
                        0
                        • D Didou

                          @scalz will try that as proposed ovoiding wait and let you know. Thanks again.

                          D Offline
                          D Offline
                          Didou
                          wrote on last edited by
                          #14

                          @didou Tryed it today with no luck.

                          The behavior is globally simillar

                          loop()
                          {
                          unsigned long currentMillis = millis();

                          // Check Sensors global timer
                          if (currentMillis - previousMillis >= intervalMillis)
                          {
                          previousMillis = currentMillis;
                          readSensors();
                          }

                          // Check Triggers
                          if (myIsrTriggerVar1)
                          {
                          #ifdef MY_DEBUG
                          Serial.println("Motion Interrupt");
                          #endif
                          send(MotionMsg.set("1"));
                          // reset flag
                          myIsrTriggerVar1 = false;
                          }
                          }

                          I got the interrupt then mysensor message -> 13:13:07.719 -> 0;255;3;0;5;1 (Motion/V_trigger -> 1)
                          Then I have to wait for 120 seconds before being able to do an other interrup
                          Not before I have this message 13:15:07.621 -> 0;255;3;0;5;0 (Motion/V_trigger -> 0) which is not in my own code

                          How often i do read the sensors do ot have any impact within the 120 seconds or outside of them.
                          I have roufly checked the mysensor code and haven't seen any such define behavior for Motion/V_trigger)

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


                          16

                          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