breadboard
Example project · Analog & circuits

Uno R4 · pot-controlled DAC sine

Turn the pot to change the A1 ADC reading and the A0 DAC sine amplitude. Probe A0 in Scope. The real DAC clips near the supply limits; the official core also briefly releases its output between updates.

The Uno R4 · pot-controlled DAC sine circuit as rendered by the simulator

What's on the bench

  • Arduino Uno R4
  • Battery
  • Resistor
  • Trim Pot

How it's wired

  • Battery · pos→Arduino Uno R4 · 5v
  • Battery · neg→Arduino Uno R4 · gnd
  • Arduino Uno R4 · 5v→Trim Pot · a
  • Arduino Uno R4 · gnd2→Trim Pot · b
  • Trim Pot · wiper→Arduino Uno R4 · a1
  • Arduino Uno R4 · a0→Resistor · a
  • Resistor · b→Arduino Uno R4 · gnd2

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.

// SPDX-License-Identifier: MIT
// First-party UNO R4 example: A1 sets the amplitude of the A0 DAC sine.
static const int16_t kSine[] = {
  0, 399, 783, 1137, 1447, 1702, 1891, 2008,
  2047, 2008, 1891, 1702, 1447, 1137, 783, 399,
  0, -399, -783, -1137, -1447, -1702, -1891, -2008,
  -2047, -2008, -1891, -1702, -1447, -1137, -783, -399
};
void setup() {
  Serial.begin(115200);
  analogReadResolution(14);
  analogWriteResolution(12);
}
void loop() {
  const int level = analogRead(A1);
  Serial.print("adc14 ");
  Serial.println(level);
  for (int16_t sample : kSine) {
    const int code = 2048 + (int32_t)sample * level / 16383;
    analogWrite(DAC, code);
    delay(1);
  }
}

Firmware licence

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

arduino-unor4wifi-analog-wave.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