最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin5PV0评论

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.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far