potentiometre.ino

GD32F103 (GigaDevice) — chip + Blue-Pill-compatible boards · File : potentiometre.ino · Language : Arduino · Use case : Visualiser un potentiomètre sur l'ADC 12 bits

The GD32 ADC is natively 12 bits: the potentiometer reads in 4096 levels, and the "raw ; volts" format feeds the IDE serial plotter directly. Averaging 8 samples cleans the noise.

Hardware required

A GD32F103C8T6 development board (Cortex-M3 at 108 MHz, Blue Pill pin-to-pin compatible), powered at 3.3 V/5 V, with an ST-Link or serial adapter. 1 10 kΩ potentiometer (wiper on PA0, legs to 3.3 V and GND).

Wiring

Wiper on PA0; never more than 3.3 V on an ADC pin (the board is 3.3 V, not 5 V).

How it works

analogReadResolution(12) makes the native width explicit; the ADC clock is tuned for accuracy. Software averaging divides noise by √8 — enough for a slow sensor. With Arduino: install the « STM32F1 » core (Roger Clark, board manager) and pick the « GD32F103C » board; the user LED is PC13 (active LOW). In C: GD32F10x firmware library + ST-Link.

Going further

Drive the previous sketch's breathing with this potentiometer (map() from ADC to duty).

potentiometre.ino

// Potentiometre sur PA0 — ADC 12 bits du GD32 (0-4095 sur 0-3,3 V).
void setup() {
  Serial.begin(115200);
  analogReadResolution(12);     // explicite : 12 bits natifs du GD32
  analogReadFrequency(PA0, 200000);  // horloge ADC 200 kHz
}

void loop() {
  long brut = 0;
  for (int i = 0; i < 8; i++) brut += analogRead(PA0);
  brut /= 8;
  float volts = brut * 3.3f / 4095.0f;
  Serial.print(brut);
  Serial.print(" ; ");
  Serial.println(volts, 3);     // format trace du traceur serie
  delay(50);
}

← Back to the board