0

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));
}
  • No. They are not defined as INPUTs by default (??). – Brethlosze Aug 3 at 3:42
  • 1
    And if you manually set those pins to INPUT, does it start working? – Majenko Aug 3 at 9:45
  • Yes... that was the problem... – Brethlosze Aug 3 at 20:24
  • 1
    I am guessing that, since those pins are also PWM pins, the alternate function was stuck in PWM mode until you manually forced it to change. Possibly from some earlier sketch or something. I don't know the SAM chips well enough to know how the pin functions work. – Majenko Aug 3 at 20:28
2

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.