Can't read ADC6 and ADC7

Hi everyone,

I am using atmega328p but I cannot have access to read pins ADC6 and ADC7.

According to my 328P data sheet it only has 6 ADC channels and these are denoted ADC0 though ADC5. How and why are you trying to access ADC6 and ADC7 ?

Thank you stowite for your reply.

Before, I thought that these pins could be use as analogue pins. thats why I interfaced two sensors to ADC6 and ADC7. Is it possible to read these pins rather then to change complete PCB design.

Many thanks

Sorry - I was looking at the DIL version not the other versions.

Please define "can not have access".

Yes sterretje, I cannot have access to ADC6 and ADC7. Do you have any thought ?

In the file C:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard\pins_arduino.h
you can see the definitions of the pins.

#define PIN_A0   (14)
#define PIN_A1   (15)
#define PIN_A2   (16)
#define PIN_A3   (17)
#define PIN_A4   (18)
#define PIN_A5   (19)
#define PIN_A6   (20)
#define PIN_A7   (21)

so this minimal sketch should show the trick

void setup()
{
  Serial.begin(115200);
  Serial.println(__FILE__);
}

void loop()
{
  for (int i = 14; i < 22; i++)
  {
    Serial.print(i);
    Serial.print("\t");
    Serial.println(analogRead(i));
  }
  Serial.println();

  delay(1000);
}

the output on my (dil) 328 shows "floating" values so seems to work

What processor/board have you selected in the IDE?

Thank you very much robtillaart for your reply.

Despite the fact that the OP does not pass the Turing test:

The ports are only available on Arduinos with SMD AVR. You have probably selected a board with a DIL AVR in the IDE.

irfiee:
Yes sterretje, I cannot have access to ADC6 and ADC7. Do you have any thought ?

Again, please explain that. Does it not compile? Or do you always read zero or whatever?

ElCaron:
The ports are only available on Arduinos with SMD AVR. You have probably selected a board with a DIL AVR in the IDE.

I compiled a code with analogReads of A6 and A7 for the Uno and the compiler did not complain (IDE 1.6.7).

irfiee:
Yes sterretje, I cannot have access to ADC6 and ADC7. Do you have any thought ?

You still do not say what you mean by "access".

These two pins can only be used for analogRead, they will not respond to digitalRead nor digitalWrite like the other analogue inputs will.

ElCaron:
The ports are only available on Arduinos with SMD AVR. You have probably selected a board with a DIL AVR in the IDE.

Even though the boards that break out ADC6 and ADC7 use a different variant, the only difference it makes is in the definition of NUM_ANALOG_INPUTS, which isn't used anywhere in the core (and rarely anywhere else).
https://github.com/arduino/ArduinoCore-avr/blob/master/variants/eightanaloginputs/pins_arduino.h:

#include "../standard/pins_arduino.h"
#undef NUM_ANALOG_INPUTS
#define NUM_ANALOG_INPUTS 8

Thank you all for yours reply.

I think robtillaart is right. We just need to download and add eightanaloginputs <pins_arduino.h> library that would give access to get readings from the pins ADC6 and ADC7, which can be define simply as A6 and A7 rerpectively.

https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/variants/eightanaloginputs/pins_arduino.h

That is not what he said, and you already have that header. It seems pretty impossible to help you, though given that you keep ignoring all attempts.