[solved] can't wake up Arduino from <SLEEP_MODE_PWR_DOWN>

EDIT: Now it seems to work. Thanks!

Hello,
I’m trying the sleep function for the first time on a breadboard Arduino. I think I’m doing something wrong. I edited the code per post #2, so now it looks like below.

If the set_sleep_mode(SLEEP_MODE_PWR_DOWN), I seem to only be able to wake it from sleep 3 times, then it stays asleep forever and playing with the interrupt wire does nothing.

Perhaps I’m no understanding how to electrically initiate the interrupt? I have a pull down resistor from Pin #2 to ground. I start with pin #2 on 5V, I then remove pin #2 from 5V, I get the “interrupt” on the serial monitor. I then put the pin back on 5V, then remove it again to see the interrupt. I can only do this 3 times though. Beyond that, the Arduino goes to sleep forever.

I think this might have something to do with < attachInterrupt(0, pinInterrupt, LOW)>. I think LOW is the only one you can use when you go to deep sleep, right?

writeout111
Entering Sleep Mode
interrupted

I am now Awake
Entering Sleep Mode
interrupted

I am now Awake
Entering Sleep Mode
interrupted

    //remove the space between '<' and 'avr'.  
    #include <avr/interrupt.h>  
    #include <avr/power.h>  
    #include <avr/sleep.h>  
    #include <avr/io.h>  
      
    void setup()  
    {  
       Serial.begin(9600);  
        //DDRD &= B00000011;       // set Arduino pins 2 to 7 as inputs, leaves 0 & 1 (RX & TX) as is  
        //DDRB = B00000000;        // set pins 8 to 13 as inputs  
        //PORTD |= B11111100;      // enable pullups on pins 2 to 7  
        //PORTB |= B11111111;      // enable pullups on pins 8 to 13  
        pinMode(13,OUTPUT);      // set pin 13 as an output so we can use LED to monitor  
        digitalWrite(13,HIGH);   // turn pin 13 LED on  
        delay(3000);
      Serial.println("writeout111");
    }  
      
    void loop()  
    {  
        // Stay awake for 1 second, then sleep.  
        // LED turns off when sleeping, then back on upon wake.  
        //delay(2000);  
        Serial.println("Entering Sleep Mode");  
        delay(5000);
        sleepNow();  
        Serial.println(" ");  
        Serial.println("I am now Awake");  
        delay(3000);
    }  
                    //  
    void sleepNow()  
    {  
        //interrupts();  
        // Set pin 2 as interrupt and attach handler:  
        attachInterrupt(0, pinInterrupt, LOW);
        delay(100);  
        // Choose our preferred sleep mode:  
        //set_sleep_mode(SLEEP_MODE_IDLE);  
        set_sleep_mode(SLEEP_MODE_PWR_DOWN);  
        //  

        //  
        // Set sleep enable (SE) bit:  
        sleep_enable();  
        //  
        // Put the device to sleep:  
        digitalWrite(13,LOW);   // turn LED off to indicate sleep  
        sleep_mode();  
        //  
        // Upon waking up, sketch continues from this point.  
        sleep_disable();  
        digitalWrite(13,HIGH);   // turn LED on to indicate awake  
        //delay(3000);
    }  
      
    void pinInterrupt()  
    {  
      detachInterrupt(0);  
      //attachInterrupt(0, pinInterrupt, LOW);
      Serial.println("interrupted!!");

    }
    DDRD &= B00000011;       // set Arduino pins 2 to 7 as inputs, leaves 0 & 1 (RX & TX) as is
    DDRB = B00000000;        // set pins 8 to 13 as inputs
    PORTD |= B11111100;      // enable pullups on pins 2 to 7
    PORTB |= B11111111;      // enable pullups on pins 8 to 13
    pinMode(led,OUTPUT);      // set pin 13 as an output so we can use LED to monitor
    digitalWrite(led,HIGH);   // turn pin 13 LED on
    delay(1000);
    digitalWrite(led,LOW);   // turn pin 13 LED on
    delay(1000);

Direct port manipulation (for speed) and delay() (for wasting time) do not belong in the same sketch.

PaulS:
Direct port manipulation (for speed) and delay() (for wasting time) do not belong in the same sketch.

I'm not sure what port manipulation means. But when I comment out the four DDR* and PORT* lines. I get slightly different behavior now. I'm not sure I'm wiring up the interrupt correctly, as I can't get out of sleep.