analogReadResolution was not declared in this scope

Hello,

I’m Trying this code(Click Here)

And i got this message:

exit status 1
‘analogReadResolution’ was not declared in this scope

But i am wondering what is wrong, I have the right board selected:
Wich is “Arduino Diecimila or Duemilanove w/ ATmega168” or “Arduino Duemilanove w/ ATmega328”,
But still wrong.

Knowing that my Serial value communication is okay, and analog pins are inputs per defect, can’t see the problem in this code…

void setup() {
  // open a serial connection
  Serial.begin(9600);
}

void loop() {
  // read the input on A0 at default resolution (10 bits)
  // and send it out the serial connection
  analogReadResolution(10);
  Serial.print("ADC 10-bit (default) : ");
  Serial.print(analogRead(A0));

  // change the resolution to 12 bits and read A0
  analogReadResolution(12);
  Serial.print(", 12-bit : ");
  Serial.print(analogRead(A0));

  // change the resolution to 16 bits and read A0
  analogReadResolution(16);
  Serial.print(", 16-bit : ");
  Serial.print(analogRead(A0));

  // change the resolution to 8 bits and read A0
  analogReadResolution(8);
  Serial.print(", 8-bit : ");
  Serial.println(analogRead(A0));

  // a little delay to not hog Serial Monitor
  delay(100);
}

This is on Youtube, it exposes part of the solution:
Half of the solution(Click Here)

SOLUTION
To solve the problem of code compilation, and to enable the option shown in the video, you need to go to Tools->Board Manager-> and download the Arduino Sam Boards (32 bits ARM Cortex-M3) by Arduino, Once you download it, the option “Arduino Due (Programming port)” will appear at the end of the Board Manager list, click that option, and then the code will compile.

I had searched the option shown in the video in the card manager, but i dind’t, so messing around in the IDE, specifically, the board manager, reading several options about Arduino DUE, I tried this one, and it worked perfectly!
Now the code runs. Go try it.
I also tried this before posting, but didn’t find the solution, so i posted it, hoping for help, but i kept trying on my own, until i solved it. I’m leaving this post right here so others can know the solution in the future.

Thanks to @Andr.oid Eric for posting that video, it helped.

analogReadResolution.ino (806 Bytes)

Brian, code goes within code tags, not quotes. I can't imagine any code that contains smiley faces wearing sunglasses runs.

In your code you are trying to call a function called analogReadResolution. However it does not appear anywhere in the code you posted, nor do you include any libraries so as the error so clearly states, 'analogReadResolution' was not declared.

But i am wondering what is wrong, I have the right board selected: Wich is "Arduino Diecimila or Duemilanove w/ ATmega168" or "Arduino Duemilanove w/ ATmega328", But still wrong.

You do have the wrong board selected, the page you referenced specifies:

The Due, Zero and MKR Family boards have 12-bit ADC capabilities that can be accessed by changing the resolution to 12. analogReadResolution() is an extension of the Analog API for the Arduino Due, Zero and MKR Family.

The Due uses a ARM Cortex-M3, not the ATmega168/368. Zero and MKR Family are ARM Cortex-M0.

https://store.arduino.cc/usa/arduino-due

david_2018: You do have the wrong board selected, the page you referenced specifies:

The Due uses a ARM Cortex-M3, not the ATmega168/368. Zero and MKR Family are ARM Cortex-M0.

https://store.arduino.cc/usa/arduino-due

What do you mean? what is this for then?

// change the resolution to 16 bits and read A0 analogReadResolution(16);

Did you read the entire page that you got the code from? The notes at the bottom specify:

Notes and Warnings

If you set the analogReadResolution() value to a value higher than your board’s capabilities, the Arduino will only report back at its highest resolution, padding the extra bits with zeros.

For example: using the Due with analogReadResolution(16) will give you an approximated 16-bit number with the first 12 bits containing the real ADC reading and the last 4 bits padded with zeros.

If you set the analogReadResolution() value to a value lower than your board’s capabilities, the extra least significant bits read from the ADC will be discarded.

Using a 16 bit resolution (or any resolution higher than actual hardware capabilities) allows you to write sketches that automatically handle devices with a higher resolution ADC when these become available on future boards without changing a line of code.

My original quote from the webpage was just to show that the sketch was written for the Due, Zero, and MKR family of boards, the part about changing the resolution to 12-bit was just the remainder of the sentence. I later corrected the quote to an earlier line from the webpage that was a bit less confusing.

david_2018: Did you read the entire page that you got the code from? The notes at the bottom specify:

Yes, i did, I already changed the values, besides, the code is made for Arduino DUE, I published this topic because i researched first, and saw that the topic was not here, and i saw in google many people searching the same problem, so, what better place to post it than the official Arduino forum?

Yes, I saw that you changed your text, but still... not the solution.

Brian_v: Yes, I saw that you changed your text, but still... not the solution.

OK, then since the board selection being incorrect is not the solution, could you please enlighten me as to the correct solution?

the code is made for Arduino DUE,

The DUE and the Duemillanova are two very different animals. You have selected the Duemillanova as the board and analogReadResolution() is not part of that boards code base.

You need to use the Board Manager in the IDE and download the cores for the Due. In the ide window follow your way Tools>Board>Boards Manager.

cattledog: The DUE and the Duemillanova are two very different animals. You have selected the Duemillanova as the board and analogReadResolution() is not part of that boards code base.

You need to use the Board Manager in the IDE and download the cores for the Due. In the ide window follow your way Tools>Board>Boards Manager.

It appears the OP has edited his original post and given that as the solution, not sure when it was changed.