adafruit_vs1053

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 interpretor 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

Hardware:

Software and Dependencies:

class adafruit_vs1053.VS1053(spi, cs, xdcs, dreq)

Class-level buffer for read and write commands.

byte_rate

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.

decode_time

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, start=0, end=None)

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

ready_for_data

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

reset()

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

set_volume(left, right)

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

sine_test(n, seconds)

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

soft_reset()

Perform a quick soft reset of the VS1053.

start_playback()

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()

Stop any playback of audio.

version

Return the status register version value.