breadboard
Example project · Builds & projects

Uno R4 · tone and header interrupts

D5 generates a short 1 kHz tone waveform. Physical wires feed D2’s CHANGE interrupt and D3’s FALLING interrupt; Serial prints their edge counts. Probe D5 in Scope and reset the simulation to capture the burst again.

The Uno R4 · tone and header interrupts circuit as rendered by the simulator

What's on the bench

  • Arduino Uno R4
  • Battery
  • Resistor

How it's wired

  • Battery · pos→Arduino Uno R4 · 5v
  • Battery · neg→Arduino Uno R4 · gnd
  • Arduino Uno R4 · d5→Resistor · a
  • Resistor · b→Arduino Uno R4 · gnd2
  • Arduino Uno R4 · d5→Arduino Uno R4 · d2
  • Arduino Uno R4 · d5→Arduino Uno R4 · d3

The code

This Arduino C++ sketch lives in the Code tab; sign in and press Compile & upload to build real firmware for the emulated board.

// Breadboard UNO R4 P5 external-interrupt and tone acceptance fixture.

static volatile uint32_t d2Edges = 0;
static volatile uint32_t d3Edges = 0;

static void onD2() {
  ++d2Edges;
}

static void onD3() {
  ++d3Edges;
}

void setup() {
  Serial.begin(115200);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(2), onD2, CHANGE);
  attachInterrupt(digitalPinToInterrupt(3), onD3, FALLING);
  tone(5, 1000, 20);
}

void loop() {
  static uint32_t last = 0;
  if (millis() - last >= 25) {
    last = millis();
    noInterrupts();
    uint32_t d2 = d2Edges;
    uint32_t d3 = d3Edges;
    interrupts();
    Serial.print("irq ");
    Serial.print(d2);
    Serial.print(' ');
    Serial.println(d3);
  }
}

Firmware licence

Notice: this firmware uses the LGPL-licensed Arduino core library

arduino-unor4wifi-irq-tone.bin is statically linked with ArduinoCore-renesas 1.6.0, in Breadboard's port of its UNO R4 WiFi variant to Renesas FSP 5.3.0. Parts of that core are licensed under the GNU Lesser General Public License, version 2.1 or (at your option) any later version ("the Library"). Breadboard distributes this firmware under terms that permit you to modify the work for your own use and to reverse engineer it for debugging such modifications.

Related projects