What is a DAC?
A DAC (Digital-to-Analog Converter) converts a number in your code into a real voltage on a pin. Write 2048 and the pin outputs ~1.65V. Write 4095 and you get ~3.3V. Write 0 and you get 0V. It’s the opposite of an ADC, which reads voltages and turns them into numbers.
Why This Matters for Your Projects
Section titled “Why This Matters for Your Projects”DACs are used for generating audio signals, creating precise reference voltages, and producing smooth waveforms. Your phone uses a DAC every time it plays audio through a speaker.
But here’s the thing: the ESP32-S3 does not have a built-in DAC. The original ESP32 had two 8-bit DAC channels, but Espressif removed them from the S3. So if you need true analog output on your tinyCore, you have three options — and for most projects, one of them will work perfectly.
Option 1: PWM (Good Enough for Most Things)
Section titled “Option 1: PWM (Good Enough for Most Things)”The ESP32-S3 has 8 PWM channels (called LEDC) that rapidly flip a pin between 3.3V and 0V. By controlling what percentage of time the pin stays HIGH (the duty cycle), you create an average voltage. Set 50% duty and the average output is ~1.65V.
This isn’t true analog — it’s a fast square wave. But for many tasks, it works great:
- LED dimming — your eyes can’t see the switching
- Motor speed control — the motor’s inertia smooths it out
- Servo positioning — servos read the pulse width, not voltage
- Fan speed — same as motors
Where PWM falls short: audio output, precision voltage references, and circuits that need a steady, clean voltage. The rapid switching creates noise that analog-sensitive circuits don’t like.
Rule of thumb: if what you’re controlling has physical inertia (mechanical, thermal, or visual), PWM works. If a downstream circuit cares about the actual instantaneous voltage, you need a real DAC.
See What is PWM? for a deep dive.
Option 2: I2S for Audio
Section titled “Option 2: I2S for Audio”For audio output specifically, the ESP32-S3 has 2 I2S peripherals designed for streaming digital audio to external amplifier or DAC chips. Pair it with a MAX98357A (I2S amplifier, drives speakers directly) or a PCM5102A (stereo I2S DAC for higher-quality audio) and you get proper audio playback — 16/24-bit resolution at 44.1 or 48 kHz.
The tinySpeak HAT uses this approach. See What is I2S? for details.
Option 3: External DAC Chip for Precise Voltage
Section titled “Option 3: External DAC Chip for Precise Voltage”For general-purpose analog output, you can plug a small external DAC into the tinyCore’s QWIIC/I2C port. The most popular choice:
MCP4725 (I2C, 12-bit)
Section titled “MCP4725 (I2C, 12-bit)”The beginner favorite. One output channel, 4,096 voltage steps, dead-simple I2C interface. Available as a QWIIC/STEMMA breakout — just plug in a cable, no breadboard needed.
#include <Wire.h>#include <Adafruit_MCP4725.h>
Adafruit_MCP4725 dac;
void setup() { pinMode(6, OUTPUT); digitalWrite(6, HIGH); // power on I2C bus Wire.begin(3, 4); // tinyCore I2C pins dac.begin(0x62); // default address on Adafruit boards}
void loop() { dac.setVoltage(2048, false); // ~1.65V (half of 3.3V) delay(1000); dac.setVoltage(4095, false); // ~3.3V (full scale) delay(1000); dac.setVoltage(0, false); // 0V delay(1000);}The setVoltage() function takes a value from 0 to 4095. Output voltage = (value / 4096) × 3.3V. The second parameter (false) means “don’t save to EEPROM” — keep it false for normal use.
Install the library: Sketch → Include Library → Manage Libraries → search “Adafruit MCP4725” → Install.
Other External DAC Options
Section titled “Other External DAC Options”| Chip | Interface | Resolution | Best For |
|---|---|---|---|
| MCP4725 | I2C | 12-bit (4,096 steps) | General purpose, easy setup |
| MCP4921 | SPI | 12-bit | Faster updates, waveform generation |
| PCM5102A | I2S | 32-bit stereo | High-quality audio playback |
Quick Reference: PWM vs External DAC
Section titled “Quick Reference: PWM vs External DAC”| PWM (built-in) | External DAC (MCP4725) | |
|---|---|---|
| Cost | Free | ~$5 for breakout |
| Good for | LEDs, motors, fans, servos | Precision voltage, waveforms, analog circuits |
| Output | Pulsed square wave | Clean, steady analog voltage |
| Resolution | Up to 14-bit | 12-bit |
| Setup | One line of code | I2C library + QWIIC cable |
Learn More
Section titled “Learn More”- What is PWM? — the most common DAC alternative on the ESP32-S3
- What is I2S? — audio output through external DAC/amplifier chips
- What is an ADC? — the opposite: reading voltages into numbers
- What is I2C? — the protocol used by external DAC breakouts