Arduino Mega 2560 Analog Pins 8-15 w/ Arduino 0022

Hey Everybody,

So I am only a moderate Arduino user and just started using the Mega for the first time.

I am trying to utilize the Analog pins from A0 - A10, and I get these error messages:

"error: 'A8' was not declared in this scope" "error: 'A9' was not declared in this scope" "error: 'A10' was not declared in this scope"

(I do know that A0-A7 are the standard Analog Pins while A8-A15 are extra which come with the Mega, but I don't know why there is a problem).

I have them listed in the code as:

int sensorPin8 = A8; // select the input pin for Row 7 Detector int sensorPin9 = A9; // select the input pin for Row 8 Detector int sensorPin10 = A10; // select the input pin for Rotation Detector

I am note sure if there is something I need to download to utilize the mega, or if there was a driver that was supposed to be installed (my computer didn't recognize anything), or if I am just ignorant of what I am supposed to be doing.

I haven't found anything answering this so far, though I have seen that people with past versions of the Mega and arduino which had the same problems, but I didn't know how to apply their troubleshooting with my versions.

If someone could point me in the right direction for getting these working I would appreciate it! Thanks!

Hello
Why dont you try the example and see if it works well
Then you can take conclusions or adapt your sketch based on this example

/*
Analog Input
Demonstrates analog input by reading an analog sensor on analog pin 0 and
turning on and off a light emitting diode(LED) connected to digital pin 13.
The amount of time the LED will be on and off depends on
the value obtained by analogRead().

The circuit:

  • Potentiometer attached to analog input 0

  • center pin of the potentiometer to the analog pin

  • one side pin (either one) to ground

  • the other side pin to +5V

  • LED anode (long leg) attached to digital output 13

  • LED cathode (short leg) attached to ground

  • Note: because most Arduinos have a built-in LED attached
    to pin 13 on the board, the LED is optional.

Created by David Cuartielles
Modified 4 Sep 2010
By Tom Igoe

This example code is in the public domain.

*/

int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor

void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
}

void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for milliseconds:
delay(sensorValue);
}

From the code snippet I presume A8 etc are #defined macros - hence you have prob missed out a #include that includes those definitions for the ‘mega’

Hey guys,

Thanks for the advice. It was a few other dumb errors on my part and a need to update the driver, got it working. Thanks for the help though!

Go to Tools/Board and select the board you are using.

here are all the errors I get if I select a wrong board:

demokit.cpp: In function 'void init_buttons()': demokit:60: error: 'A8' was not declared in this scope demokit:61: error: 'A9' was not declared in this scope demokit.cpp: In function 'void setup()': demokit:131: error: 'A8' was not declared in this scope demokit:132: error: 'A9' was not declared in this scope demokit.cpp: In function 'void loop()': demokit:207: error: 'A8' was not declared in this scope demokit:215: error: 'A9' was not declared in this scope demokit.cpp: In function 'void init_joystick(int)': demokit:290: error: 'A9' was not declared in this scope demokit:293: error: 'A10' was not declared in this scope demokit:296: error: 'A11' was not declared in this scope demokit.cpp: In function 'char joystick_interrupt()': demokit:365: error: 'A10' was not declared in this scope

valimdj: Go to Tools/Board and select the board you are using.

here are all the errors I get if I select a wrong board:

demokit.cpp: In function 'void init_buttons()': demokit:60: error: 'A8' was not declared in this scope demokit:61: error: 'A9' was not declared in this scope demokit.cpp: In function 'void setup()': demokit:131: error: 'A8' was not declared in this scope demokit:132: error: 'A9' was not declared in this scope demokit.cpp: In function 'void loop()': demokit:207: error: 'A8' was not declared in this scope demokit:215: error: 'A9' was not declared in this scope demokit.cpp: In function 'void init_joystick(int)': demokit:290: error: 'A9' was not declared in this scope demokit:293: error: 'A10' was not declared in this scope demokit:296: error: 'A11' was not declared in this scope demokit.cpp: In function 'char joystick_interrupt()': demokit:365: error: 'A10' was not declared in this scope

my thought as well. Very sneaky setting.

hello, the same case happened to me. Try to click in "tools" (arduino application) and then "board" and select the correct model you are working with. That was de solution in my case. Good luck!

yes loraule answer is correct, go to tools, Arduino board and select Arduino mega 2560 from their then the error will be ok.