-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() 
{
}
11
  • 2
    A6 and A7 are analog only on classic Nano. 3.3 V on Nano?
    – Juraj
    Aug 24, 2019 at 16:57
  • 1
    Also D0 is pin 0, not pin 1. Why are you bothering with an array?
    – Majenko
    Aug 24, 2019 at 17:01
  • 1
    your array is wrong. A0 is 13
    – Juraj
    Aug 24, 2019 at 17:04
  • 1
    you use pin numbers not valid for Nano, you skip D3 and D4
    – Juraj
    Aug 24, 2019 at 17:08
  • 1
    that are pins of the PCB. sorry A0 is 14. github.com/arduino/ArduinoCore-avr/blob/…
    – Juraj
    Aug 24, 2019 at 17:17

1 Answer 1

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.

7
  • Thanks for the answer (btw, as a side question, I noticed there is not a NUM_ANALOG_PINS declared). Why not? (and also I thought analog pins could be used as digital pins, but not the other way around). Aug 24, 2019 at 17:15
  • 1
    It's defined as NUM_ANALOG_INPUTS not NUM_ANALOG_PINS.
    – Majenko
    Aug 24, 2019 at 17:18
  • 1
    And the NUM_DIGITAL_PINS incorporates all the analog pins that can be digital inputs and outputs.
    – Majenko
    Aug 24, 2019 at 17:18
  • 1
    arduino.stackexchange.com/a/36683/37523
    – VE7JRO
    Aug 24, 2019 at 17:20
  • 1
    @MichelKeijzers Well, an analog input may not be a physical pin. There are chips around that have temperature sensors (for example) built in that connect to the ADC MUX - so an analog input exists that connects to that sensor, but it doesn't have a "pin" as such - so calling them analog pins is a misnomer.
    – Majenko
    Aug 24, 2019 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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