Skip to content

Commit

Permalink
circuitpython demos for PCM510x
Browse files Browse the repository at this point in the history
wav and tone demos for PCM510x I2S DAC
  • Loading branch information
BlitzCityDIY committed Mar 5, 2025
1 parent a11851d commit 636ec27
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
29 changes: 29 additions & 0 deletions PCM510x_Examples/CircuitPython_Tone/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
# SPDX-License-Identifier: MIT
"""
CircuitPython I2S Tone playback example.
Plays a tone for one second on, one
second off, in a loop.
"""
import time
import array
import math
import audiocore
import board
import audiobusio

audio = audiobusio.I2SOut(board.D9, board.D10, board.D11)

tone_volume = 0.1 # Increase this to increase the volume of the tone.
frequency = 440 # Set this to the Hz of the tone you want to generate.
length = 8000 // 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)

while True:
audio.play(sine_wave_sample, loop=True)
time.sleep(1)
audio.stop()
time.sleep(1)
Binary file not shown.
21 changes: 21 additions & 0 deletions PCM510x_Examples/CircuitPython_WAV/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
# SPDX-License-Identifier: MIT
"""
CircuitPython I2S WAV file playback.
Plays a WAV file once.
"""
import audiocore
import board
import audiobusio

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!")

0 comments on commit 636ec27

Please sign in to comment.