I was wondering if anyone here knows if there is any library in micropython for the Raspberry Pi Pico to use a DAC (PCM5102). I want to output sound from a wavetable using the DAC.
So far I have not found any code in micropython to do this, however there is a code for circuitpython that works well:
Code: Select all
import time import array import math import audiocore import board import audiobusio sample_rate = 8000 tone_volume = .1 # Increase or decrease this to adjust the volume of the tone. frequency = 440 # Set this to the Hz of the tone you want to generate. length = sample_rate // frequency # One frequency period sine_wave = array.array("H",  * length) for i in range(length): sine_wave[i] = int((math.sin(math.pi * 2 * frequency * i / sample_rate) * tone_volume + 1) * (2 ** 15 - 1)) audio = audiobusio.I2SOut(board.GP16, board.GP17, board.GP18) sine_wave_sample = audiocore.RawSample(sine_wave, sample_rate=sample_rate) audio.play(sine_wave_sample, loop=True) time.sleep(1) audio.stop() time.sleep(1)