dht22.ino
The DHT 1-wire protocol is microsecond-timed: the Adafruit library runs on the STM32F1 core but delay calibration depends on CPU speed. Systematic failures flag that tuning.
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 DHT22 + 10 kΩ resistor (3-pin module: built in).
Wiring
VDD 3.3 V, DATA on PA4 with 10 kΩ pull-up, GND. Short wires (< 30 cm): the protocol is noise-sensitive.
How it works
readTemperature timestamps pulses via micros(); on fast cores the library switches to DWT/timer. NaNs mean a corrupted frame, not necessarily a dead 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
Add the previous sketch's OLED display, or the alert threshold on a buzzer.
dht22.ino
// DHT22 sur PA4 — bibliotheque DHT sensor library (Adafruit).
#include <DHT.h>
#define DHTPIN PA4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
unsigned long precedent = 0;
void setup() {
Serial.begin(115200);
dht.begin();
Serial.println("DHT22 sur GD32 (2 s mini entre lectures)");
}
void loop() {
if (millis() - precedent < 2000) return;
precedent = millis();
float t = dht.readTemperature();
float h = dht.readHumidity();
if (isnan(t) || isnan(h)) { Serial.println("trame perdue"); return; }
Serial.printf("T=%.1f C HR=%.1f %%\n", t, h);
// Le GD32 etant 100x plus rapide, la bibliotheque doit calibrer ses
// microsecondes : si les lectures echouent toutes, voir note doc.
}