I have a project that uses a bread-boarded ATmega328P-PU. When I first power up, it seems like all (or at least many) of the digital pins go high resulting in anomalous behavior of servos, relays etc. I have tried to eliminate this by setting everything to low on setup() but I still get strange things happening till the system settles down, and then my code is implemented flawlessly.
What am I missing here?
On reset, all the IO pins become inputs until your sketch takes over. That includes the time while the bootloader is doing its thing.
You can try pulldown resistors on all the pins to hold them low.
You cry try installing yourcode with no bootloader, let the sketch start immediately on power up/reset.
I have also heard that the Arduino flickers each pin on startup or reset. I am not sure if this is true, but it may explain some of the issues you are having.
I'd not heard that.
There's always been an effort minimize the size of the bootloader - the only pin that does anything is D13.
On reset, all the IO pins become inputs until your sketch takes over
Would this cause some of them to go high?
I think I will live with the startup glitch on this project since I don't want to start re-soldering the output pins with pulldowns. It's not fatal, just annoying. In the future I will do that. I had already done that on my pins initialized as digital input since they seem to be sensitive as hell and fire sometimes if you even touch the wires connected to them.
Is tying the digital pins to ground routinely done with the ATmega328?
I have also heard that the Arduino flickers each pin on startup or reset
The behavior I am seeing is not the same each time on power up, one or two pins always seem to go high but others only do it once and a while. Seem like if they all flicker then I should see the same thing happen on each power up.
"Would this cause some of them to go high?"
High, Low, unknown how your external circuitry will see them.
"Is tying the digital pins to ground routinely done with the ATmega328?"
If you can't accept floating pins on a restart, then pulling them high or low with external resistors as needed is about the only solution.
Atmel recommends forcing unused pins into a high or low state so the pins do not oscillate, especially important in battery powered apps. I normally define any unused pins as inputs and enable the pullup resistors.