ADC with 5V external reference on M0

Dear all,

I am having difficulty reading 0-5V with the adc of my arduino M0 (Arduino pc software 1.6.5). 0-3.3V is no problem, but when I use 5V as an external reference (5V of the board attached directly to AREF), the values I am getting are always lower than 746 of 1024.

For setting the external reference I use:

analogReference((eAnalogReference)EXTERNAL);

Without casting I get an error... Is this a bug? Makes me worry that something is not quite right with the library.

When attaching 3.3V to the reference (AREF), I get a reading of 1023 at 3.3-5Volt as expected. When attaching 5V to the reference I get at most (when 5V applied to A0/adc) 743.

For reading out the adc I use:

sensorValue = analogRead(ReadInPin); Serial.println(sensorValue);

delay(400);

Does anyone have an idea what going on?

Thanks! Bas

Dear All,

I’ve been looking for the answer in the wiring_analog.c and arduino.h files. Especially I want to know what type External is and what value (with type) it is assigned.

I have trouble reading those files because I do not know what flag is defined for zero processors: e.g. AVR_ATtiny24 or AVR_ATmega1280.

I would expect something like AVR_ATSAMD21 or so, but that does not seem to exist. Is there a list where I can look thus up?

I’ve tried outputing the following values (all that are used for defining “EXTERNAL”), but the compiler did not know any of them (for my zero project):
AVR_ATtiny24
AVR_ATtiny44
AVR_ATtiny84
AVR_ATtiny25
AVR_ATtiny45
AVR_ATtiny85
AVR_ATmega1280
AVR_ATmega2560
AVR_ATmega1284
AVR_ATmega1284P
AVR_ATmega644
AVR_ATmega644A
AVR_ATmega644P
AVR_ATmega644PA

It seems that I am looking in the wrong place or that EXTERNAL is not defined (which I do not believe because I see a change when using analogReference…

I appreciate the help!
Bas

The Zero is a 3.3V system. All ADC values must be between 0V and 3.3V

It is similar with the 5V UNO. All ADC values must be between 0V and 5V.

If you want to measure a larger voltage, use a potential divider. e.g. two 4k7 resistors will divide by 2.
This will apply to your external reference too.

In practice, your internal references are plenty good enough.

David.

Thanks David!

Now it's clear why it did not work.

Bas

Here are the correct analog reference values for Zero:

wiring_analog.h

typedef enum _eAnalogReference
{
  AR_DEFAULT,
  AR_INTERNAL,
  AR_EXTERNAL,
  AR_INTERNAL1V0,
  AR_INTERNAL1V65,
  AR_INTERNAL2V23
} eAnalogReference ;