Read analog input of Arduino Due board

The Arduino Due Board has 12 analog inputs (pins from A0 to A11), each of which can provide 12 bits of resolution (i.e. 4096 different values). By default, the resolution of the readings is set at 10 bits, for compatibility with other Arduino boards. It is possible to change the resolution of the ADC with analogReadResolution(). 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.

Analog input pins on Arduino Due Board
Analog input pins on Arduino Due Board

Example to read from Analog Input:

int analogInputA0 = A0;
int varA0;

void setup() {
Serial.begin(9600);
analogReadResolution(12); //set ADC resolution to 12 bits

}

void loop() {
varA0 = analogRead(analogInputA0); //read ADC input
Serial.println(varA0, HEX); //print as HEX
delay(1000);
}

Read Analog Input on Arduino Due
Read Analog Input on Arduino Due


If the code compiled with error: 'analogReadResolution' was not declared in this scope.
Check if you select the correct Tools -> Board.

Comments

Popular posts from this blog

Application Note of Cortex-M3 Embedded Software Development