Unfortunately I do not have a scope.
Maybe because pin 2 is close to the tx-tr pins from some strange reason the communication with the computer makes him wake up ?
The code :
#include <IRremote.h>
#include <IRremoteInt.h>
#include <avr/sleep.h>
#include <avr/power.h>
#if defined(ARDUINO_AVR_UNO)
int RECV_PIN = 12;
const int motor_1_control_1 = 2;
const int motor_1_control_2 = 3;
const int motor_1_enabled = 4;
const int motor_2_control_1 = 5;
const int motor_2_control_2 = 6;
const int motor_2_enabled = 7;
#define INTERUPT_PIN PCINT4
#define INTERUPT_PIN_RANGE_F PCIF0
#define INTERUPT_PIN_RANGE_C PCIE0
#define INTERUPT_MASK PCMSK0
EMPTY_INTERRUPT (PCINT0_vect);
#endif
#if defined(ARDUINO_AVR_PRO)
int RECV_PIN = 2;
const int motor_1_control_1 = 10;
const int motor_1_control_2 = 11;
const int motor_1_enabled = 12;
const int motor_2_control_1 = 9;
const int motor_2_control_2 = 8;
const int motor_2_enabled = 7;
#define INTERUPT_PIN PCINT19
#define INTERUPT_PIN_RANGE_F PCIF2
#define INTERUPT_PIN_RANGE_C PCIE2
#define INTERUPT_MASK PCMSK2
EMPTY_INTERRUPT (PCINT2_vect);
#endif
const unsigned long NO_ACTIVITY_TIMEOUT = 1000; // milliseconds
unsigned long lastActivity = 0; // when we last woke
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
pinMode(motor_1_control_1, OUTPUT);
pinMode(motor_1_control_2, OUTPUT);
pinMode(motor_1_enabled, OUTPUT);
pinMode(motor_2_control_1, OUTPUT);
pinMode(motor_2_control_2, OUTPUT);
pinMode(motor_2_enabled, OUTPUT);
Serial.begin(9600);
Serial.println("Starting");
Serial.println(RECV_PIN);
irrecv.enableIRIn(); // Start the receiver
}
unsigned long totalWakeTime = 0;
unsigned long totalSleepTime = 0;
unsigned long lastTime = 0;
void sleepFunc()
{
// sleep if no activity for a while
if (millis () - lastActivity >= NO_ACTIVITY_TIMEOUT)
{
Serial.print("Going to sleep, slept ");
Serial.print(totalSleepTime);
Serial.print(" Been awake ");
Serial.println(totalWakeTime);
Serial.flush (); // wait for Serial to finish outputting
Serial.end (); // shut down Serial
noInterrupts (); // timed sequence coming up
INTERUPT_MASK |= bit (INTERUPT_PIN);
PCIFR |= bit (INTERUPT_PIN_RANGE_F); // clear any outstanding interrupts
PCICR |= bit (INTERUPT_PIN_RANGE_C); // enable pin change interrupts
totalWakeTime += millis() - lastTime;
lastTime = millis();
set_sleep_mode (SLEEP_MODE_STANDBY);
sleep_enable();
byte old_ADCSRA = ADCSRA;
// disable ADC to save power
ADCSRA = 0;
power_all_disable (); // turn off various modules
interrupts ();
sleep_cpu ();
totalSleepTime += millis() - lastTime;
lastTime = millis();
sleep_disable();
power_all_enable (); // enable modules again
ADCSRA = old_ADCSRA; // re-enable ADC conversion
Serial.begin(9600);
Serial.println("Waking up");
lastActivity = millis ();
} // end of no activity for a couple of seconds
}
void loop()
{
if (irrecv.decode(&results))
{
Serial.println(results.value, HEX);
delay(50);
irrecv.resume(); // Receive the next value
}
sleepFunc();
}
jremington:
Any interrupt, including communication from the computer, will wake the Arduino.
As you can see above, the same code runs on the arduino uno and pro mini.
The arduino uno sleeps till I press a button on the remote.
The pro mini always wakes up.
I've tested them both while they are connected to the computer.