arduino / ArduinoCore-avr

The Official Arduino AVR core
https://www.arduino.cc
1.25k stars 1.06k forks source link

Arduino Pro and Arduino Pro Mini, pin 13 initialized as output #477

Open landret opened 2 years ago

landret commented 2 years ago

Hi, pin 13 is unexpecteadly initialized as output. This code shows that the on board led on pin 13 blinks, without the pin being set as output in the code.

void setup(){}

void loop()
{
  delay(1000);
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
}
PaulStoffregen commented 2 years ago

This is a well known behavior of the classic AVR hardware. The pins default to INPUT mode if not configured with pinMode(), and when in that mode, writing to the output enables/disables the internal pullup resistor (which is normally accessed by pinMode with INPUT_PULLUP).

If you add pinMode(13, OUTPUT), you will see the LED is much brighter. When driven only by the weak internal pullup resistor, the LED still works but is quite dim.

Again, this is a well known behavior of the older AVR hardware. It is not a software bug.