I wrote a simple program to see what happens on boot up with the pins I am using on a different program. When I look at the pin states on a signal analyzer I see that D19 is high all the time (3.28 volts measured). I assume that this may be because of an internal pullup. However, on boot, all the output pins go high for 1.1608 seconds, then they all go low. Is there any way I can prevent this high output condition on boot up?
Which board and CPU? I guess PH3 implies an Arduino Mega (Atmega2560)? (But 3.28V "high" implies otherwise...)
Are you sure the pins go high, rather than just "float" in high impedance state? Immediately after reset, and during the bootloader check for new sketch, all the pins are normally in input mode, which means they aren't driven at all. (most bootloaders will be careful not to do anything to pins that they're not actually using.)
You'd need physical "pull" resistors to ensure a particular state during that time period.
What you are describing is normal with most any processor. When reset It has no clue as to what is connected to what so it turns the ports off (Tristate or input) processor dependent. The program then configures the ports to what it was programed to. Then the program commands the outputs to be HIGH or LOW. During this transition you have no control with the processor.
The solution is to add resistors to pull the port pin into the desired level. You see this recommended a lot when MOSFETs are used as they can fry when in that intermediate state, to use pull down resistors. That is generally a 10K resistor connected to the port pin and ground. This keeps the output level LOW for the reset process until the program takes control .
Several processors actually read the level on some ports to determine there boot sequence. This is quite common on the ESP processors. You will find you can use the port pins but they need to be in a given state for reset.
Sorry, I should have mentioned that it is a Mega 2560. I double checked the voltage and it is real at ~3.28 volts. VDD to ground measures just a tad over 5 volts.
I tried a 10K pull down on an output pin. That seemed to cure the high initial state, yet still allows the pin to go high when I command it to do so. I have no formal training in electronics or microcontroller programming, so I'm kind of self taught and still very much learning. I had read someplace that all unused output pins should be tied to ground, but I hadn't heard about using pull downs on pins being used. It does make sense though. Does the 2560 have an option for an internal pull down resistor or is an external resistor the only way to do it?
Thanks so much for the information.
There is an internal option for it, but the sane problem will occur if you use the internal pull-up resistors (Logically, they aren't configured at boot).
DO NOT do this to "unused output pins". Directly wiring a pin to either ground or 5V, or 3.3V, means that if it is inadvertently programmed as an output later on without removing that connection, it's very likely it will be set to the opposite state(i.e. wired low, but programmed as a 1, or wired high, but programmed as a zero), and will be damaged.
You may certainly pull any unused pin to GND or to VCC with a pullup/pulldown resistor. Saving on resistors by wiring many pins to the same resistor for pullup/pulldown is false economy in my books, but may be done if minimal cost is important.
Sorry, I should have specified through a resistor. On that subject, what is the highest value that would work but still allow a commanded high state to work?
So I suppose a bit of trial and error would be in order. Perhaps start with 10K and keep increasing until the pin no longer stays low on boot up, then back off a bit. Sound logical?
The internal pull-up resistors are documented as having an value of about 40k.
It'll depend somewhat on the environment; I've heard people claim that 40k is too high for some "noisy" environments.
There's some controversy about what to do with unused pins. Turning on the internal pullups and leaving them as inputs should be fine for most cases. (and better than the default state of "input without pullups.)