I've got an Arduino mega compatible board, called Ethermega, from Freetronics (ATmega2560).
Schematic here.
In setup, I've written this code:
Serial.begin(9600);
pinMode(4, INPUT_PULLUP);
digitalWrite(4, HIGH); // Optional, I tried with and without
while (1)
{
if (digitalRead(4) == HIGH)
{
Serial.write("Up!\n");
}
}
(Don't worry about the fact I'm not using loop)
When I connect input 4 with 5V, I see "Up!". Rest of the time, I see nothing.
Considering I have enabled the internal pull-up, I'm expecting it should be up/high by default, and I would have to connect it to GND to get it low...
Another thing that puzzles me is I can find heaps of examples that use a tactile switch and no pullup/pulldown at all...
So what am I missing or doing wrong? Seems like whatever I do, I've got some kind of pulldown enabled...
pinMode(x, INPUT); digitalWrite(x, HIGH);
is the same aspinMode(x, INPUT_PULLUP);
. In general most cores will emulate that for you (I know chipKIT does) but you're right, it's best not to rely on it.