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. Pin change interrupt not firing with MySensors

Pin change interrupt not firing with MySensors

Scheduled Pinned Locked Moved Troubleshooting
39 Posts 7 Posters 11.3k Views 5 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.
  • elysionE Offline
    elysionE Offline
    elysion
    wrote on last edited by elysion
    #1

    Hi!

    I have been working on building motion sensors with MySensors to be able to trigger events on my Vera. Earlier I was able to get a few sensors working using 3.3V 8MHz Pro Minis. Now I am trying to build one with a custom ATMega328 board that uses the internal RC oscillator. For some reason I am unable to get the board to respond to pin change interrupts when using MySensors gw.sleep() using the MotionSensor.ino. I debugged the issue with a Pro Mini that (afaicr) is also using the internal oscillator instead of the external oscillator on the board. Everything however works correctly if I do not include MySensors code in my sketch and use attachInterrupt with mode set to CHANGE:

    void setup() {
      Serial.begin(115200);
      Serial.println("Boot");
      pinMode(3, INPUT_PULLUP);
      attachInterrupt(digitalPinToInterrupt(3), handler, CHANGE);
    }
    
    void loop() {
    }
    
    void handler() {
       Serial.println("foo");
    }
    

    However if I pass LOW mode to gw.sleep, the interrupt seems to work and a message seems to be sent to the controller correctly. But of course this only happens when the pin is in LOW state and not on changes.

    Has anyone got a clue on what might be causing the issue? I read through the interrupt handling code in MySensors that I believe is relevant in my case (MyHwATMega328 class), but was unable to find anything that might cause the issue.

    edit Forgot to mention, but I am using version 1.5 of MySensors /edit

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

      Hello,

      for the moment you can't use pin interrupt change lib with mysensors.
      Also, note, pinchange need you handle the change state. these are not working like D2/D3 INT0/1.
      I'm using pinchange with mysensors, but i use raw registers, my own isr for interrupts, and my sleep function.

      • for this you can have a look at how pinchange works here http://gammon.com.au/interrupts
      • or you can also OR your different pins with diodes
      elysionE 1 Reply Last reply
      0
      • scalzS scalz

        Hello,

        for the moment you can't use pin interrupt change lib with mysensors.
        Also, note, pinchange need you handle the change state. these are not working like D2/D3 INT0/1.
        I'm using pinchange with mysensors, but i use raw registers, my own isr for interrupts, and my sleep function.

        • for this you can have a look at how pinchange works here http://gammon.com.au/interrupts
        • or you can also OR your different pins with diodes
        elysionE Offline
        elysionE Offline
        elysion
        wrote on last edited by
        #3

        Thanks for the reply scalz!

        @scalz said:

        for the moment you can't use pin interrupt change lib with mysensors.

        I'm not sure what you mean by "pin interrupt change lib", but I would assume it would be possible to use the CHANGE type when calling gw.sleep as in the examples: https://github.com/mysensors/MySensors/blob/59550410a3f55f11b39aacfcaaa2dd8926682673/libraries/MySensors/examples/MotionSensor/MotionSensor.ino#L64

        Also, note, pinchange need you handle the change state. these are not working like D2/D3 INT0/1.
        I'm using pinchange with mysensors, but i use raw registers, my own isr for interrupts, and my sleep function.

        I have only connected the one motion sensor to my board and the interrupt handler just sends the current state (tripped / not tripped) to the controller. Thus I do not think I need to do anything special here.

        To clarify, I am using the MotionSensor.ino code without any modifications on my board. The execution reaches the gw.sleep call without problems, but does not resume even if the pin state changes. I am able to read the value from the pin by setting SLEEP_TIME to 1000 and this way confirm that the value of the pin does change and that can be read correctly.

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

          okay!
          you're right, i misread because of the title "pin change" lol . So you're using D3, clear :)
          quickly checked the lib, but i don't see anything fancy for the moment. if i find time, perhaps i'll try to reproduce but i've not heard others having this issue. Do you have this problem without doing any changes in the Motion sketch?

          elysionE 1 Reply Last reply
          0
          • scalzS scalz

            okay!
            you're right, i misread because of the title "pin change" lol . So you're using D3, clear :)
            quickly checked the lib, but i don't see anything fancy for the moment. if i find time, perhaps i'll try to reproduce but i've not heard others having this issue. Do you have this problem without doing any changes in the Motion sketch?

            elysionE Offline
            elysionE Offline
            elysion
            wrote on last edited by
            #5

            What I am currently uploading is the unmodified version of MotionSensor.ino linked above. I have previously build a motion sensor using a 3.3V pro mini with the same code. The only difference that I can think of with my current setup is that I am using the internal RC oscillator instead of the external and have changed the fuses accordingly by using the bootloader upload in Arduino IDE. I used the following board configuration:

            atmega328PstandaloneInt8MHz.name=Standalone ATmega328P (ATmega boot, internal 8MHz)
            
            atmega328PstandaloneInt8MHz.upload.tool=arduino:avrdude
            atmega328PstandaloneInt8MHz.upload.protocol=arduino
            atmega328PstandaloneInt8MHz.upload.maximum_size=30720
            atmega328PstandaloneInt8MHz.upload.maximum_data_size=2048
            atmega328PstandaloneInt8MHz.upload.speed=57600
            
            atmega328PstandaloneInt8MHz.bootloader.tool=arduino:avrdude
            atmega328PstandaloneInt8MHz.bootloader.low_fuses=0xE2
            atmega328PstandaloneInt8MHz.bootloader.high_fuses=0xDA
            atmega328PstandaloneInt8MHz.bootloader.extended_fuses=0xFD
            atmega328PstandaloneInt8MHz.bootloader.unlock_bits=0x3F
            atmega328PstandaloneInt8MHz.bootloader.lock_bits=0x0F
            atmega328PstandaloneInt8MHz.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex
            atmega328PstandaloneInt8MHz.build.mcu=atmega328p
            atmega328PstandaloneInt8MHz.build.f_cpu=8000000L
            atmega328PstandaloneInt8MHz.build.board=AVR_PRO
            atmega328PstandaloneInt8MHz.build.core=arduino
            atmega328PstandaloneInt8MHz.build.variant=standard```
            1 Reply Last reply
            0
            • I Offline
              I Offline
              idstone
              wrote on last edited by idstone
              #6

              Hi.
              Perhaps I ran into a similar issue?
              I created a new node with older 1.5.x version of my sensors-library.
              But I was not able to get a door-contact working via interrupt on pin 3 with a sketch I used more than 5 times before.
              Last change I can remember, was updating Arduino IDE for MacOS Sierra....

              How can I get back a working interrupt controlled door-switch?!

              elysionE 1 Reply Last reply
              0
              • I idstone

                Hi.
                Perhaps I ran into a similar issue?
                I created a new node with older 1.5.x version of my sensors-library.
                But I was not able to get a door-contact working via interrupt on pin 3 with a sketch I used more than 5 times before.
                Last change I can remember, was updating Arduino IDE for MacOS Sierra....

                How can I get back a working interrupt controlled door-switch?!

                elysionE Offline
                elysionE Offline
                elysion
                wrote on last edited by
                #7

                @idstone: Have you tried passing another mode (e.g. LOW) to gw.sleep method? The issue I am having is that with LOW the interrupt fires, but with CHANGE (which is the default in the sketches) it does not.

                YveauxY I 2 Replies Last reply
                0
                • elysionE elysion

                  @idstone: Have you tried passing another mode (e.g. LOW) to gw.sleep method? The issue I am having is that with LOW the interrupt fires, but with CHANGE (which is the default in the sketches) it does not.

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

                  @elysion Issues were fixed in the 2.1 beta of the MySensors library, so you'd better have a look at this code to see how to wake from interrupt.
                  Furthermore, you're using the ATmega out of spec when trying to wake from CHANGE; see http://forum.mysensors.org/topic/250/how-do-i-use-the-interrupt/5

                  http://yveaux.blogspot.nl

                  1 Reply Last reply
                  0
                  • elysionE elysion

                    @idstone: Have you tried passing another mode (e.g. LOW) to gw.sleep method? The issue I am having is that with LOW the interrupt fires, but with CHANGE (which is the default in the sketches) it does not.

                    I Offline
                    I Offline
                    idstone
                    wrote on last edited by
                    #9

                    @elysion

                    Hi. It seems, that the problem is related to complete charge of my 3,3V arduino pro's.
                    Reaction on interrupt while closing a door-switch on pin 3 works on an older 5V arduino.
                    I've read about problems at a customer-evalutation (amazon), especially with arduino pro clones and their interrupt-function.
                    Bought some more over store from mysensors on ebay... hope these will work correctly :(

                    YveauxY 1 Reply Last reply
                    0
                    • I idstone

                      @elysion

                      Hi. It seems, that the problem is related to complete charge of my 3,3V arduino pro's.
                      Reaction on interrupt while closing a door-switch on pin 3 works on an older 5V arduino.
                      I've read about problems at a customer-evalutation (amazon), especially with arduino pro clones and their interrupt-function.
                      Bought some more over store from mysensors on ebay... hope these will work correctly :(

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

                      @idstone said:

                      I've read about problems at a customer-evalutation (amazon), especially with arduino pro clones and their interrupt-function.

                      Can you quote your source please?

                      http://yveaux.blogspot.nl

                      I 1 Reply Last reply
                      0
                      • YveauxY Yveaux

                        @idstone said:

                        I've read about problems at a customer-evalutation (amazon), especially with arduino pro clones and their interrupt-function.

                        Can you quote your source please?

                        I Offline
                        I Offline
                        idstone
                        wrote on last edited by
                        #11

                        @Yveaux
                        https://www.amazon.de/Aukru-Redesign-atmega328-ATmega128-Compatible/dp/B00PLD3E1S

                        5.0 von 5 SternenWunderbar!
                        Von Ludwig Enfield am 19. Juli 2015

                        Bei den Arduino Remakes gibt es immer wieder kleine Abweichungen im Pinout. Also aufpassen - das betrifft hier insbeondere die Interrupt-Pins 0 und 1 bzw. die Pins A6/A7 (u.a. Analog-Ports).

                        YveauxY 1 Reply Last reply
                        0
                        • I idstone

                          @Yveaux
                          https://www.amazon.de/Aukru-Redesign-atmega328-ATmega128-Compatible/dp/B00PLD3E1S

                          5.0 von 5 SternenWunderbar!
                          Von Ludwig Enfield am 19. Juli 2015

                          Bei den Arduino Remakes gibt es immer wieder kleine Abweichungen im Pinout. Also aufpassen - das betrifft hier insbeondere die Interrupt-Pins 0 und 1 bzw. die Pins A6/A7 (u.a. Analog-Ports).

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

                          @idstone thanks!
                          If I understand it correctly, the feedback states the pinout of arduino pro mini clones is often slightly different, especially on interrupt pins and analog.
                          For analog pins this is certainly true, for interrupt pins I have not experienced this myself (yet).

                          http://yveaux.blogspot.nl

                          I 1 Reply Last reply
                          0
                          • D Offline
                            D Offline
                            DavidZH
                            wrote on last edited by
                            #13

                            In one sketch I am using pin change interrupt. But that is a node I built from scratch. I have the feeling the issues arise with the MyS function "sleep()" in combination with a set time. As long as I call sleep(0xff,0x00, 0xff, 0x00, 0);
                            pin change interrupts work. As soon as I change any of the parameters, the node will not wake up anymore.

                            That was on 2.0 I have yet to convert and try it on 2.1.

                            As soon as I have done that, I will post the code .

                            YveauxY 1 Reply Last reply
                            0
                            • D DavidZH

                              In one sketch I am using pin change interrupt. But that is a node I built from scratch. I have the feeling the issues arise with the MyS function "sleep()" in combination with a set time. As long as I call sleep(0xff,0x00, 0xff, 0x00, 0);
                              pin change interrupts work. As soon as I change any of the parameters, the node will not wake up anymore.

                              That was on 2.0 I have yet to convert and try it on 2.1.

                              As soon as I have done that, I will post the code .

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

                              @DavidZH Just a shot in the dark, but could you try @tekka workaround from https://github.com/mysensors/MySensors/issues/725 and see if it still crashes ?

                              http://yveaux.blogspot.nl

                              D 1 Reply Last reply
                              0
                              • YveauxY Yveaux

                                @DavidZH Just a shot in the dark, but could you try @tekka workaround from https://github.com/mysensors/MySensors/issues/725 and see if it still crashes ?

                                D Offline
                                D Offline
                                DavidZH
                                wrote on last edited by
                                #15

                                @Yveaux I will try that as soon as I'm back from my winter sports vacation (as far as you can call lush green Alpine meadows that. At least the slopes are well maintained!). I have no access to a node and gateway now.

                                For me it worked for that sketch as it's main function is reading momentary switches, either on mains power or on battery. As soon as I want to add a sensor that needs to send it's info on a set interval I needed it to be on mains power.

                                But like I said, I will convert the sketch to 2.1 this week, and next week I'll give the workaround a shot.
                                Keep you posted!

                                1 Reply Last reply
                                1
                                • YveauxY Yveaux

                                  @idstone thanks!
                                  If I understand it correctly, the feedback states the pinout of arduino pro mini clones is often slightly different, especially on interrupt pins and analog.
                                  For analog pins this is certainly true, for interrupt pins I have not experienced this myself (yet).

                                  I Offline
                                  I Offline
                                  idstone
                                  wrote on last edited by idstone
                                  #16

                                  @Yveaux

                                  Hey!
                                  Got some news... the new charge of Arduino Pros arrived, but the problem persists. So I started more trail ' n error and got something:

                                  I installed the Arduino-IDE and mysensors-1.5.4-library on an manjaro-based notebook. I had to do some symlinking to get a newer version of avrdude working and now the same sketch I used before works now!

                                  Back to my Mac, flashing the same sketch, the node doesn't work correctly?!
                                  So problem seems to be the version of avrdude, which is offered by the arduino-ide?!


                                  I finally downgraded to IDE 1.6.8 and especially AVR Boards 1.6.8.
                                  Now everything works as expected .... :D

                                  1 Reply Last reply
                                  0
                                  • gohanG Offline
                                    gohanG Offline
                                    gohan
                                    Mod
                                    wrote on last edited by
                                    #17

                                    So it was just a bug in the latest updates of the ide and boards? I'm having probably the same problem on a mega2560

                                    I 1 Reply Last reply
                                    0
                                    • gohanG gohan

                                      So it was just a bug in the latest updates of the ide and boards? I'm having probably the same problem on a mega2560

                                      I Offline
                                      I Offline
                                      idstone
                                      wrote on last edited by
                                      #18

                                      @gohan

                                      I'm not familiar with your problem, but mine was, that the interrupt on pin3 didn't work as expected. So I was not able to use my new sensor as watchdog for my windows/doors. With downgrade of the Arduino-IDE AND especially AVR Boards 1.6.8 my problem is solved now and every change on that interrupt-pin is correctly recognised and send to gateway.

                                      gohanG 1 Reply Last reply
                                      0
                                      • I idstone

                                        @gohan

                                        I'm not familiar with your problem, but mine was, that the interrupt on pin3 didn't work as expected. So I was not able to use my new sensor as watchdog for my windows/doors. With downgrade of the Arduino-IDE AND especially AVR Boards 1.6.8 my problem is solved now and every change on that interrupt-pin is correctly recognised and send to gateway.

                                        gohanG Offline
                                        gohanG Offline
                                        gohan
                                        Mod
                                        wrote on last edited by
                                        #19

                                        @idstone if you don't mind, please take a look at last line of my code https://forum.mysensors.org/topic/5807/interrupt-and-sleep

                                        I 1 Reply Last reply
                                        0
                                        • gohanG gohan

                                          @idstone if you don't mind, please take a look at last line of my code https://forum.mysensors.org/topic/5807/interrupt-and-sleep

                                          I Offline
                                          I Offline
                                          idstone
                                          wrote on last edited by
                                          #20

                                          @gohan

                                          Hi again. I can confirm, that I got similar problems... the state of the interrupt pin wasn't correctly recognized, too.
                                          May be You could try downgrading Arduino-IDE and (very important) avr boards (1.6.8) ?!

                                          elysionE gohanG 2 Replies Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          22

                                          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