CircuitPython
It's easy to use the TLV320DAC3100 with CircuitPython, and the Adafruit_CircuitPython_TLV320 module. This module allows you to easily write Python code to configure this I2S DAC.
CircuitPython Microcontroller Wiring
First wire up the I2S DAC to your board exactly as follows. The following is the DAC wired to a Feather RP2040 with the headphone output:
- Board 3.3V to DAC VIN (red wire)
- Board GND to DAC GND (black wire)
- Board SCL to DAC SCL (yellow wire)
- Board SDA to DAC SDA (blue wire)
- Board D9 to DAC BCK (green wire)
- Board D10 to DAC WSEL (orange wire)
- Board D11 to DAC DIN (white wire)
- DAC 3.5mm output to headphones
- Board D12 to DAC RST (purple wire)
CircuitPython Usage
To use with CircuitPython, you need to first install the Adafruit_CircuitPython_TLV320 library, and its dependencies, into the lib folder on your CIRCUITPY drive. Then you need to update code.py with the example script.
Thankfully, we can do this in one go. In the example below, click the Download Project Bundle button below to download the necessary libraries and the code.py file in a zip file. Extract the contents of the zip file, and copy the entire lib folder and the code.py file to your CIRCUITPY drive.
Your CIRCUITPY/lib folder should contain the following folder and file:
- adafruit_bus_device/
- adafruit_tlv320.mpy
# SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import array
import math
import time
import audiobusio
import audiocore
import board
import digitalio
import adafruit_tlv320
# Reset the DAC before use
reset_pin = digitalio.DigitalInOut(board.D12)
reset_pin.direction = digitalio.Direction.OUTPUT
reset_pin.value = False # Set low to reset
time.sleep(0.1) # Pause 100ms
reset_pin.value = True # Set high to release from reset
i2c = board.I2C()
dac = adafruit_tlv320.TLV320DAC3100(i2c)
# set sample rate & bit depth, use bclk
dac.configure_clocks(sample_rate=44100, bit_depth=16)
# use headphones
dac.headphone_output = True
dac.dac_volume = -10 # dB
# or use speaker
# dac.speaker_output = True
# dac.speaker_volume = -20 # dB
if "I2S_BCLK" and "I2S_WS" in dir(board):
audio = audiobusio.I2SOut(board.I2S_BCLK, board.I2S_WS, board.I2S_DIN)
else:
audio = audiobusio.I2SOut(board.D9, board.D10, board.D11)
# generate a sine wave
tone_volume = 0.5
frequency = 440
sample_rate = dac.sample_rate
length = sample_rate // frequency
sine_wave = array.array("h", [0] * length)
for i in range(length):
sine_wave[i] = int((math.sin(math.pi * 2 * i / length)) * tone_volume * (2**15 - 1))
sine_wave_sample = audiocore.RawSample(sine_wave, sample_rate=sample_rate)
while True:
audio.stop()
time.sleep(1)
audio.play(sine_wave_sample, loop=True)
time.sleep(1)
Once the code starts running, you'll begin hearing a one second 440Hz tone, every other second.
Then, update the code.py file with the code below:
# SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import audiobusio
import audiocore
import board
import adafruit_tlv320
i2c = board.I2C()
dac = adafruit_tlv320.TLV320DAC3100(i2c)
# set sample rate & bit depth, use bclk
dac.configure_clocks(sample_rate=44100, bit_depth=16)
# use headphones
dac.headphone_output = True
dac.dac_volume = -15 # dB
# or use speaker
# dac.speaker_output = True
# dac.speaker_volume = -10 # dB
audio = audiobusio.I2SOut(board.D9, board.D10, board.D11)
with open("StreetChicken.wav", "rb") as wave_file:
wav = audiocore.WaveFile(wave_file)
print("Playing wav file!")
audio.play(wav)
while audio.playing:
pass
print("Done!")
Once the code starts running, you'll hear the Street Chicken WAV file play once.
Page last edited September 25, 2025
Text editor powered by tinymce.