user41638: Years ago, I encountered a fairly long debate at AVRfreaks.net about whether or not it's OK to directly connect AVR pins that are configured as inputs with internal pullup enabled directly to ground through a button or switch.
From what I recall, the consensus at the time was that it's not (at least, for switches likely to be closed and conducting at reset), because at least some AVR MCUs weren't absolutely guaranteed to have their pins in high-impedance state at reset (at least, not if the chip reset while in brownout state, or something like that).
Thinking back, I'm not sure whether the warnings even applied to the chips I was introduced to at the time (ATtiny2313, ATtiny13, and ATmega162)... I just remember that the others on the site were pretty adamant that I was courting disaster, and I took their word for it.
Fast forward ~15 years.
The current datasheet for the ATmega2560 (at https://ww1.microchip.com/downloads/en/DeviceDoc/ATmega640-1280-1281-2560-2561-Datasheet-DS40002211A.pdf ) does seem to guarantee (on pages 7-9) that the pins used by ports A through L are tri-state high-impedance input pins at reset under all conditions, including when the clock is halted (obviously, any pin Arduino's bootloader subsequently makes use of could behave differently if I tried to hijack it for double-duty reading a button/switch... but the Mega2560 has so many pins, there really isn't any reason to reuse pins Arduino uses for its own purposes).
Offhand, I can think of three potential remaining concerns:

If I screw up and accidentally execute code that configures a pin connected directly to ground through a closed switch as a high output, the pin (and probably the whole chip) is likely to go up in smoke. I can deal with this risk.

If I were powering it with batteries, I might care about the constant power drain wasting battery life. I'm not, and I don't.

I'm not quite sure whether "OK to connect directly to ground through a momentary pushbutton" necessarily equates to "OK to connect directly to ground through a switch that might conceivably be closed and continuously conducting current for the life of the circuit.


So... have I missed anything? And is #3 a legitimate concern, or is it something that's not worth caring about if you're talking about something like 8 pins connected through a DIP switch?
Illustrative circuit:
Ground <-- [switch] --> IO pin (configured for input, internal pullup enabled)

user48011: 
If I screw up and accidentally execute code that configures a pin connected directly to ground through a closed switch as a high output, the pin (and probably the whole chip) is likely to go up in smoke. I can deal with this risk.

In addition to “there is an obvious bug”, there could also be a bug that is only triggered in very rare conditions, or a “cosmic ray” event which causes the processor to mis-execute instructions.
Or, maybe a metal tool or piece of debris fell across two of the processor pins and the other pin is an output that's currently high. (This is impossible to protect against in all cases, of course.)
In any of these cases, the hazard is that you're turning a situation where the device misbehaves temporarily into a situation where the device is permanently damaged.
Will this happen? Likely not. Is it worth protecting against? Depends on your application, on hard-to-quantify risk probabilities, and how much of a bother it would be to replace the processor.

41638: <p>Years ago, I encountered a fairly long debate at AVRfreaks.net about whether or not it's OK to directly connect AVR pins that are configured as inputs with internal pullup enabled directly to ground through a button or switch.</p>
<p>From what I recall, the consensus at the time was that it's not (at least, for switches likely to be <em>closed</em> and <em>conducting</em> at reset), because at least <em>some</em> AVR MCUs weren't absolutely <em>guaranteed</em> to have their pins in high-impedance state at reset (at least, not if the chip reset while in brownout state, or something like that).</p>
<p>Thinking back, I'm not sure whether the warnings even applied to the chips <strong>I</strong> was introduced to at the time (ATtiny2313, ATtiny13, and ATmega162)... I just remember that the others on the site were pretty adamant that I was courting disaster, and I took their word for it.</p>
<p>Fast forward ~15 years.</p>
<p>The <strong>current</strong> datasheet for the ATmega2560 (at <a href="https://ww1.microchip.com/downloads/en/DeviceDoc/ATmega640-1280-1281-2560-2561-Datasheet-DS40002211A.pdf" rel="noreferrer">https://ww1.microchip.com/downloads/en/DeviceDoc/ATmega640-1280-1281-2560-2561-Datasheet-DS40002211A.pdf</a> ) <strong>does</strong> seem to guarantee (on pages 7-9) that the pins used by ports A through L <strong>are</strong> tri-state high-impedance input pins at reset under all conditions, including when the clock is halted (obviously, any pin Arduino's bootloader subsequently makes use of could behave differently if I tried to hijack it for double-duty reading a button/switch... but the Mega2560 has so many pins, there really isn't any <em>reason</em> to reuse pins Arduino uses for its own purposes).</p>
<p>Offhand, I can think of three potential remaining concerns:</p>
<ul>
<li><p>If I screw up and accidentally execute code that configures a pin connected directly to ground through a closed switch as a high output, the pin (and probably the whole chip) is likely to go up in smoke. I can deal with this risk.</p>
</li>
<li><p>If I were powering it with batteries, I might care about the constant power drain wasting battery life. I'm not, and I don't.</p>
</li>
<li><p>I'm not quite sure whether &quot;OK to connect directly to ground through a <em>momentary</em> pushbutton&quot; necessarily equates to &quot;OK to connect directly to ground through a <em>switch</em> that might conceivably be closed and continuously conducting current for the life of the circuit.</p>
</li>
</ul>
<p>So... have I missed anything? And <strong>is</strong> #3 a legitimate concern, or is it something that's not worth caring about if you're talking about something like 8 pins connected through a DIP switch?</p>
<p>Illustrative circuit:</p>
<p><code>Ground &lt;-- [switch] --&gt; IO pin (configured for input, internal pullup enabled)</code></p>
 48011: <blockquote>
<p>If I screw up and accidentally execute code that configures a pin connected directly to ground through a closed switch as a high output, the pin (and probably the whole chip) is likely to go up in smoke. I can deal with this risk.</p>
</blockquote>
<p>In addition to “there is an obvious bug”, there could also be a bug that is only triggered in very rare conditions, or a “cosmic ray” event which causes the processor to mis-execute instructions.</p>
<p>Or, maybe a metal tool or piece of debris fell across two of the processor pins and the other pin <em>is</em> an output that's currently high. (This is impossible to protect against in all cases, of course.)</p>
<p>In any of these cases, the hazard is that you're <strong>turning a situation where the device misbehaves temporarily into a situation where the device is permanently damaged.</strong></p>
<p>Will this happen? Likely not. Is it worth protecting against? Depends on your application, on hard-to-quantify risk probabilities, and how much of a bother it would be to replace the processor.</p>
