It's easy to play audio on the Fruit Jam with CircuitPython thanks to the built-in TLV320DAC3100 DAC and the Adafruit_CircuitPython_FruitJam module. This module allows you to easily write Python code to play audio and wave files (.wav) from the headphone jack or speaker connector.
Fruit Jam Speaker Wiring
The Fruit Jam supports playing audio out of the 3.5mm stereo jack to headphones or powered speakers, or using a small mono 4-8Ω speaker connected to the JST-SH speaker connector.
CircuitPython Usage
To use with CircuitPython, you need to first install the Adafruit_CircuitPython_FruitJam 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 folders and files:
- adafruit_bitmap_font/
- adafruit_bus_device/
- adafruit_display_text/
- adafruit_esp32spi/
- adafruit_fruitjam/
- adafruit_imageload/
- adafruit_io/
- adafruit_minimqtt/
- adafruit_portalbase/
- adafruit_connection_manager.mpy
- adafruit_fakerequests.mpy
- adafruit_miniqr.mpy
- adafruit_ntp.mpy
- adafruit_pixelbuf.mpy
- adafruit_requests.mpy
- adafruit_sdcard.mpy
- adafruit_ticks.mpy
- neopixel.mpy
- simpleio.mpy
- adafruit_simplemath.mpy
- adafruit_tlv320.mpy
# SPDX-FileCopyrightText: 2025 Liz Clark, Tim Cocks for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import array
import math
import time
import audiocore
from adafruit_fruitjam.peripherals import Peripherals
fruit_jam = Peripherals()
# use headphones
fruit_jam.dac.headphone_output = True
fruit_jam.dac.dac_volume = -10 # dB
# or use speaker
# fruit_jam.dac.speaker_output = True
# fruit_jam.dac.speaker_volume = -20 # dB
# generate a sine wave
tone_volume = 0.5
frequency = 440
sample_rate = fruit_jam.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:
fruit_jam.audio.stop()
time.sleep(1)
fruit_jam.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, Tim Cocks for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import audiocore
from adafruit_fruitjam.peripherals import Peripherals
fruit_jam = Peripherals()
# use headphones
fruit_jam.dac.headphone_output = True
fruit_jam.dac.dac_volume = -10 # dB
# or use speaker
# fruit_jam.dac.speaker_output = True
# fruit_jam.dac.speaker_volume = -20 # dB
# set sample rate & bit depth, use bclk
fruit_jam.dac.configure_clocks(sample_rate=44100, bit_depth=16)
with open("StreetChicken.wav", "rb") as wave_file:
wav = audiocore.WaveFile(wave_file)
print("Playing wav file!")
fruit_jam.audio.play(wav)
while fruit_jam.audio.playing:
pass
print("Done!")
Once the code starts running, you'll hear the Street Chicken WAV file play once.
Page last edited October 03, 2025
Text editor powered by tinymce.