🛠 Potentiomètre et sortie DAC sur la prise audio du GIGA R1
Objectives
Discover the analog world of the GIGA R1: read a voltage using an analog-to-digital converter (3 ADCs on the STM32H747XI) and generate a signal with a digital-to-analog converter (2 DACs, 12 bits). A specific feature of this board: the 3.5 mm audio jack is wired to DAC0, DAC1, and A7 — a real sound project without a shield.
Hardware
- 1 Arduino GIGA R1 WiFi board
- 1 10 kΩ potentiometer
- 1 speaker or headphones on the built-in 3.5 mm jack
- Jumper wires, USB-C cable
Complete code
// GIGA R1 WiFi — son d'onde en dent de scie sur DAC0 (prise jack), hauteur = A0
#include <Arduino.h>
const int KNOB_PIN = A0; // potentiomètre 0..3,3 V
const int DAC_PIN = DAC0; // sortie DAC reliée à la prise jack embarquée
uint32_t phase = 0;
void setup {
Serial.begin(115200);
analogWriteResolution(12); // le DAC du STM32H747XI est 12 bits (0..4095)
Serial.println("Tournez le potentiometre");
}
void loop {
uint32_t pas = 1 + map(analogRead(KNOB_PIN), 0, 4095, 0, 63);
phase = (phase + pas) & 0xFFF; // retour à zéro sur 12 bits
analogWrite(DAC_PIN, phase); // dent de scie -> son modulable
}
Potentiometer wiring: wiper to A0, one end to 3.3 V, the other to GND.
Expected verification
Turning the potentiometer progressively increases the pitch of the sound generated in the headphones. By displaying analogRead(A0) on the Serial Monitor, the value follows the wiper from 0 to approximately 4095.
Common errors
- Forgetting
analogWriteResolution(12): the DAC is then underutilized and the signal is coarser. - Direct speaker without amplification: the DAC level is low; a small amplifier or headphones provide much better results.
- Documented ADC mapping bug:
analogRead(A12)used to return the value of A8 (bug #758, closed); re-test your ADC pins after each core update. - Powering the potentiometer with 5 V: the ADC accepts a maximum of 3.3 V, causing the measurement to clip.
Other tutorials for this board
- Faire clignoter la LED de l'Arduino GIGA R1
- Bouton poussoir et console série sur le GIGA R1
- Piloter un micro-servo avec la PWM du GIGA R1
- Connecter un capteur I2C sur le GIGA R1
- Publier des données en MQTT/HTTP via le Wi-Fi du GIGA R1
- Programmer les deux cœurs M7 et M4 du GIGA R1 et les faire communiquer
Code examples for this board
clignotante.inoArduinobouton.inoArduinorespiration.inoArduinoanalogique.inoArduinodac-onde.inoArduinooled-i2c.inoArduino