How to adapt a sketch written for Uno to Nano, including pins A6 and A7?

There is a project published at the links below that lets a person automatically test all the pins of an Arduino to find any that aren't functioning the way they're meant to. I would like to use this project but it was made for the Arduino Uno and I use mostly Arduino Nanos which have an additional two analogue-only pins called A6 and A7. The project is written with these two constants set to define the range of pins to put through the analogue-pin test. Would it work if I changed 15 to A0 and 19 to A7? I'm guessing not. I don't suppose pins A6 and A7 can be referred to as pins 20 and 21 in the code either? Thanks for any help.

const  int    FirstAnaPort =  15;
const  int    LastAnaPort  =  19;

The entirity of the code is here: http://arduinoinfo.mywikis.net/wiki/Arduino_Test

The explaination of the project is here: Arduino-testing - ArduinoInfo

Have you tried printing the value of A6 and A7 ?

Why not use

const  int    FirstAnaPort =  A0;
const  int    LastAnaPort  =  A7;

I haven’t tried it; I haven’t yet made the thing with the resistors.

Would this code work with for FirstAnaPort = A0 and LastAnaPort = A7? I assumed that would only work with numbers but I am hoping you’re going to tell me it will work with a letter in there!

  for (  DigPort2Test = FirstAnaPort;
         DigPort2Test <= LastAnaPort;
         DigPort2Test ++)

seanspotatobusiness:
I haven’t tried it; I haven’t yet made the thing with the resistors.

Would this code work with for FirstAnaPort = A0 and LastAnaPort = A7? I assumed that would only work with numbers but I am hoping you’re going to tell me it will work with a letter in there!

  for (  DigPort2Test = FirstAnaPort;

DigPort2Test <= LastAnaPort;
        DigPort2Test ++)

There’s no letters in there.

Somewhere in the Arduino IDE there’s something like…

const int A0 = 14;
//or maybe...
#define A0 14

Regardless, what value “A0” has depends on which Arduino platform you are running on.

Writing such code relies on the fact that the analogue pin numbers are all consecutive and without any gaps. As far as I know that may be the case, but there’s no such guarantee.

Create an array if you want a guaranteed list of analogue pin numbers to iterate over…

int pins[] = { A0, A1, A2, A3, A4, A5, A6, A7 };

sp.const byte pins[] = { A0, A1, A2, A3, A4, A5, A6, A7 };

I haven't tried it; I haven't yet made the thing with the resistors.

There is nothing stopping you printing the values associated with the A* pin names.

The A* names are just a convenient way of referring to the analogue pins so that they can be labelled as such on the Arduino board, but they actually have pin numbers as well.

I modified the code for test 5 in a way that I think will convert it to use an array. I had to add this bit to the top of the sketch:

int allAnaPins[] = {A1, A2, A3, A4, A5, A6, A7};  // array of all analogue pins on Nano and Pro Micro including input-only pins except A0 which is used to do the testing
int numAnaPins = 7; // number of analogue pins on Nano and Pro Micro including input-only pins except A0 which is used to do the testing

Could anyone please confirm that the change I made is correct? I followed the tutorial here: Tutorial 13: How to Use Arrays with Arduino | Programming Electronics Academy but they don’t explain what compels the Arduino to use the “thisPin” value as the position in the array to take. Thanks very much.

Original:

 Serial.println("TEST 005 - Analog Pins Sink Current");
  pinMode(2, OUTPUT);      // Set Load pin to Output mode
  digitalWrite(2, HIGH);              // Connect HIGH Load  

  WriteAnalogPinLabels();

  for (  DigPort2Test = FirstAnaPort;
         DigPort2Test <= LastAnaPort;
         DigPort2Test ++)
  {//Loop thru Sink Tests

    pinMode(DigPort2Test, OUTPUT);      // Set tested pin to Output mode
    digitalWrite(DigPort2Test, LOW);    // Pin Sinks current LOW   
    delay(A2D_Delay);
    IntVoltsRead = analogRead(A0);
    FloatVoltsRead = a2d2float (IntVoltsRead);
    pinMode(DigPort2Test, INPUT);      // ReSet tested pin to Input mode   
    Serial.print(FloatVoltsRead,2);
    Serial.print("   ");

    if (FloatVoltsRead > LowVoltResultOK
      &&  FloatVoltsRead < HighVoltResultOK)
    {
      FailArray[FailArrayPtr]  = 0;
    }
    else
    {
      Failure ++;
      FailArray[FailArrayPtr]  = 1;
    }

  }//END Loop thru Source Tests
  Serial.println();
  WriteAnalogPassFail();

Modified:

 Serial.println("TEST 005 - Analog Pins Sink Current");
  pinMode(2, OUTPUT);      // Set Load pin to Output mode
  digitalWrite(2, HIGH);              // Connect HIGH Load  

  WriteAnalogPinLabels();

  for (  int thisPin = 0; 
         thisPin < numAnaPins; 
         thisPin++)
  {//Loop thru Sink Tests

    pinMode(allAnaPins, OUTPUT);      // Set tested pin to Output mode
    digitalWrite(allAnaPins, LOW);    // Pin Sinks current LOW   
    delay(A2D_Delay);
    IntVoltsRead = analogRead(A0);
    FloatVoltsRead = a2d2float (IntVoltsRead);
    pinMode(allAnaPins, INPUT);      // ReSet tested pin to Input mode   
    Serial.print(FloatVoltsRead,2);
    Serial.print("   ");

    if (FloatVoltsRead > LowVoltResultOK
      &&  FloatVoltsRead < HighVoltResultOK)
    {
      FailArray[FailArrayPtr]  = 0;
    }
    else
    {
      Failure ++;
      FailArray[FailArrayPtr]  = 1;
    }

  }//END Loop thru Source Tests
  Serial.println();
  WriteAnalogPassFail();

Wrong, functions that expect a single variable can't just be fed an array:

int allAnaPins[] = {A1, A2, A3, A4, A5, A6, A7};  // array of all analogue pins on Nano and Pro Micro including input-only pins except A0 which is used to do the testing
int numAnaPins = 7; // number of analogue pins on Nano and Pro Micro including input-only pins except A0 which is used to do the testing
...
    digitalWrite(allAnaPins, LOW);    // Pin Sinks current LOW

That is the whole point of iterating over the range of the array, so you can process the elements one at a time.

On this page: Tutorial 13: How to Use Arrays with Arduino | Programming Electronics Academy

The example is as follows:

int timer = 100;           // The higher the number, the slower the timing.
int ledPins[] = {
  2, 7, 4, 6, 5, 3
};       // an array of pin numbers to which LEDs are attached
int pinCount = 6;           // the number of pins (i.e. the length of the array)

void setup() {
  // the array elements are numbered from 0 to (pinCount - 1).
  // use a for loop to initialize each pin as an output:
  for (int thisPin = 0; thisPin < pinCount; thisPin++) {
    pinMode(ledPins, OUTPUT);
  }
}

void loop() {
  // loop from the lowest pin to the highest:
  for (int thisPin = 0; thisPin < pinCount; thisPin++) {
    // turn the pin on:
    digitalWrite(ledPins, HIGH);
    delay(timer);
    // turn the pin off:
    digitalWrite(ledPins, LOW);

  }

  // loop from the highest pin to the lowest:
  for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) {
    // turn the pin on:
    digitalWrite(ledPins, HIGH);
    delay(timer);
    // turn the pin off:
    digitalWrite(ledPins, LOW);
  }
}

As far as I can tell, I copied what they did. Did they do it wrong as well or did I miss something?

They did it wrong and you copied it

Take a look at where they copied their example from, mangling it as they did so

Thanks - this makes much more sense now.