Driver for interacting and playing media files with the VS1053 audio codec over a SPI connection.

NOTE: This is not currently working for audio playback of files. Only sine wave test currently works. The problem is that pure Python code is currently too slow to keep up with feeding data to the VS1053 fast enough. There’s no interrupt support so Python code has to monitor the DREQ line and provide a small buffer of data when ready, but the overhead of the interpreter means we can’t keep up. Optimizing SPI to use DMA transfers could help but ultimately an interrupt-based approach is likely what can make this work better (or C functions built in to custom builds that monitor the DREQ line and feed a buffer of data).

  • Author(s): Tony DiCola

Implementation Notes


Software and Dependencies:

class adafruit_vs1053.VS1053(spi: SPI, cs: Pin, xdcs: Pin, dreq: Pin)

Class-level buffer for read and write commands.

property byte_rate: int

Return the bit rate in bytes per second (computed each second). Useful to know if a song is being played and how fast it’s happening.

property decode_time: int

Return the decode time register value. This is the amount of time the current file has been played back in seconds.

play_data(data_buffer: Union[array, bytearray, bytes, memoryview, rgbmatrix.RGBMatrix, ulab.numpy.ndarray], start: int = 0, end: Optional[int] = None)

Send a buffer of file data to the VS1053 for playback. Make sure the ready_for_data property is True before calling!

property ready_for_data: bool

Return True if the VS1053 is ready to accept data, false otherwise.

reset() None

Perform a longer full reset with clock and volume reset too.

set_volume(left: int, right: int) None

Set the volume of the left and right channels to the provided byte value (0-255), the lower the louder.

sine_test(n: int, seconds: float) None

Play a sine wave for the specified number of seconds. Useful to test the VS1053 is working.

soft_reset() None

Perform a quick soft reset of the VS1053.

start_playback() None

Prepare for playback of a file. After calling this check the ready_for_data property continually until true and then send in buffers of music data to the play_data function.

stop_playback() None

Stop any playback of audio.

property version: int

Return the status register version value.