Using Digital Pins 0 and 1 (PD0, PD1)

Hi, I have an Arduino Duemilanove with ATmega328P. I need to be able to set low bits of PORTD, but my code doesn’t work (leds don’t blink).

#define F_CPU 16.000E6
#include <avr/io.h>
#include <util/delay.h>

int main(void)

    // set PORTD as output
    DDRD = 0xff;

        PORTD = 0x03;
        PORTD = 0x00;
    return 0;      

Nowhere on the website it says that it is not possible to use these pins (just not recommended). Any ideas?


P.S. not using those pins is not an option.

    // set PORTB as output
    DDRB = 0xff;

Shouldn't you be setting DDRD and not DDRB

Sorry, that was missed in this example only. The question remains. Thanks.

I think the reason pins 0 and 1 are not recommended is because they are used by the Serial port.

If you really have to use them you may want to try commenting out the creation of the Serial Object in HardwareSerial.cpp

The thing is that I am not using Arduino's IDE. I use avr-gcc to compile and load the code with avrdude. I don't see how HardwareSerial.cpp could be affecting anything. I thought it may be the bootloader or something. That's why I'm here - to find out.

What I do is I try to use Arduino only as a prototyping board (which it is). I hope one day to pop-out the micro and use it in my project. For this I need it to behave like a normal micro.

Pins 0 and 1 are connected through 1k resistors to the serial hardware, that my be affecting your output.

You may be better off with a runtime board that does not have the serial hardware.

Sounds reasonable. I guess I’ll just have to try to assemble the circuit on breadboard. Thanks.