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
# SPDX-License-Identifier: Unlicense """ CircuitPython I2S MP3 playback example. Plays an MP3 once. Remove this line and all of the following docstring content before submitting to the Learn repo. Update the three I2S pins to match the wiring chosen for the microcontroller. If you are unsure of a proper I2S pin combination, run the pin combination script found here: https://adafru.it/i2s-pin-combo-finder Update the following pin names to a viable pin combination: * BIT_CLOCK_PIN * WORD_SELECT_PIN * DATA_PIN """ import board import audiomp3 import audiobusio audio = audiobusio.I2SOut(board.BIT_CLOCK_PIN, board.WORD_SELECT_PIN, board.DATA_PIN) mp3 = audiomp3.MP3Decoder(open("slow.mp3", "rb")) audio.play(mp3) while audio.playing: pass print("Done playing!")
"""Modified CircuitPython Essentials Audio Out MP3 Example""" """See Logans Run Hand Jewel:""" """https://learn.adafruit.com/led-in-you-hand-logans-run-life-clock/3d-printing?view=all#overview""" import time import board import neopixel import audiocore import audiobusio import digitalio from audiomp3 import MP3Decoder mp3 = open("still-alive.mp3", "rb") decoder = MP3Decoder(mp3) audio = audiobusio.I2SOut(board.GP10, board.GP11, board.GP9) pixpin = board.GP0 numpix = 7 wait = 3 # 1/2 second color fade duration # defaults to RGB|GRB Neopixels strip = neopixel.NeoPixel(pixpin, numpix, brightness=1, auto_write=False) # uncomment the following 3 line for RGBW Neopixels # strip = neopixel.NeoPixel( # pixpin, numpix, bpp=4, brightness=.3, auto_write=True # ) # Linear interpolation of y value given min/max x, min/max y, and x position.
# SPDX-License-Identifier: MIT import time import array import math import audiocore 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( (math.sin(math.pi * 2 * i / length)) * tone_volume * (2**15 - 1)) # 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 = audiocore.RawSample(sine_wave) while True: audio.play(sine_wave_sample, loop=True) time.sleep(1) audio.stop() time.sleep(1)
hour = Line(114, 128, 114, 128, 0xFFFFFF) splash.append(hour) minute = Line(114, 128, 114, 128, 0xFFFFFF) splash.append(minute) second = Line(114, 128, 114, 128, 0x808080) splash.append(second) time.sleep(1) # Audio setup wave_file = open("alarm.wav", "rb") wave = audiocore.WaveFile(wave_file) audio = audiobusio.I2SOut(board.IO8, board.IO14, board.IO13) # Create a socket pool pool = socketpool.SocketPool(wifi.radio) # Initialize a new MQTT Client object mqtt_client = MQTT.MQTT( broker="io.adafruit.com", username=secrets["aio_username"], password=secrets["aio_key"], socket_pool=pool, ssl_context=ssl.create_default_context(), ) # Connect the callback methods defined above to Adafruit IO mqtt_client.on_connect = connected
""" CircuitPython I2S WAV file playback. Plays a WAV file once. """ import audiocore import board import audiobusio audio = audiobusio.I2SOut(board.GP0, board.GP1, board.GP2) wave_file = open("StreetChicken.wav", "rb") wav = audiocore.WaveFile(wave_file) print("Playing wav file!") audio.play(wav) while audio.playing: pass print("Done!")
import rp2pio import adafruit_pioasm time.sleep(10) trigger = digitalio.DigitalInOut(board.D4) trigger.switch_to_output(True) # Generate one period of sine wav. length = 8000 // 440 # signed 16 bit s16 = array.array("h", [0] * length) for i in range(length): s16[i] = int(math.sin(math.pi * 2 * i / length) * (2**15)) print(s16[i]) sample = audiocore.RawSample(s16, sample_rate=8000) dac = audiobusio.I2SOut(bit_clock=board.D10, word_select=board.D11, data=board.D12) trigger.value = False dac.play(sample, loop=True) time.sleep(1) dac.stop() trigger.value = True print("done")
import board import audiocore import audiobusio import time print("Playing sample 10 times") f = open("tricorder_2.wav", "rb") wav = audiocore.WaveFile(f) i2s = audiobusio.I2SOut(bit_clock=board.GP10, word_select=board.GP11, data=board.GP9) for i in range(10): start = time.monotonic() i2s.play(wav) i = 0 while i2s.playing: time.sleep(0.01) # while i < 100: # i=i+1 # time.sleep(0.1) # pass i2s.stop() stop = time.monotonic() print("Total length = ", stop, "-", start, "=", stop - start)
def __init__(self, spi_clock, spi_mosi, spi_miso, i2c_scl, i2c_sda, dsp_command, dsp_chip_select, dsp_reset, i2s_clock, i2s_word, i2s_data, uart_tx, uart_rx): # Turn on the Pico's on-board LED print("Setting up power blinky") self.setupPowerBlinky() time.sleep(1) print("Done power blinky") try: # Create your bus objects self.spi = busio.SPI(clock=spi_clock, MOSI=spi_mosi, MISO=spi_miso) self.display_bus = displayio.FourWire(self.spi, command=dsp_command, chip_select=dsp_chip_select, reset=dsp_reset) self.main_screen = adafruit_ili9341.ILI9341(self.display_bus, width=self.WIDTH, height=self.HEIGHT) self.i2c = busio.I2C(scl=i2c_scl, sda=i2c_sda) self.uart = busio.UART(tx=uart_tx, rx=uart_rx, baudrate=9600, timeout=10) if sounds_enabled: self.i2s = audiobusio.I2SOut(bit_clock=i2s_clock, word_select=i2s_word, data=i2s_data) self.colours = Colours() # Create objects for display self.setupBlinkies() self.setupButtons() if touch_screen_enabled: try: self.touch_screen = adafruit_stmpe610.Adafruit_STMPE610_I2C( self.i2c, address=0x41) except Exception as err: self.led.value = False print("No touch screen could be enabled") self.okuda_font = bitmap_font.load_font("fonts/okuda.pcf") #self.okuda_font = bitmap_font.load_font("fonts/font5x8.bin") #self.okuda_font.load_glyphs(b'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 %.') # Define sensor devices self.thermal_camera = ThermalCamera(width=self.WIDTH, height=self.HEIGHT, i2c=self.i2c, display_bus=self.display_bus, display=self.main_screen, reverse=False, font=self.okuda_font) self.bme680 = adafruit_bme680.Adafruit_BME680_I2C(self.i2c, address=0x77) self.bme680.seaLevelhPa = self.SEA_LEVEL_NORMAL self.veml = adafruit_veml6075.VEML6075(self.i2c, integration_time=100) self.gps = adafruit_gps.GPS(self.uart, debug=False) self.matrix = Matrix(i2c=self.i2c) self.loadSounds() self.setupGPS() self.setupLCARS() except Exception as err: print("Error in PicoPicorder.init()") self.blinkError(err) time.sleep(2)