Hallo,
hab meinen zweiten Mega 2560 erhalten und habe beim "alten" den Spannungsregler runtergelötet und nochmal verglichen. Die Messung bzw. Stromaufnahme reagiert empfindlich auf jeden Unterschied der Versorgungsspannung. Deswegen komme ich auch nicht mehr auf die alten 27mA in Sleep ohne Jumper. Habe beide Boards nochmal vermessen.
In Idle leuchtet LED 13, in Sleep ist die aus.
Den Effekt ohne Spannungsregler hatte ich etwas größer erwartet. Dachte an 5mA in Sleep. Aber nun gut, sind immerhin 5mA weniger, was der Batterielaufzeit auch einiges bringt. Der Jumper am 16U2 hat seine Wirkung behalten. Sehr wichtig zu wissen.
Testcode:
/* Sleep Demo Serial
* -----------------
* Example code to demonstrate the sleep functions in a Arduino. Arduino will wake up
* when new data is received in the serial port USART
* Based on Sleep Demo Serial from http://www.arduino.cc/playground/Learning/ArduinoSleepCode
"Aufwach-Schalter" an Pin 2 gegen Masse
Originalboard Arduino Mega 2560
Idle 59,2mA Sleep 22,3mA ohne 16U2 Jumper
Idle 54,5mA Sleep 15,5mA mit Jumper auf GND-Reset für 16U2
ohne Spannungsregler auf Board, abgegelötet
Idle 55,1mA Sleep 16,5mA ohne 16U2 Jumper
Idle 49,9mA Sleep 9,8mA mit Jumper auf GND-Reset für 16U2
*/
#include <avr/sleep.h>
int sleepStatus = 0; // variable to store a request for sleep
int count = 0; // counter
int ledPin = 13; // LED connected to digital pin 13
//int interruptPin = 10; // LED to show the action of a interrupt
int wakePin = 2; // active LOW, ground this pin momentary to wake up
//int sleepPin = 12; // active LOW, ground this pin momentary to sleep
int ledState = LOW;
void wakeUpNow() // here the interrupt is handled after wakeup
{
// execute code here after wake-up before returning to the loop() function
// timers and code using timers (serial.print and more...) will not work here.
// digitalWrite(interruptPin, HIGH); // LED an Pin 10 ein
}
void sleepNow()
{
/* Now is the time to set the sleep mode. In the Atmega8 datasheet
* http://www.atmel.com/dyn/resources/prod_documents/doc2486.pdf on page 35
* there is a list of sleep modes which explains which clocks and
* wake up sources are available in which sleep modus.
*
* In the avr/sleep.h file, the call names of these sleep modus are to be found:
*
* The 5 different modes are:
* SLEEP_MODE_IDLE -the least power savings
* SLEEP_MODE_ADC
* SLEEP_MODE_PWR_SAVE
* SLEEP_MODE_STANDBY
* SLEEP_MODE_PWR_DOWN -the most power savings
*
* the power reduction management <avr/power.h> is described in
* http://www.nongnu.org/avr-libc/user-manual/group__avr__power.html
*/
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
sleep_enable(); // enables the sleep bit in the mcucr register
// so sleep is possible. just a safety pin
/* Now it is time to enable an interrupt. We do it here so an
* accidentally pushed interrupt button doesn't interrupt
* our running program. if you want to be able to run
* interrupt code besides the sleep function, place it in
* setup() for example.
*
* In the function call attachInterrupt(A, B, C)
* A can be either 0 or 1 for interrupts on pin 2 or 3.
*
* B Name of a function you want to execute at interrupt for A.
*
* C Trigger mode of the interrupt pin. can be:
* LOW a low level triggers
* CHANGE a change in level triggers
* RISING a rising edge of a level triggers
* FALLING a falling edge of a level triggers
*
* In all but the IDLE sleep modes only LOW can be used.
*/
attachInterrupt(0,wakeUpNow, LOW); // use interrupt 0 (pin 2) and run function
// wakeUpNow when pin 2 gets LOW
sleep_mode(); // here the device is actually put to sleep!!
// THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP
sleep_disable(); // first thing after waking from sleep:
// disable sleep...
detachInterrupt(0); // disables interrupt 0 on pin 2 so the
// wakeUpNow code will not be executed
// during normal running time.
}
void setup()
{
pinMode(ledPin, OUTPUT); // LED connected to digital pin 13
//pinMode(interruptPin, OUTPUT); // LED to show the action of a interrupt pin 10
pinMode(wakePin, INPUT); // active LOW, ground this pin momentary to wake up
digitalWrite(wakePin, HIGH); // Pullup aktiv
//pinMode(sleepPin, INPUT); // active LOW, ground this pin momentary to sleep
//digitalWrite(sleepPin, HIGH); // Pullup aktiv
attachInterrupt(0,wakeUpNow, LOW); // use interrupt 0 (pin 2) and run function
// wakeUpNow when pin 2 gets LOW
}
void loop()
{
if ( digitalRead(2) == LOW ) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
sleepNow(); // sleep function called here
}
}