Go Down

Topic: analogReadResolution(12) - will not upload to Due (Read 3122 times) previous topic - next topic

AlexJK

Jul 27, 2013, 01:39 pm Last Edit: Jul 28, 2013, 11:44 am by AlexJK Reason: 1
I am new to Arduino and enjoying the experience. I am trying to set the analogReadResolution() of a Due to 12 bit as explained in this tutorial http://arduino.cc/en/Reference/AnalogReadResolution but get the following error:

Code: [Select]
In function 'void loop()':
sketch_jul28a:9: error: 'analogReadResolution' was not declared in this scope


I have tried both software versions 1.0.5 and 1.5.2, the board is correctly set to Due and I have been able to successfully use the board at normal 10 bit resolution in other tutorials. The code is as follows, any help or guidance appreciated:

Code: [Select]
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);
}

Nick Gammon

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

wmvdw

What board is selected under 'Tools'->'Board'? I also encountered the problem once, in my case the software selected another board, instead of my Arduino Due.

AlexJK

Just back from vacation, apologies for the late reply. I double checked and Due is selected.

Still scratching my head with this one. To have the extra resolution would be really useful and it's infuriating to think that the board should run this sketch but I cannot work out why it doesn't.

Palliser

I just tested your code and is running OK in my Due. I noticed the reference for analogReadResolution is contained in the following files:
wiring_analog.c
wiring_analog.h
These files are located at:

Quote
..\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\cores\arduino


Check that out. Regards!

AlexJK

I checked the wiring_analog.c and .c files - they are both present. I also found that if I choose Arduino Due (Programming Port) or Arduino Due (Native USB Port) the sketch compiles without any errors BUT I cannot upload as the board is not found. When I revert to Arduino Due I can upload other sketches but still cannot get the analogReadResolution(12) to compile.

Palliser

Hello AlexJK,
May be this is redundant but remember that the most of the time you switch between USB ports in Due, the active virtual COM port changes. Thus, every time you switch between port verify in Tools->Serial Port that you active virtual COM port is checked. Also, what do you mean with "the board is not found"?
It could be useful if you post here the verbata you are getting after trying to upload your sketch. Are you getting something like:

Quote
Binary sketch size: 10,796 bytes (of a 524,288 byte maximum) - 2% used
Forcing reset using 1200bps open/close on port COM12
PORTS {COM12, } / {COM12, } => {}
PORTS {COM12, } / {COM12, } => {}
PORTS {COM12, } / {COM12, } => {}
PORTS {COM12, } / {COM12, } => {}
PORTS {COM12, } / {COM12, } => {}
PORTS {COM12, } / {COM12, } => {}
PORTS {COM12, } / {COM12, } => {}
PORTS {COM12, } / {COM12, } => {}
PORTS {COM12, } / {COM12, } => {}
PORTS {COM12, } / {COM12, } => {}
PORTS {COM12, } / {COM12, } => {}
PORTS {COM12, } / {COM12, } => {}
PORTS {COM12, } / {COM12, } => {}
PORTS {COM12, } / {COM12, } => {}
PORTS {COM12, } / {COM12, } => {}
PORTS {COM12, } / {COM12, } => {}
PORTS {COM12, } / {COM12, } => {}
PORTS {COM12, } / {COM12, } => {}
PORTS {COM12, } / {COM12, } => {}
PORTS {COM12, } / {COM12, } => {}
Uploading using selected port: COM12
C:\Users\Myself\Downloads\arduino-1.5.2-windows\arduino-1.5.2/hardware/tools/bossac.exe --port=COM12 -U true -e -w -v -b C:\Users\Myself\AppData\Local\Temp

\build7800558003391814885.tmp/sketch_aug16a.cpp.bin -R
No device found on COM12
?
Regards!

Docedison

#7
Sep 11, 2013, 06:08 am Last Edit: Sep 11, 2013, 06:14 am by Docedison Reason: 1
Quote
I have tried both software versions 1.0.5 and 1.5.2, the board is correctly set to Due and I have been able to successfully use the board at normal 10 bit resolution in other tutorials. The code is as follows, any help or guidance appreciated:

software versions 1.0.5 doesn't support the Due... I would think that "analogReadResolution(12)" must fail to compile on ver 1.0.5 unconditionally and should as well in ver 1.5.2, If you had the wrong board selected... The ATMega 328P-PU and for that matter all the ATMega parts only are capable of 10 bits of A/D resolution.

Doc
--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Go Up