Analog oddness after uploading to Nano as Uno in IDE

Hi,

I read somewhere that it might be better to use the nano as an uno in IDE. Supposed to be more memory efficient.

But now the last two analog inputs (A6 and A7) does not work.

Would this error be expected?

If so, how can I make it work again? Selecting nano and uploading the sketch again does not solve it.

It may be that I am doing something else wrong.

Thanks!

Please post your sketch.

pert:
Please post your sketch.

//number of elements in arrays need to match for() cycles in void setup
int pinsIn[4] = {2, 3, 10, 11};
int pinsAnalog[8] = {0, 1, 2, 3, 4, 5, 6, 7};

int pin = 0;
int val = 0;
int pinsOut[4] = {4, 5, 6, 7};

void setup()
{
  //set up a total of pins for digital input (has to match number of elements in array)
  for(int i = 0; i < 4; i++)
  pinMode(pinsIn[i], INPUT);
  
  for (int i = 0; i < 4; i++) {
    pinMode(pinsOut[i], OUTPUT);
    digitalWrite(pinsOut[i], LOW);
  }

  analogReference(DEFAULT);

  pinMode(A0, INPUT_PULLUP);
  pinMode(A1, INPUT_PULLUP);
  pinMode(A2, INPUT_PULLUP);
  pinMode(A3, INPUT_PULLUP);
  pinMode(A4, INPUT_PULLUP);
  pinMode(A5, INPUT_PULLUP);
  pinMode(A6, INPUT_PULLUP);
  pinMode(A7, INPUT_PULLUP);
  
  Serial.begin(115200); // perhaps use a faster baud rate
}

void loop()
{
  Serial.print("knobs"); // use "knobs" as a keyword so you can receive
  // the knob values as a list with a [r knobs] in Pd
  for(int i = 0; i < 8; i++){
    unsigned int knob = analogRead (pinsAnalog[i]);
    Serial.print(" "); // first print a white space to separate the "knob" keyword from the values
    // and the values from each other
    Serial.print(knob); // then  print the actual knob value
  }
  Serial.println(); // finally print a newline character to denote end of data for keyword "knobs"

  // the same technique applies to the switches too
  // receive the switch values as a list with [r switches]
  Serial.print("switches");
  for(int i = 0; i < 4; i++) {
    int switchVal = digitalRead(pinsIn[i]);
    Serial.print(" ");
    Serial.print(switchVal);
  }
  Serial.println();
  
  //handle digital outputs
  if (Serial.available()) {
    static int temp;
    byte in = Serial.read();
    if (isDigit(in)) {
      temp = temp * 10 + in - '0';
    }
    else if (in == 'p') {
      pin = temp;
      temp = 0;
    }
    else if (in == 'v')  {
      val = temp;
      temp = 0;
      digitalWrite(pinsOut[pin], val);
    }
}
}

The Arduino is used as a serial interface over usb for graphical programming language PureData.

The only difference between the Uno and the Nano is that the NUM_ANALOG_INPUTS macro is set to 6 instead of 8 when compiling for Uno. But the Arduino core library doesn't actually make any use of that macro, and you're not using it anywhere in your sketch or using any libraries that might use it, so I don't think there could be any effect at all of compiling your sketch for an Uno.

A6 and A7 are ADC only, so this

  pinMode(A6, INPUT_PULLUP);
 pinMode(A7, INPUT_PULLUP);

won't work, you'll need external pullups instead. Not sure how it was working previously unless these inputs floated to a high level.

dlloyd:
A6 and A7 are ADC only

That must be it. Do you know where I can find info on this in the (arduino.cc) reference?

brodbord:
That must be it. Do you know where I can find info on this in the (arduino.cc) reference?

In the reference page.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.