-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
CircuitPython version and board name
Adafruit CircuitPython 10.0.3-1-g92170768f6 on 2025-10-22; Adafruit Fruit Jam with rp2350bCode/REPL
import math
import supervisor
from adafruit_fruitjam.peripherals import Peripherals
from adafruit_fruitjam.peripherals import request_display_config
import array
import audiocore
import time
import displayio
from adafruit_display_shapes.circle import Circle
def play_tone(frequency, duration, volume=0.5):
"""Play a tone at the specified frequency for the specified duration
Args:
frequency (int/float): Frequency in Hz (e.g., 440 for A4)
duration (float): Duration in seconds
volume (float): Volume level from 0.0 to 1.0 (default 0.5)
"""
# Get the sample rate from the DAC
sample_rate = fruit_jam.dac.sample_rate
# Calculate length of one period of the waveform
length = sample_rate // int(frequency)
# Generate a sine wave for one period
sine_wave = array.array("h", [0] * length)
for i in range(length):
sine_wave[i] = int((math.sin(math.pi * 2 * i / length)) * volume * (2**15 - 1))
# Create a RawSample from the sine wave
sine_wave_sample = audiocore.RawSample(sine_wave, sample_rate=sample_rate)
# Play the tone
#audio = audiobusio.I2SOut(board.I2S_BCLK, board.I2S_WS, board.I2S_DIN)
fruit_jam.audio.play(sine_wave_sample, loop=True)
time.sleep(duration)
fruit_jam.audio.stop()
fruit_jam = Peripherals(audio_output="speaker") # or "headphone"
fruit_jam.dac.speaker_output = True
fruit_jam.dac.dac_volume = -20 # Digital volume (-63.5 to 24.0 dB)
fruit_jam.dac.speaker_volume = -5 # Analog volume (-78.3 to 0 dB)
fruit_jam.dac.speaker_gain = 18 # Amplifier gain (6, 12, 18, or 24 dB)
request_display_config(320, 240)
display = supervisor.runtime.display
group = displayio.Group()
display.root_group = group
for i in range(20):
for j in range(10):
group.append(Circle((i*10)+10,(j*10)+10,5,fill=0xffff00))
play_tone(660,1.)Behavior
During the playback of the tone, the DVI Output goes blank for a second or two. As you reduce the playback length the chance of encountering the blank screen decreases but even for very short tones (.05 seconds) the screen will occasionally go blank.
Description
The play_tone function was written by @TheKitty as part of her recent update to the breakout game for Fruit Jam. It works great but apparently audiobusio I2SOut is hanging up the DVI output and causing the screen to periodically blank out.
Additional information
It does appear that Displayio is somehow related as it was difficult to recreate the issue without having a lot of displayio objects (circles in my demonstration code) on the screen.
I didn't actually run the above demonstration code as code.py but pasted it into the REPL using CTRL-E mode.