entree-analogique.ino

Arduino UNO R4 WiFi · File : entree-analogique.ino · Language : Arduino · Use case : Exploiter la résolution 14 bits de l'ADC du R4

The R4 ADC reaches 14 bits (16384 levels) versus 10 on classic Unos: the 32-sample sliding window yields very stable voltages, ideal for a precision sensor or amplified gauge bridge.

Hardware

An Arduino UNO R4 WiFi (Renesas RA4M1 @ 14 MHz + companion ESP32-S3 Wi-Fi/BLE, 12x8 LED matrix, RGB LED) powered by USB or 6-24 V. 1 10 kΩ potentiometer to test (or analog sensor 0-3.3 V).

Wiring

Wiper to A1, potentiometer ends to 3V3 and GND. Max input 3.3 V (mind 5 V circuits).

How it works

analogReadResolution(14) exploits the converter's full resolution; the sliding window divides noise by √32. Conversion uses a 3.3 V reference.

Running it

Arduino IDE 2.x with the « Arduino UNO R4 Boards » core, « Arduino UNO R4 WiFi » board, serial port then Upload. The ESP32-S3 coprocessor updates separately if the IDE asks.

Variants

Switch to the internal reference (analogReference) to measure beyond 3.3 V, or sample with timer + DMA for audio.

entree-analogique.ino

// ADC 14 bits du R4 (0..16383) avec moyenne glissante.
const int CANAL = A1;
const int NB = 32;

uint16_t fenetre[NB];
int idx = 0;
bool plein = false;
unsigned long t0 = 0;

void setup() {
  analogReadResolution(14);   // 14 bits natifs du RA4M1
  Serial.begin(9600);
}

void loop() {
  if (millis() - t0 < 100) return;
  t0 = millis();

  fenetre[idx] = analogRead(CANAL);
  idx = (idx + 1) % NB;
  if (idx == 0) plein = true;
  int n = plein ? NB : idx;
  if (!n) return;

  long somme = 0;
  for (int i = 0; i < n; i++) somme += fenetre[i];
  long moyenne = somme / n;

  float tension = moyenne * 3.3 / 16383.0;
  Serial.print(F("brut=")); Serial.print(moyenne);
  Serial.print(F("  U=")); Serial.print(tension, 4);
  Serial.println(F(" V"));
}

← Back to the board