PIR example doesn`t wake Mega 2560?
-
Hello all,
I just wired and tested the Motion Sensor example, (https://www.mysensors.org/build/motion),
but my Mega 2560 wont wake from sleep because of the interrupt when motion is detected.
It always finishes the sleeping. I serialprinted the sleeps output, it always states -2.
The motion sensor works, I can see that, when I shorten the sleep time (tested with 1 sec).
I also tested the output of the PIR, it generates more than 3.7 volts.
I`m using the latest library and IDE. I made my best to read all connected forum posts but didn't find a solution.
Anyone please can check it if it works for him?
Any help would be appreciated!
Thanks! -
Hello all,
I just wired and tested the Motion Sensor example, (https://www.mysensors.org/build/motion),
but my Mega 2560 wont wake from sleep because of the interrupt when motion is detected.
It always finishes the sleeping. I serialprinted the sleeps output, it always states -2.
The motion sensor works, I can see that, when I shorten the sleep time (tested with 1 sec).
I also tested the output of the PIR, it generates more than 3.7 volts.
I`m using the latest library and IDE. I made my best to read all connected forum posts but didn't find a solution.
Anyone please can check it if it works for him?
Any help would be appreciated!
Thanks! -
@vobi which pin (DIGITAL_INPUT_SENSOR) are you using?
The following pins on the Mega has support for interrupt: 2, 3, 18, 19, 20, 21
@mfalkvidd
I follow exactly the example, so D3.
But D2 also doesn't work. -
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? -
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? -
@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) -
-
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 :)
-
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