On two of my Arduino Due, when connecting the pin 3.3V
to any digital inputs (37
,36
,35
,34
), no serial message nor LED_BUILTIN
is thrown as output, only the Test
message.
Digital Pins are set as INPUT
by default. Blink
works.
I have never connected any other thing on those pins, even 5V.
What I am missing?
void setup() {
Serial.begin(115200);
while(!Serial);
pinMode(LED_BUILTIN,OUTPUT);
Serial.print("Test");
}
void loop() {
if (digitalRead(37))
Serial.print("37");
if (digitalRead(36))
Serial.print("36");
if (digitalRead(35))
Serial.print("35");
if (digitalRead(34))
Serial.print("34");
digitalWrite(LED_BUILTIN,digitalRead(37));
}
1 Answer 1
A good practice is to set the pin mode for all the pins used by the sketch.
void setup() {
Serial.begin(115200);
while(!Serial);
pinMode(34, INPUT);
pinMode(35, INPUT);
pinMode(36, INPUT);
pinMode(37, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
Serial.print("Test");
}
The Arduino AVR core does set the pin mode to INPUT by default but the Arduino SAM core does not. The SAM MCU is much more advanced and allows turning on and off the ports, and a lot of other functionality.
Cheers!
INPUT
s by default (??).