MAX98357 code and fritzings
This commit is contained in:
parent
4981a59ce6
commit
458277c4db
8 changed files with 83 additions and 0 deletions
27
Adafruit_MAX98357/CircuitPython_I2S_Tone.py
Executable file
27
Adafruit_MAX98357/CircuitPython_I2S_Tone.py
Executable file
|
|
@ -0,0 +1,27 @@
|
|||
import time
|
||||
import array
|
||||
import math
|
||||
import audioio
|
||||
import board
|
||||
import audiobusio
|
||||
|
||||
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((1 + math.sin(math.pi * 2 * i / 18)) * tone_volume * (2 ** 15))
|
||||
|
||||
# For Feather M0 Express, ItsyBitsy M0 Express, Metro M0 Express
|
||||
audio = audiobusio.I2SOut(board.D1, board.D0, board.D9)
|
||||
# For Feather M4 Express
|
||||
# audio = audiobusio.I2SOut(board.D1, board.D10, board.D11)
|
||||
# For Metro M4 Express
|
||||
# audio = audiobusio.I2SOut(board.D3, board.D9, board.D8)
|
||||
sine_wave_sample = audioio.RawSample(sine_wave)
|
||||
|
||||
while True:
|
||||
audio.play(sine_wave_sample, loop=True)
|
||||
time.sleep(1)
|
||||
audio.stop()
|
||||
time.sleep(1)
|
||||
18
Adafruit_MAX98357/CircuitPython_I2S_Wave.py
Executable file
18
Adafruit_MAX98357/CircuitPython_I2S_Wave.py
Executable file
|
|
@ -0,0 +1,18 @@
|
|||
import audioio
|
||||
import board
|
||||
import audiobusio
|
||||
|
||||
wave_file = open("StreetChicken.wav", "rb")
|
||||
wave = audioio.WaveFile(wave_file)
|
||||
|
||||
# For Feather M0 Express, ItsyBitsy M0 Express, Metro M0 Express
|
||||
audio = audiobusio.I2SOut(board.D1, board.D0, board.D9)
|
||||
# For Feather M4 Express
|
||||
# audio = audiobusio.I2SOut(board.D1, board.D10, board.D11)
|
||||
# For Metro M4 Express
|
||||
# audio = audiobusio.I2SOut(board.D3, board.D9, board.D8)
|
||||
|
||||
while True:
|
||||
audio.play(wave)
|
||||
while audio.playing:
|
||||
pass
|
||||
BIN
Adafruit_MAX98357/FeatherM0MAX98357.fzz
Normal file
BIN
Adafruit_MAX98357/FeatherM0MAX98357.fzz
Normal file
Binary file not shown.
BIN
Adafruit_MAX98357/FeatherM4MAX98357.fzz
Normal file
BIN
Adafruit_MAX98357/FeatherM4MAX98357.fzz
Normal file
Binary file not shown.
38
Adafruit_MAX98357/I2S_Test_Script.py
Normal file
38
Adafruit_MAX98357/I2S_Test_Script.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import board
|
||||
import audiobusio
|
||||
from microcontroller import Pin
|
||||
|
||||
|
||||
def is_hardware_i2s(bit_clock, word_select, data):
|
||||
try:
|
||||
p = audiobusio.I2SOut(bit_clock, word_select, data)
|
||||
p.deinit()
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
|
||||
def get_unique_pins():
|
||||
exclude = ['NEOPIXEL', 'APA102_MOSI', 'APA102_SCK']
|
||||
pins = [pin for pin in [
|
||||
getattr(board, p) for p in dir(board) if p not in exclude]
|
||||
if isinstance(pin, Pin)]
|
||||
unique = []
|
||||
for p in pins:
|
||||
if p not in unique:
|
||||
unique.append(p)
|
||||
return unique
|
||||
|
||||
|
||||
for bit_clock_pin in get_unique_pins():
|
||||
for word_select_pin in get_unique_pins():
|
||||
for data_pin in get_unique_pins():
|
||||
if bit_clock_pin is word_select_pin or bit_clock_pin is data_pin or word_select_pin\
|
||||
is data_pin:
|
||||
continue
|
||||
else:
|
||||
if is_hardware_i2s(bit_clock_pin, word_select_pin, data_pin):
|
||||
print("Bit clock pin:", bit_clock_pin, "\t Word select pin:", word_select_pin,
|
||||
"\t Data pin:", data_pin)
|
||||
else:
|
||||
pass
|
||||
BIN
Adafruit_MAX98357/ItsyBitsyM0MAX98357.fzz
Normal file
BIN
Adafruit_MAX98357/ItsyBitsyM0MAX98357.fzz
Normal file
Binary file not shown.
BIN
Adafruit_MAX98357/MetroM0MAX98357.fzz
Normal file
BIN
Adafruit_MAX98357/MetroM0MAX98357.fzz
Normal file
Binary file not shown.
BIN
Adafruit_MAX98357/MetroM4MAX98357.fzz
Normal file
BIN
Adafruit_MAX98357/MetroM4MAX98357.fzz
Normal file
Binary file not shown.
Loading…
Reference in a new issue