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. interrupt mystery with sensebender micro

interrupt mystery with sensebender micro

Scheduled Pinned Locked Moved Troubleshooting
17 Posts 6 Posters 4.2k 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.
  • ikkeTI Offline
    ikkeTI Offline
    ikkeT
    wrote on last edited by ikkeT
    #1

    Hi,

    I don't get interrupts working for door and PIR sensors. Any help appreciated.

    I connected door trigger on pin 3 (I assume thats D3) and PIR motion sensor on pin4 (D4). They are defined like this in code:
    https://github.com/ikke-t/sensebender/blob/master/SenseBender/SenseBender.ino#L114

    #define DOOR_PIN       3
    #define MOTION_PIN     4
    

    Then I try do stuff based on their value, waking up interrupt as described here:
    https://www.mysensors.org/download/sensor_api_20#sleeping

      sleep(digitalPinToInterrupt(DOOR_PIN), CHANGE,
            digitalPinToInterrupt(MOTION_PIN), CHANGE,
            MEASURE_INTERVAL);
    

    Somehow I don't get any changes from the PIR, and The door sensor only sends when the door opens. But then after couple times printing out values the serial from SB micro just goes bananas, outputting junk instead of readable stuff. Do the use of wakeup interrupt screw up the serial output?

    Another mystery is, that I read from some sample codes that only pins 2&3 can cause interrupts. But I don't see it mentioned in SB Micro page. And there is no D2 in SB micro, I assume it's used by the internal sensors. Is this true with SB Micro?

    So any idea how to make me understand how wrong I am? :)

    The code and all the necessary libraries are here:
    https://github.com/ikke-t/sensebender/blob/master/SenseBender/SenseBender.ino

    BTW, the door sensor worked fine until I changed it to be interruptible. But I don't want to poll in loop.

    Thanks,
    ikke

    1 Reply Last reply
    0
    • hekH Online
      hekH Online
      hek
      Admin
      wrote on last edited by
      #2

      D2 is connected to the radios IRQ pin on the sensebender.

      https://www.openhardware.io/dl/568d7feb0779a3581858ac2a/design/MySensorMicro.pdf

      So your sleep -ing will be interrupted by the radio IRQ pin.

      You could tap in to the D2 somewhere (and cut the leg off the radio module) to solve your dual external pin wake up problem.

      1 Reply Last reply
      0
      • ikkeTI Offline
        ikkeTI Offline
        ikkeT
        wrote on last edited by
        #3

        Is it safe to cut off radio irq pin? So it's not used by the MySensors code?

        1 Reply Last reply
        0
        • hekH Online
          hekH Online
          hek
          Admin
          wrote on last edited by
          #4

          No, it's not used right now.

          1 Reply Last reply
          1
          • tbowmoT Offline
            tbowmoT Offline
            tbowmo
            Admin
            wrote on last edited by tbowmo
            #5

            D2 interrupt is not used by nrf24, but if you're going to use it with rfm69 (with an adapter board) then you need interrupt for the radio.

            1 Reply Last reply
            1
            • ikkeTI Offline
              ikkeTI Offline
              ikkeT
              wrote on last edited by
              #6

              According to the above pic, there is plenty of interrupt pins. If thats what the int means in their name. Why can't I use other than the D2 for interrupt, and make sure D2 is not used for interrupts?

              1 Reply Last reply
              0
              • tbowmoT Offline
                tbowmoT Offline
                tbowmo
                Admin
                wrote on last edited by
                #7

                D3 is also an interrupt. The rest of the pins also have a pin change interrupt function (haven't used it yet myself)

                1 Reply Last reply
                1
                • ikkeTI Offline
                  ikkeTI Offline
                  ikkeT
                  wrote on last edited by
                  #8

                  I used pins 3 and 4 for the interruptible input from sensors. What does D2 have to do with this in my case, if none of the code is using it for interrupts?

                  I brought d2 and d3 up because some sample codes for sensors mentioned that only those can be used for interrupts. But I assume now this is not the case for SB, thanks to the pic above.

                  1 Reply Last reply
                  0
                  • hekH Online
                    hekH Online
                    hek
                    Admin
                    wrote on last edited by
                    #9

                    The CHANGE interrupt can only be used on pin 2,3 of the Atmeta328

                    https://www.arduino.cc/en/Reference/AttachInterrupt

                    There are other ways of trigger wakeup on all pins, but they are not supported by the MySensors sleep function and requires out to keep track of which pin that was triggered manually.

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

                      +1 on what said @Hek ;)
                      there is Pin change Int for other pins but you'll need to use raw registers stuff. There exists a lib for this but not supported by MYS sleep. And it's more efficient for memory consumption to use only what you need :)
                      I will publish soon my multisensor sketch where I use D2/int0,D3/int1 and two others pinchange int but in case you will find everything you need for this here : : http://www.gammon.com.au/forum/?id=11497

                      1 Reply Last reply
                      0
                      • hekH hek

                        The CHANGE interrupt can only be used on pin 2,3 of the Atmeta328

                        https://www.arduino.cc/en/Reference/AttachInterrupt

                        There are other ways of trigger wakeup on all pins, but they are not supported by the MySensors sleep function and requires out to keep track of which pin that was triggered manually.

                        ikkeTI Offline
                        ikkeTI Offline
                        ikkeT
                        wrote on last edited by
                        #11

                        @hek thanks, this clears the topic. I'll try cutting off the D2 and reuse that. I'll report back...

                        1 Reply Last reply
                        0
                        • ikkeTI Offline
                          ikkeTI Offline
                          ikkeT
                          wrote on last edited by
                          #12

                          Good news and bad news... I got change based interrupts to work by moving the motion to D2. That required cutting off the radio IRQ. Naturally I lost one radio there cutting too much....

                          So now it works initially. But after some rounds the serial text gets garbled, and it stops sending anything quite soon then.

                          isMetric: 1
                          TempDiff :127.31
                          HumDiff  :151.00
                          T: 27.31
                          H: 51
                          TempDiff :0.01
                          HumDiff  :0.00
                          Door  :0
                          Motion:1
                          TempDiff :0.01
                          HumDiff  :0.00
                          Door  :0
                          Motion:0
                          TempDiff :0.07
                          HumDiff  :0.00
                          Door  :0
                          Motion:1
                          TempDiff :0.10
                          HumDiff  :0.00
                          Door  :0
                          Motion:0
                          x00�����x00�����x00�x00x00��x00��x00x00�x00x00�x00x00x00�x00x00x00x00�x00�x00x00x00x00��x00x00�x00x00x00���������```
                          

                          the last line contines for long. Any ideas what could cause it? Some trick I missed with interrupts?

                          Again, the fixed code is here, it's almost the original SB Micro sample:
                          https://github.com/ikke-t/sensebender/blob/master/SenseBender/SenseBender.ino

                          1 Reply Last reply
                          0
                          • ikkeTI Offline
                            ikkeTI Offline
                            ikkeT
                            wrote on last edited by ikkeT
                            #13

                            Solved the scrambled test. I removed the interrupts, and made it loop faster. It always got screwed after five rounds, so it seemed to be due the clock speed change in the template:

                            #ifndef MY_OTA_FIRMWARE_FEATURE
                              if ((measureCount == 5) && highfreq) 
                              {
                                clock_prescale_set(clock_div_8); // Switch to 1Mhz for the reminder of the sketch, save power.
                                highfreq = false;
                              } 
                            #endif
                            

                            Removing that takes it further. I suppose the sample code is missing something to fix the serial speed after prescaler change. I also wonder if the radio would require some reconfig after clock speed change?

                            1 Reply Last reply
                            0
                            • ikkeTI Offline
                              ikkeTI Offline
                              ikkeT
                              wrote on last edited by
                              #14

                              But weird still. If I set the sleep time to 10 secs, without interrupts it works just fine. If interrupts are enabled, it stops always in less than ten rounds. So could it be the interrupts break the radio part somehow? E.g. if interrupt comes during transmit? Are interrupts safe in arduino, or should there be some lock set or disable interrupts for time of radio transmit?

                              YveauxY 1 Reply Last reply
                              0
                              • ikkeTI ikkeT

                                But weird still. If I set the sleep time to 10 secs, without interrupts it works just fine. If interrupts are enabled, it stops always in less than ten rounds. So could it be the interrupts break the radio part somehow? E.g. if interrupt comes during transmit? Are interrupts safe in arduino, or should there be some lock set or disable interrupts for time of radio transmit?

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

                                @ikkeT Have a look at the other pin interrupt related post: https://forum.mysensors.org/topic/4999/solved-latest-git-snapshot-causes-freezes/38
                                I fixed an issue that might also bother you.

                                http://yveaux.blogspot.nl

                                ikkeTI 1 Reply Last reply
                                1
                                • YveauxY Yveaux

                                  @ikkeT Have a look at the other pin interrupt related post: https://forum.mysensors.org/topic/4999/solved-latest-git-snapshot-causes-freezes/38
                                  I fixed an issue that might also bother you.

                                  ikkeTI Offline
                                  ikkeTI Offline
                                  ikkeT
                                  wrote on last edited by
                                  #16

                                  @Yveaux Thanks, I was following the thread. I confirm, the change fixed my problem too, excellent.

                                  1 Reply Last reply
                                  0
                                  • rborerR Offline
                                    rborerR Offline
                                    rborer
                                    wrote on last edited by
                                    #17

                                    @ikkeT, I've used the PIN 3 with a door sensor, it work perfectly, just enable the mode INPUT_PULLUP on the setup.

                                    void setup() {
                                    pinMode(DOOR_PIN, INPUT_PULLUP);

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


                                    14

                                    Online

                                    11.7k

                                    Users

                                    11.2k

                                    Topics

                                    113.0k

                                    Posts


                                    Copyright 2019 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