analogique.ino
The GIGA's 12-bit ADC samples at 50 Hz with a 32-sample sliding average: the serial plotter shows a clean curve, ready for a real analog sensor (0-3.3 V).
Hardware required
An Arduino Giga R1 board (STM32H747 dual-core M7 at 480 MHz + M4, 76 I/O pins, 2 DACs, FDCAN) powered over USB-C or 5-24 V. 1 0-3.3 V analog sensor (potentiometer wiper, conditioned module output).
Wiring
Signal on A0, common GND. Never exceed 3.3 V: the ADC is not 5 V tolerant.
How it works
The 32-value circular buffer smooths without allocation; analogReadResolution aligns width to the STM32H7 native. Sampling at 50 Hz leaves the M7 free. In the Arduino IDE, install the « Arduino Zephyr-based Boards » (or Mbed) platform, select « Arduino Giga R1 », then Upload. 3.3 V logic.
Going further
Trigger an out-of-range alert, or send the average over CAN (dedicated sketch).
analogique.ino
// Capteur analogique sur A0 : ADC 12 bits + moyenne glissante.
const int CANAL = A0;
const int FENETRE = 32;
uint16_t tampon[FENETRE];
int tete = 0;
unsigned long precedent = 0;
void setup() {
analogReadResolution(12); // 0..4095 pour 0..3,3 V
Serial.begin(115200);
}
void loop() {
if (millis() - precedent < 20) return; // 50 Hz
precedent = millis();
tampon[tete] = analogRead(CANAL);
tete = (tete + 1) % FENETRE;
uint32_t somme = 0;
for (int i = 0; i < FENETRE; i++) somme += tampon[i];
float moyenne = (float)somme / FENETRE;
float volts = moyenne * 3.3f / 4095.0f;
Serial.printf("%6.1f %.3f V\n", moyenne, volts); // traceur serie
}