Question

I have a the ADK2012 arduino due-like device. I am using google's copy of the arduino software, and I can compile and run various sketches without trouble.

I've got an LM35 that I've hooked up to an analog input. By default, the reference voltage is 5 volts. This seems to work fine, but I would like to use a different analogReference value, as documented here:

http://arduino.cc/en/Reference/AnalogReference

Unfortunately, I'm having some trouble. When I use DEFAULT or EXTERNAL like this:

analogReference(DEFAULT);

I get this when I compile:

AnalogReadSerial.cpp: In function 'void setup()':
AnalogReadSerial:12: error: invalid conversion from 'int' to 'eAnalogReference'
AnalogReadSerial:12: error: initializing argument 1 of 'void analogReference(eAnalogReference)'

If I try to set it to INTERNAL, INTERNAL1V1, or INTERNAL2V56, I get errors like:

AnalogReadSerial.cpp: In function 'void setup()':
AnalogReadSerial:12: error: 'INTERNAL' was not declared in this scope

I'm at a bit of a dead end here. I'm not familiar enough with Arduino or Wiring to know if this is a problem with the supplied device configuration, or an actual limitation of the physical hardware, or a bug or incompatibility internally.

It's unfortunate that the hardware I'm using is relatively rare, and doesn't seem to have much documentation. I'd appreciate suggestions on where to start looking to fix this issue.

Was it helpful?

Solution 2

It turns out (now that the arduino docs have caught up, 5 months later) that the answer is:

These devices operate at 3.3 volts natively, and so the analogReference function isn't enabled.

The Due’s analog inputs pins measure from ground to a maximum value of 3.3V. Applying more then 3.3V on the Due’s pins will damage the SAM3X chip. The analogReference() function is ignored on the Due.

http://arduino.cc/en/Main/ArduinoBoardDue

OTHER TIPS

It seems that analogRefence() expects a something like enum as argument

and the the definitions in arduino.h is a int

do you have the latest arduino ide (rev 1.0.1)

I've made a toolchain for arduino, and linked that to another ide, (netbeans)
so debugging the arduino core is quite simple.

haven't found the bug, (it works in the latest arduino ide);

anyway, for the arduino mega (ADK) you can do this in the new ide,
if this works, then you have selected the wrong board (tools>>board>>arduino mega2560 or mega ADK)

analogReference(0); //EXTERNAL
analogReference(1); //DEFAULT
analogReference(2); //INTERNAL1V1
analogReference(3); //INTERNAL2V56

Arduino 2 doesn't permit EXTERNAL reference. You will find this in the SAM library (...sam\cores\arduino\wiring_analog.h ):

typedef enum _eAnalogReference
{
    AR_DEFAULT,
} eAnalogReference ;

And external is not permitted.

The µC use always external refernce, but is Hardware connected to 3.3V, if you want to use AREF you can change a 0-Ohm resistor on the board.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top