-
-
Notifications
You must be signed in to change notification settings - Fork 237
External DAC
The best sound quality can be achieved with an external digital to analog converter. Here is a quick overview of the most popular I2S DAC breakout boards that can be found.
The default pins are defined for each microcontroller architecture in the AudioConfig.h.
The framework uses e.g. the following default pins for an ESP32:
- PIN_I2S_BCK = 14
- PIN_I2S_WS = 15
- PIN_I2S_DATA_OUT = 22
So the output goes to GPIO 14, 15 and 22. Please double check the actual settings in AudioConfig.h for your Processor. There you can also modify the pins and other settings that will apply to all your sketches. You can also configure I2S in your individual sketch. The available settings are processor specific, so consult the documentation.
Recommendation: I recommend to define the pins and other settings in your sketch!
auto config = i2sStream.defaultConfig(TX_MODE);
config.pin_bck = 14;
config.pin_ws = 15;
config.pin_data = 22;
// config.pin_mck = 0; // optional master clock pin
// config.i2s_format = I2S_STD_FORMAT; // default format
// config.is_master = true; // default esp32 is master
i2sStream.begin(config);
Use TX_MODE if you want to transmit (write) audio data from the processor to the external DAC. With RXTX_MODE you can receive and transmit at the same time if you have a audio codec chip that supports this function (see chapter Audio Boards). If you don't specify anything RXTX_MODE is used.
This DAC is very easy to use: Just connect the 3 I2S pins and the power and everything works as expected, w/o changing the configuration!
DAC | ESP32 | RP2040 |
---|---|---|
BCK | BCK (GPIO14) | GPIO26 |
DATA | OUT (GPIO22) | GPIO28 |
WS | WS (GPIO15) | GPIO27 |
GND | GND | GND |
GND | GND | GND |
VDD | 5V | VBUS |
It seems that most DACs from Adafruit have a different byte order then what the ESP32 expects and therefore you need to indicate the communication format as I2S_LSB:
auto config = i2sStream.defaultConfig(TX_MODE);
config.i2s_format = I2S_LSB_FORMAT;
i2sStream.begin(config);
DAC | ESP32 | RP2040 |
---|---|---|
VIN | 5V | VBUS |
GND | GND | GND |
WSEL | WS (GPIO14) | GPIO27 |
DIN | OUT (GPIO22) | GPIO28 |
BCLK | BCK (GPIO15) | GPIO26 |
I was struggling quite a big to have this one working, because it needs some additional connections:
DAC | ESP32 | RP2040 |
---|---|---|
VCC | 5V | VBUS |
GND | GND | GND |
BCK | BCK GPIO14 | GPIO26 |
DIN | OUT GPIO22 | GPIO28 |
LCK | WS GPIO15 | GPIO27 |
FMT | GND | GND |
XMT | 3V (**) | 3V3 |
- ** - or another GPIO PIN which is set to high
- DMP - De-emphasis control for 44.1kHz sampling rate(1): Off (Low) / On (High)
- FLT - Filter select : Normal latency (Low) / Low latency (High)
- SCL - System clock input (probably SCL on your board).
- FMT - Audio format selection : I2S (Low) / Left justified (High)
- XMT - Soft mute control(1): Soft mute (Low) / soft un-mute (High)
This DAC is very easy to use: Just connect the 3 I2S pins and the power and everything works as expected, w/o changing the configuration! SCK to ground seems to reduce noise.
DAC | ESP32 | RP2040 |
---|---|---|
SCK | GND | GND |
BCK | BCK (GPIO14) | GPIO26 |
DIN | OUT (GPIO22) | GPIO28 |
LCK | WS (GPIO15) | GPIO27 |
GND | GND | GND |
VIN | 5V | VBUS |
Solder Bridges:
- H1L: FLT - Filter select : Normal latency (Low) / Low latency (High)
- H2L: DEMP - De-emphasis control for 44.1kHz sampling rate: Off (Low) / On (High)
- H3L: XSMT - Soft mute control: Soft mute (Low) / soft un-mute (High)
- H4L: FMT - Audio format selection : I2S (Low) / Left justified (High)
Normally it's working w/o any soldering! However if you encounter any issues I suggest that you try connect the solder bridges FLT:Low, DEMP: Low, XSMT: High, FMT: Low (or add some additional connections to these pins)
This module is sold as high end HIFI DAC.(e.g. to be used with a Rasperry PI).
DAC | ESP32 | RP2040 |
---|---|---|
GND | GND | GND |
5V | 5V | VBUS |
BCK | BCK (GPIO14) | GPIO26 |
LRCK | WS (GPIO15) | GPIO27 |
DATA | OUT (GPIO22) | GPIO28 |
MCLK | - | - |
The masterclock is optional and does not need to be connected.
This DAC is quite difficult to use because it does not support the output of 16 bit samples. You need to resample your output to use 32 bits e.g. with the help of a NumberFormatConverterStream:
I2SStream i2s; // final output of decoded stream
NumberFormatConverterStream fc(i2s); // write the 16bit data to fc
// conigure 16 -> 32 bit
fc.begin(16, 32);
It's a pity that this module does not provide any I2C pins which would allow to configure the es9018.
This module provides an I2S DAC with a mono amplifier and you just need to connect a speaker.
auto config = i2sStream.defaultConfig(TX_MODE);
// config.i2s_format = I2S_STD_FORMAT;
i2sStream.begin(config);
DAC | ESP32 | RP2040 |
---|---|---|
VIN | 5V (or 3.3V) | VBUS |
GND | GND | GND |
LRC | WS (GPIO14) | GPIO27 |
BCLK | BCK (GPIO15) | GPIO26 |
DIN | OUT (GPIO22) | GPIO28 |
It seems that most DACs from Adafruit have a different byte order then what the ESP32 expects and therefore you need to indicate the communication format as I2S_LSB:
auto config = i2sStream.defaultConfig(TX_MODE);
config.i2s_format = I2S_LSB_FORMAT;
i2sStream.begin(config);
DAC | ESP32 | RP2040 |
---|---|---|
VIN | 5V (or 3.3V) | VBUS |
GND | GND | GND |
LRC | WS (GPIO14) | GPIO27 |
BCLK | BCK (GPIO15) | GPIO26 |
DIN | OUT (GPIO22) | GPIO28 |
See the next chapter