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. PIR example doesn`t wake Mega 2560?

PIR example doesn`t wake Mega 2560?

Scheduled Pinned Locked Moved Troubleshooting
15 Posts 4 Posters 2.7k 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.
  • V Offline
    V Offline
    vobi
    wrote on last edited by
    #6

    So, I have tested the following:
    Sketch on Mega 2560,
    pin 3 with int1 - not working
    pin 3 with int5 - not working
    pin2, int0,4 - not working
    pins 18-21, (digitalPinToInterrupt(DIGITAL_INPUT_SENSOR)) - not working
    Sketch on UNO - works as it should!
    So definitely something strange going on with 2560s interrupts.
    Any advice?

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

      It looks like the mega is not meant to be used as a sleeping node 😁

      mfalkviddM 1 Reply Last reply
      0
      • gohanG gohan

        It looks like the mega is not meant to be used as a sleeping node 😁

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

        @gohan nice catch. The return value -2 is defined as MY_SLEEP_NOT_POSSIBLE https://github.com/mysensors/MySensors/blob/fd417b66b25d66f8ac749a0c5e253e886598bac7/core/MySensorsCore.h#L82

        1 Reply Last reply
        0
        • V Offline
          V Offline
          vobi
          wrote on last edited by vobi
          #9

          Then what does it do when sleep is issued?
          Because the defined sleep-time still has to pass...and it does "nothing" till that, and that something cannot be broken by interrupt?
          What should be the good method to catch an interrupt, or a motion, without going thru the main loop crazy fast?
          Why cant it sleep?

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

            @vobi
            i think mega2560 can go powerdown, but have not the hardware for testing.
            What you could do for isolting the issue, is removing sleep and check if the interrupt triggers well (with a bool flag)

            V 1 Reply Last reply
            0
            • scalzS scalz

              @vobi
              i think mega2560 can go powerdown, but have not the hardware for testing.
              What you could do for isolting the issue, is removing sleep and check if the interrupt triggers well (with a bool flag)

              V Offline
              V Offline
              vobi
              wrote on last edited by
              #11

              @scalz
              Thanks, I will try it, and report back.

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

                I think the interrupt is triggered but it is just ignored by the sleep function, if the code I've been advised to use to check the interrupt is correct 😀

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  vobi
                  wrote on last edited by
                  #13

                  I have tested it, the interrupt indeed works fine.
                  So yes, because there is no sleep, it cannot be interrupted.
                  I still don`t understand why it cannot sleep.
                  And IMHO the interrupt should break the not-so-sleep-but-wait cycle anyway.
                  What do You think?

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

                    I don't have this much deep knowledge on the chip, but my best guess is that there must be something different in the MEGA chip than the other on the at328p on the uno and mini pro. It could very well be that the MEGA is not designed to be a low power device, but I'll let others say something more appropriate :)

                    1 Reply Last reply
                    0
                    • V Offline
                      V Offline
                      vobi
                      wrote on last edited by vobi
                      #15

                      According to Mr. Nick Gammon, thats not the case (or I`m missing something):

                      Running from a 9V battery through the "power in" plug, it draws about 50 mA.
                      Running on 5V through the +5V pin, it draws about 49 mA.
                      (Note: around 68 mA on a Mega 2560 board)
                      Now we'll try putting it to sleep:
                      Sketch B

                      #include <avr/sleep.h>
                      void setup () 
                      {
                        set_sleep_mode (SLEEP_MODE_PWR_DOWN);  
                        sleep_enable();
                        sleep_cpu ();  
                      }  // end of setup
                      void loop () { }
                      

                      Now the Uno draws 34.5 mA. A saving, but not a lot.
                      (Note: around 24 mA on a Mega 2560 board)
                      http://www.gammon.com.au/power

                      Also see:
                      https://forum.arduino.cc/index.php?topic=76724.0

                      1 Reply 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