audio - How do I play an MP3 file from Polaris NB IoT board to MP3Click with VS1053 decoding chip using Python? - Stack Overflow

I have a Polaris NB IoT board on which I have an SD card that contains an MP3 file. I am trying to play

I have a Polaris NB IoT board on which I have an SD card that contains an MP3 file. I am trying to play said file on an MP3Click using SPI communication. I am using Python to code my board. I am able to write to the MP3 Click using this function and can read the data I send from a similar function.

def write_register(register, value):
    
    high_byte = (value >> 8) & 0xFF
    
    spi.select()
    low_byte = value & 0xFF
    spi.write(bytearray([SCI_WRITE, register, high_byte, low_byte]))
    spi.unselect() 

However when I try to write my byte data from my MP3 file there is no sound being played. I am certain the MP3 file has data. I have a suspicion it is because the GPIO1 pin of my chip is not pulled low, making it act as a midi synthesizer as explained in .php?f=10&t=58 but from the datasheet .pdf I cannot figure out how I could do this with the exposure I have using the MP3Click...


DREQ_PIN = D0  # Data request pin
pinMode(DREQ_PIN,INPUT_PULLUP)
RESET_PIN = D1  # Reset pin

SCI_MODE = 0x00
SCI_STATUS = 0x01
SCI_WRITE = 0x02
SCI_READ = 0x03

SCI_WRAM = 0x06
SCI_WRAMADDR = 0x07
SCI_HDAT0 = 0x08
SCI_HDAT1 = 0x09
SCI_VOL = 0x0B

SM_STREAM = 0x200
SM_RESET = 0x2000

spiData = spi.Spi(D7, clock=1000000)
spi = spi.Spi(D2, clock=1000000)

def vs1053_init():
    """Initialize the VS1053 chip for MP3 playback"""
    pinMode(RESET_PIN, OUTPUT)
    digitalWrite(RESET_PIN, LOW)
    sleep(50)
    digitalWrite(RESET_PIN, HIGH)
    sleep(50)
    soft_reset_vs1053()
    
    while digitalRead(DREQ_PIN) == LOW:
        sleep(10)  # Wait until DREQ is high
    print("SCI_MODE: ", read_register(SCI_MODE))
    print("SCI_STATUS: ", read_register(SCI_STATUS))
    
    write_register(SCI_MODE, 0x2B2)  # Set the mode to MP3 decoder mode
    while digitalRead(DREQ_PIN) == LOW:
        sleep(10)  # Wait until DREQ is high
        
    write_register(SCI_VOL, 0x0000)
    print("VS1053 Initialized")
    sleep(100)
    print("SCI_MODE: ", read_register(SCI_MODE))
    print("SCI_STATUS: ", read_register(SCI_STATUS))

def send_mp3_data(register, data):
    while digitalRead(DREQ_PIN) == LOW:
        sleep(10)
    spiData.select()
    writeData = bytearray([register]) + data
    spiData.write(writeData)
    spiData.unselect()

def play_mp3(filename):
    mp3_file = os.open(filename, 'rb+')
    while True:
        # Wait for DREQ to go high
        while digitalRead(DREQ_PIN) == LOW:
            soft_reset_vs1053()
            sleep(10)
        
        data = mp3_file.read(32)
        if not data:
            print("EOF")
            break  # End of file
        # Send the data chunk to VS1053B
        send_mp3_data(SCI_WRITE,data)
    print("Playback finished")

I have tried plugging both a wired in ear headset into the headphone jack and an amplifier connected to a speaker. The in ear headset makes no noise at all while the speaker is constantly buzzing loudly, also while no data is being sent. I am unable to attach images but the layout of my board can be found at .4.0/official/board.zerynth.polaris_nbiot/docs/index.html. The MP3 Click is inserted into the micro bus of the board.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745621181a4636524.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信