melodie.ino
tone() on the GIGA rides a hardware timer: the buzzer plays the melody while the M7 does something else. The audio feedback of a workshop machine is three wires away.
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 passive 3.3 V buzzer (pin + GND) or piezo.
Wiring
Buzzer + to D9, − to GND. An active buzzer (built-in oscillator) plays one sound only: go passive.
How it works
tone(pin, freq, duration) sets the timer to square output and stops itself; the following delay lets the note breathe. Several timers = polyphony possible. 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
A CAN alert beep (error frame = low tone), or an ADC-driven musical memo.
melodie.ino
// Buzzer passif entre D9 et GND — tone() du core GIGA.
const int BUZZER = D9;
struct Note { int freq; int ms; };
Note air[] = {
{659, 300}, {659, 300}, {659, 300}, {523, 900}, // mi mi mi do
{659, 600}, {784, 30}, {392, 600}, {523, 600},
};
const int NB = sizeof(air) / sizeof(Note);
void setup() {
pinMode(BUZZER, OUTPUT);
Serial.begin(115200);
Serial.println("Appui bouton D2 = musique");
pinMode(D2, INPUT_PULLUP);
}
void loop() {
if (digitalRead(D2) == LOW) {
for (int i = 0; i < NB; i++) {
tone(BUZZER, air[i].freq, air[i].ms);
delay(air[i].ms + 30);
}
}
}