🛠 Lire un potentiomètre avec le vrai ADC 12 bits de la Due

Arduino Due · debutant · Schéma : IMG-due-debutant-2-potentiometre-adc-12-bits.svg — Arduino Due avec un potentiomètre 10 kΩ câblé sur A0 (3,3 V / A0 / GND), moniteur série affichant des valeurs 0–4095 après analogReadResolution(12), puce ADC 12 bits annotée.

Objectives

Leverage the analog side selling point of the Due: its analog-to-digital converter is 12 bits (0–4095), compared to 10 bits on AVR Arduinos. You will wire a potentiometer, read its position… and discover the core's documented pitfall: analogRead returns 10-bit values (0–1023) by default to maintain AVR compatibility. You must explicitly request 12-bit resolution using analogReadResolution(12).

Hardware

Complete code

// Lecture 12 bits d'un potentiomètre sur A0
// Fils : potentiomètre broche gauche -> 3V3, curseur -> A0, broche droite -> GND

void setup {
  analogReadResolution(12);   // sans cette ligne : 0..1023 (défaut 10 bits !)
  SerialUSB.begin(115200);    // moniteur sur le port Native
}

void loop {
  int brut = analogRead(A0);            // 0..4095 en 12 bits
  float tension = brut * 3.3f / 4095.0f; // base 3,3 V (Vref de la Due)
  SerialUSB.printf("brut=%d  soit %.3f V\n", brut, tension);
  delay(50);
}

Expected verification

When turning the potentiometer to its limits, the raw value should sweep approximately from 0 to 4095, and the calculated voltage from 0 to 3.3 V. If you comment out analogReadResolution(12), the range drops back to 0–1023: this proves the core's 10-bit default. The voltage follows the wiper position linearly.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials