-1

I made a sketch to switch on all digital and analog pins, and found out several pins did not work as expected. Note: I manually put a jumper wire from each digital and analog pin (one at a time) to a resistor, LED and GND pin.

What I noticed was that some pins did not work (D3, D4, A4, A6 and A7) and pin A3 was only lit about half intensity. I tried two different Nanos and they performed both equally (also pin A3 at half intensity).

I also tried the jumper wires directly touching the pins (without a breadboard in between, to rule out a breadboard problem). Same behavior (so the breadboard is ok).

My questions:

  1. How come pins D3, D4, A4, A6 and A7 are not output VCC (3.3V) ?
  2. How can I switch pins these pins on?
  3. What is the reason pin A3 is blinking at half intensity?
  4. How can I switch this pin fully on?
  5. Bonus question: I used numbers, why are the pin names A0..A7 and D0..D12 not defined in Arduino IDE?

Test sketch:

const int NR_OF_PINS = 22;

int pins[NR_OF_PINS]   = 
// 0  1  2  3  4  5  6   7   8   9  10 11   12  13  14  15  16  17  18  19  20  21    
//D0 D1 D2 D3 D4 D5 D6  D7  D8  D9 D10 D11 D12 D13  A0  A1  A2  A3  A4  A5  A6  A7
 { 1, 2, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19, 20, 21, 22, 23, 24, 25, 26 };


void setup() 
{
  for (int n = 0; n < NR_OF_PINS; n++)
  { 
    pinMode(pins[n], OUTPUT);
    digitalWrite(pins[n], HIGH);
  }
}

void loop() 
{
}
Michel Keijzers
  • 13,014
  • 7
  • 41
  • 58

1 Answers1

2

You don't need an array, and your "base" pin is wrong - you start at pin 1, not pin 0. Also pins A6 and A7 can only be analog inputs, not digital outputs.

It's simpler to write:

void setup() {
    for (uint8_t i = 0; i < NUM_DIGITAL_PINS; i++) {
        pinMode(i, OUTPUT);
        digitalWrite(i, HIGH);
    }
}

void loop() {
}

That will work correctly on all Arduino boards regardless of the number of pins, since the board definition defines how many pins there are, and pins are always contiguously numbered from 0.

Majenko
  • 105,851
  • 5
  • 82
  • 139