I have an output tied high with a pull-up resistor. When I use the pinMode statement with OUTPUT as the parameter, the output goes low even though I don't explicitly use digitalWrite(pin,LOW) to set the pin low.
Is this the normal default state of the pin after pinMode is called? To maintain the pin at a high level, should I use a digitalWrite(pin,HIGH) before calling pinMode. Presumably behind the scenes this just sets the appropriate bit in the output register for the port?
Eugbug:
Is this the normal default state of the pin after pinMode is called?
Yes, unless you have previously written HIGH to that pin.
Why do you have the pull up resistor on the output ?
UKHeliBob:
Why do you have the pull up resistor on the output ?
That is sometimes required for external circuitry to prevent short turn on during reset and power up sequence. For example many of those Asia E-bay relay boards use a low input on their relay channels to activate each relay channel, so adding an external pull-up resistor will prevent a short turn on of the relays during an initial power up before the sketch code gets a chance to set the pin to output mode and HIGH output.
Lefty
UKHeliBob:
Why do you have the pull up resistor on the output ?
It's a pull up resistor. I'm communicating with a DS18B20 temperature sensor which has an open drain output stage so a resistor is needed.
Hi,
You can use digitalWrite(pin, HIGH) before use pinMode(pin, OUTPUT).
Best Regards.