diff --git a/Metro_RP2350_Examples/CircuitPython_I2S_Tone/code.py b/Metro_RP2350_Examples/CircuitPython_I2S_Tone/code.py new file mode 100644 index 000000000..2c874b9fb --- /dev/null +++ b/Metro_RP2350_Examples/CircuitPython_I2S_Tone/code.py @@ -0,0 +1,30 @@ +# 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.A0, board.A1, board.A2) + +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) diff --git a/Metro_RP2350_Examples/CircuitPython_I2S_Wav/StreetChicken.wav b/Metro_RP2350_Examples/CircuitPython_I2S_Wav/StreetChicken.wav new file mode 100644 index 000000000..55d4eb0f2 Binary files /dev/null and b/Metro_RP2350_Examples/CircuitPython_I2S_Wav/StreetChicken.wav differ diff --git a/Metro_RP2350_Examples/CircuitPython_I2S_Wav/code.py b/Metro_RP2350_Examples/CircuitPython_I2S_Wav/code.py new file mode 100644 index 000000000..1061ca78b --- /dev/null +++ b/Metro_RP2350_Examples/CircuitPython_I2S_Wav/code.py @@ -0,0 +1,22 @@ +# 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.A0, board.A1, board.A2) + +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!") diff --git a/Metro_RP2350_Examples/CircuitPython_PSRAM/code.py b/Metro_RP2350_Examples/CircuitPython_PSRAM/code.py new file mode 100644 index 000000000..50f7b2e09 --- /dev/null +++ b/Metro_RP2350_Examples/CircuitPython_PSRAM/code.py @@ -0,0 +1,5 @@ +# SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries +# SPDX-License-Identifier: MIT +import gc + +print(gc.mem_free()) diff --git a/Metro_RP2350_Examples/CircuitPython_PWM_Audio_Multi_MP3/code.py b/Metro_RP2350_Examples/CircuitPython_PWM_Audio_Multi_MP3/code.py new file mode 100644 index 000000000..fc60fbc45 --- /dev/null +++ b/Metro_RP2350_Examples/CircuitPython_PWM_Audio_Multi_MP3/code.py @@ -0,0 +1,26 @@ +# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries +# SPDX-License-Identifier: MIT +""" +CircuitPython multiple MP3 playback example. +Plays two MP3 files consecutively, once time each. +""" + +import board +import audiomp3 +import audiopwmio + +audio = audiopwmio.PWMAudioOut(board.A0) + +mp3files = ["slow.mp3", "happy.mp3"] + +with open(mp3files[0], "rb") as mp3: + decoder = audiomp3.MP3Decoder(mp3) + + for filename in mp3files: + with open(filename, "rb") as decoder.file: + audio.play(decoder) + print("Playing:", filename) + while audio.playing: + pass + +print("Done playing!") diff --git a/Metro_RP2350_Examples/CircuitPython_PWM_Audio_Multi_MP3/happy.mp3 b/Metro_RP2350_Examples/CircuitPython_PWM_Audio_Multi_MP3/happy.mp3 new file mode 100755 index 000000000..58fd59724 Binary files /dev/null and b/Metro_RP2350_Examples/CircuitPython_PWM_Audio_Multi_MP3/happy.mp3 differ diff --git a/Metro_RP2350_Examples/CircuitPython_PWM_Audio_Multi_MP3/slow.mp3 b/Metro_RP2350_Examples/CircuitPython_PWM_Audio_Multi_MP3/slow.mp3 new file mode 100755 index 000000000..39ceecdf6 Binary files /dev/null and b/Metro_RP2350_Examples/CircuitPython_PWM_Audio_Multi_MP3/slow.mp3 differ diff --git a/Metro_RP2350_Examples/CircuitPython_PWM_Audio_Single_MP3/code.py b/Metro_RP2350_Examples/CircuitPython_PWM_Audio_Single_MP3/code.py new file mode 100644 index 000000000..db70b9a6c --- /dev/null +++ b/Metro_RP2350_Examples/CircuitPython_PWM_Audio_Single_MP3/code.py @@ -0,0 +1,20 @@ +# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries +# SPDX-License-Identifier: MIT +""" +CircuitPython single MP3 playback example. +Plays a single MP3 once. +""" +import board +import audiomp3 +import audiopwmio + +audio = audiopwmio.PWMAudioOut(board.A0) + +with open("slow.mp3", "rb") as mp3_file: + decoder = audiomp3.MP3Decoder(mp3_file) + + audio.play(decoder) + while audio.playing: + pass + +print("Done playing!") diff --git a/Metro_RP2350_Examples/CircuitPython_PWM_Audio_Single_MP3/slow.mp3 b/Metro_RP2350_Examples/CircuitPython_PWM_Audio_Single_MP3/slow.mp3 new file mode 100755 index 000000000..39ceecdf6 Binary files /dev/null and b/Metro_RP2350_Examples/CircuitPython_PWM_Audio_Single_MP3/slow.mp3 differ diff --git a/Metro_RP2350_Examples/CircuitPython_SDCard_ListFiles/code.py b/Metro_RP2350_Examples/CircuitPython_SDCard_ListFiles/code.py new file mode 100644 index 000000000..be5386756 --- /dev/null +++ b/Metro_RP2350_Examples/CircuitPython_SDCard_ListFiles/code.py @@ -0,0 +1,56 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + +""" +CircuitPython Essentials SD Card Read Demo + +""" + +import os +import digitalio +import busio +import board +import storage +import adafruit_sdcard + +# The SD_CS pin is the chip select line. +SD_CS = board.SD_CS + +# Connect to the card and mount the filesystem. +cs = digitalio.DigitalInOut(SD_CS) +sdcard = adafruit_sdcard.SDCard(busio.SPI(board.SD_SCK, board.SD_MOSI, board.SD_MISO), cs) +vfs = storage.VfsFat(sdcard) +storage.mount(vfs, "/sd") + +# Use the filesystem as normal! Our files are under /sd + +# This helper function will print the contents of the SD +def print_directory(path, tabs=0): + for file in os.listdir(path): + stats = os.stat(path + "/" + file) + filesize = stats[6] + isdir = stats[0] & 0x4000 + + if filesize < 1000: + sizestr = str(filesize) + " bytes" + elif filesize < 1000000: + sizestr = "%0.1f KB" % (filesize / 1000) + else: + sizestr = "%0.1f MB" % (filesize / 1000000) + + prettyprintname = "" + for _ in range(tabs): + prettyprintname += " " + prettyprintname += file + if isdir: + prettyprintname += "/" + print("{0:<40} Size: {1:>10}".format(prettyprintname, sizestr)) + + # recursively print directory contents + if isdir: + print_directory(path + "/" + file, tabs + 1) + + +print("Files on filesystem:") +print("====================") +print_directory("/sd") diff --git a/Metro_RP2350_Examples/CircuitPython_SDCard_Write/code.py b/Metro_RP2350_Examples/CircuitPython_SDCard_Write/code.py new file mode 100644 index 000000000..596c2b75f --- /dev/null +++ b/Metro_RP2350_Examples/CircuitPython_SDCard_Write/code.py @@ -0,0 +1,41 @@ +# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +""" +CircuitPython Essentials SD Card Write Demo +REMOVE THIS LINE AND ALL BELOW IT BEFORE SUBMITTING TO LEARN +Update CHIP_SELECT_PIN to match the CS pin on your board. + +For example, for the Metro ESP32-S3, you would use: board.SD_CS. +""" + +import time +import adafruit_sdcard +import board +import busio +import digitalio +import microcontroller +import storage + +# The SD_CS pin is the chip select line. +SD_CS = board.SD_CS + +# Connect to the card and mount the filesystem. +cs = digitalio.DigitalInOut(SD_CS) +sdcard = adafruit_sdcard.SDCard(busio.SPI(board.SD_SCK, board.SD_MOSI, board.SD_MISO), cs) +vfs = storage.VfsFat(sdcard) +storage.mount(vfs, "/sd") + +# Use the filesystem as normal! Our files are under /sd + +print("Logging temperature to filesystem") +# append to the file! +while True: + # open file for append + with open("/sd/temperature.txt", "a") as f: + t = microcontroller.cpu.temperature + print("Temperature = %0.1f" % t) + f.write("%0.1f\n" % t) + # file is saved + time.sleep(1)