Skip to content

Commit 458277c

Browse files
committed
MAX98357 code and fritzings
1 parent 4981a59 commit 458277c

8 files changed

+83
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import time
2+
import array
3+
import math
4+
import audioio
5+
import board
6+
import audiobusio
7+
8+
tone_volume = 0.1 # Increase this to increase the volume of the tone.
9+
frequency = 440 # Set this to the Hz of the tone you want to generate.
10+
length = 8000 // frequency
11+
sine_wave = array.array("H", [0] * length)
12+
for i in range(length):
13+
sine_wave[i] = int((1 + math.sin(math.pi * 2 * i / 18)) * tone_volume * (2 ** 15))
14+
15+
# For Feather M0 Express, ItsyBitsy M0 Express, Metro M0 Express
16+
audio = audiobusio.I2SOut(board.D1, board.D0, board.D9)
17+
# For Feather M4 Express
18+
# audio = audiobusio.I2SOut(board.D1, board.D10, board.D11)
19+
# For Metro M4 Express
20+
# audio = audiobusio.I2SOut(board.D3, board.D9, board.D8)
21+
sine_wave_sample = audioio.RawSample(sine_wave)
22+
23+
while True:
24+
audio.play(sine_wave_sample, loop=True)
25+
time.sleep(1)
26+
audio.stop()
27+
time.sleep(1)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import audioio
2+
import board
3+
import audiobusio
4+
5+
wave_file = open("StreetChicken.wav", "rb")
6+
wave = audioio.WaveFile(wave_file)
7+
8+
# For Feather M0 Express, ItsyBitsy M0 Express, Metro M0 Express
9+
audio = audiobusio.I2SOut(board.D1, board.D0, board.D9)
10+
# For Feather M4 Express
11+
# audio = audiobusio.I2SOut(board.D1, board.D10, board.D11)
12+
# For Metro M4 Express
13+
# audio = audiobusio.I2SOut(board.D3, board.D9, board.D8)
14+
15+
while True:
16+
audio.play(wave)
17+
while audio.playing:
18+
pass
67.1 KB
Binary file not shown.
114 KB
Binary file not shown.

Adafruit_MAX98357/I2S_Test_Script.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import board
2+
import audiobusio
3+
from microcontroller import Pin
4+
5+
6+
def is_hardware_i2s(bit_clock, word_select, data):
7+
try:
8+
p = audiobusio.I2SOut(bit_clock, word_select, data)
9+
p.deinit()
10+
return True
11+
except ValueError:
12+
return False
13+
14+
15+
def get_unique_pins():
16+
exclude = ['NEOPIXEL', 'APA102_MOSI', 'APA102_SCK']
17+
pins = [pin for pin in [
18+
getattr(board, p) for p in dir(board) if p not in exclude]
19+
if isinstance(pin, Pin)]
20+
unique = []
21+
for p in pins:
22+
if p not in unique:
23+
unique.append(p)
24+
return unique
25+
26+
27+
for bit_clock_pin in get_unique_pins():
28+
for word_select_pin in get_unique_pins():
29+
for data_pin in get_unique_pins():
30+
if bit_clock_pin is word_select_pin or bit_clock_pin is data_pin or word_select_pin\
31+
is data_pin:
32+
continue
33+
else:
34+
if is_hardware_i2s(bit_clock_pin, word_select_pin, data_pin):
35+
print("Bit clock pin:", bit_clock_pin, "\t Word select pin:", word_select_pin,
36+
"\t Data pin:", data_pin)
37+
else:
38+
pass
97.8 KB
Binary file not shown.

Adafruit_MAX98357/MetroM0MAX98357.fzz

150 KB
Binary file not shown.

Adafruit_MAX98357/MetroM4MAX98357.fzz

160 KB
Binary file not shown.

0 commit comments

Comments
 (0)