There is no pinMode(pin, INPUT_PULLDOWN)

Just an FYI - I am pretty sure that these boards do not support INPUT_PULLDOWN.

Which I verified in the code, that it simply does the same as pinMode(pin, INPUT);

For awhile I thought my MINIMA board was having major issues, as I tried running a slightly modified version of a pin test that I use on Teensy boards (and others).

//#ifdef ESP_PLATFORM
#define digitalWriteFast digitalWrite
#define digitalReadFast digitalRead
//#endif
void setup() {
  Serial.begin(115200);
  while (!Serial && millis() < 4000 );
  //Serial.println("Compile Time:: " __FILE__ " " __DATE__ " " __TIME__);
  Serial.print("Num Digital Pins: ");
  Serial.println(NUM_DIGITAL_PINS, DEC);
  Serial.flush();

  testForShorts();
  
}

uint32_t cnt = 0;
void loop() {
  cnt++;
    allPinTest( cnt );
}

uint32_t pinLast[NUM_DIGITAL_PINS];
void allPinTest( uint32_t cnt ) {
  uint32_t ii, SET;
  Serial.print("PULLDOWN Start Vals:\n  ");
  SET = 1;
  Serial.print("PULLDOWN :: TEST to 3.3V\n  ");
  for ( ii = 0; ii < NUM_DIGITAL_PINS; ii++) {
    pinMode( ii, INPUT_PULLDOWN );
    delayMicroseconds( 5 );
    pinLast[ii] = digitalReadFast( ii );
    if (pinLast[ii]) {
      Serial.print("\nd#=");
      Serial.print( ii );
      Serial.print( " val=" );
    }
    Serial.print( pinLast[ii] );
    Serial.print(',');
  }
  Serial.println();
  Serial.println();
  while ( 1 ) {
    uint32_t jj, dd = 0, cc = 0, ee=4;
    cc = 0;
    for ( ii = 0; ii < NUM_DIGITAL_PINS; ii++) {
      jj = digitalReadFast( ii );
      if ( jj != pinLast[ii] ) {
        dd = 1;
        cc++;
        pinLast[ii] = jj;
        Serial.print("d#=");
        Serial.print( ii );
        if ( pinLast[ii] ) Serial.print( "\t" );
        Serial.print( " val=" );
        Serial.print( pinLast[ii] );
        Serial.print(',');
      }
      if ( cc > 1 && ee ) {
        Serial.println(">>> MULTI CHANGE !!");
        ee--;
      }
      if ( Serial.available() ) {
        while ( Serial.available() ) Serial.read();
        if ( 0 == SET ) {
          SET = 1;
          Serial.print("PULLUP :: TEST TO GND\n  ");
        }
        else {
          SET = 0;
          Serial.print("PULLDOWN :: TEST to 3.3V\n  ");
        }
        for ( ii = 0; ii < NUM_DIGITAL_PINS; ii++) {
          if ( 0 == SET )
            pinMode( ii, INPUT_PULLDOWN );
          else
            pinMode( ii, INPUT_PULLUP );
          delayMicroseconds( 20 );
          pinLast[ii] = digitalReadFast( ii );
          if (SET != pinLast[ii]) {
            Serial.print("d#=");
            Serial.print( ii );
            Serial.print( " val=" );
            Serial.println( pinLast[ii] );
          }
        }
      }
    }
    if ( dd ) {
      dd = 0;
      Serial.println();
      delay( 50 );
    }
  }
}

void testForShorts() {
  uint32_t ii;
  Serial.print("Quick Test for Shorts to adjacent pin");
  Serial.println("First pull pins down and see if the next one follows");
  for ( ii = 0; ii < NUM_DIGITAL_PINS-1; ii++) {
    pinMode( ii+1, INPUT_PULLDOWN );
    pinMode( ii, OUTPUT);
    digitalWrite(ii, HIGH);
    delayMicroseconds( 5 );
    if (digitalRead(ii+1)) {
      Serial.print(ii,DEC);
      Serial.print(":");
      Serial.println(ii+1, DEC);
    }
  }
  Serial.println("\n Now try Pull up and see if setting low follow");
  for ( ii = 0; ii < NUM_DIGITAL_PINS-1; ii++) {
    pinMode( ii+1, INPUT_PULLUP );
    pinMode( ii, OUTPUT);
    digitalWrite(ii, LOW);
    delayMicroseconds( 5 );
    if (!digitalRead(ii+1)) {
      Serial.print(ii,DEC);
      Serial.print(":");
      Serial.println(ii+1, DEC);
    }
  }
  Serial.println();  
}

The code basically allows you to try to set all of the IO pins to either INPUT_PULLUP or INPUT_PULLDOWN.   And then cycles scanning all of the pins to see if any pins have changed state.  

So for example if you are in INPUT_PULLUP mode, and you have a jumper to GND, if you touch an IO pin it will print out which pin changed state.  Which helps when sometimes what you think you have attached to a device is not... Like off by one issues...

It also helps pinpoint possible shorts, that is if I touch one pin and 3 change state, then maybe something is wrong...

Is working ok in this state, but tried with INPUT_PULLDOWN where you try to jumper from 3.3v or 5v to different pins, to see if any changes.  In this case I was getting tons of random pins changing state.  I was also getting several pins changing state when I simply changed if I was holding a wire to gnd or not... Which makes sense as all of the IO pins states are floating.

May still be an issue with my minima, as if I try the jumper in the PU state to pin 13, nothing shows up, and I then felt the temperature of the processor going up...

Again post is mostly just a heads up, on INPUT_PULLDOWN.

Nope. From digital.cpp in the core

case INPUT_PULLDOWN: // **TODO: document the INPUT_PULLDOWN is unavailable**

saw it the other day.

1 Like

I think the architecture might support it, but on ATMega*8 it is not, so I guess it was not implemented

Neither the Microchip ATmega328 nor the Renesas RA4m1 HARDWARE support pulldowns on the GPIO pins.

1 Like

Is not it the compatibility with classic Uno R3 that you wanted?

Looking at the hardware manual, I don't think so, for example if you look at Table 19.2 you see:

And in section 19.2.5 Port mn Pin Function Select register, there is a PCR bit to control Pull-up and no mention of pull down.

Thanks @Merlin513, I remember seeing that as well, after the program failed and I thought something was broken.

I might humbly suggest that, one option might be, to show that in the context pop-up text:

Maybe if it said, not supported by the hardware or some such thing.

Maybe have something on documentation pages, like:
pinMode() - Arduino Reference
Digital Pins | Arduino Documentation

Which describe more of the different options, and maybe a table or the like that says not supported on the following architectures or the like.

Thank you for the insightful answer.

Yes, I do believe in compatibility and having programs working as expected. As I am sure you do as well!

Have a wonderful day.

1 Like

The "hover" will show the text of a comment adjacent to the enumerator if present, so it is generally possible to provide such information.

However, it isn't so easy to do that with this particular piece of code. The reason is that this comes from the "Arduino core API", which is shared by multiple cores. So the comment could not be added to the upstream source. The only way it would be possible is by patching the comment into the code at the time it is pulled into the "Arduino UNO R4 Boards" platform when packaging a release.

1 Like

Sounds like that could be a pain.

Wonder if it could somehow be done by conditional?
like

#ifdef PORT_PINS_SUPPORT_PD
<normal comments>
#else
<not supported by this hardware comment>
#endif

It was just an idea.

The comment will not be recognized as adjacent to the enumerator by the language server with that approach so the comments would not be shown in the "hover".

But this approach does work as intended:

#ifdef PORT_PINS_SUPPORT_PD
  <normal comments>
  INPUT_PULLDOWN   = 0x3,
#else
  <not supported by this hardware comment>
  INPUT_PULLDOWN   = 0x3,
#endif
1 Like

That would be great.

For a laugh, I started this thread, because, I am debugging some stuff, and I thought maybe I had screwed up the MINIMA board, so I loaded up the sketch above and found that doing anything, showed lots of pins changing state... even just touching and moving my jumper wire that one end was connected to ground.

So I ordered a new MINIMA board from Amazon which arrived in town... After I ordered the new one, I figured out, the board is probably fine, but just all of the IO pins were floating.

Although I should probably check to make sure, as I found jumpering D13 to GND and the processor started to get HOT...