Closed codingyoutub closed 3 years ago
In arduino, the dfplayer worked well and Raspberry connected to HC05 Bluetooth and it worked very well.
However, Raspberry and FDplayer are not allowed. Can you look at the chords?
`import serial import time
MP3_PLAYBACK_SOURCE = 0x09 MP3_VOLUME = 0x06 MP3_PLAYBACK_SOURCE_TF = 1
global send default_buf = [0x7E,0xFF, 0x06, 0x00, 0x00, 0x00, 0x00,0x00,0x00, 0xEF] mp3_cmd_buf = [0x7E,0xFF, 0x06, 0x00, 0x00, 0x00, 0x00,0x00,0x00, 0xEF]
global ser ser = serial.Serial( port='/dev/ttyAMA1', baudrate=9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize= serial.EIGHTBITS, timeout=1 )
global loop loop = False
def dfplayer_init(): mp3_send_cmd(MP3_PLAYBACK_SOURCE, 0, MP3_PLAYBACK_SOURCE_TF) time.sleep(0.01) mp3_send_cmd(MP3_VOLUME, 0, 30) time.sleep(0.01)
def Volume(v): mp3_send_cmd(MP3_VOLUME, 0, v)
def Play(): global loop loop = True mp3_send_cmd(0x12, 0, 1)
def NextPlay(): global loop loop = True mp3_send_cmd(0x01, 0, 0)
def Stop(): global loop if loop: loop = False mp3_send_cmd(0x16, 0, 1)
def mp3_send_cmd(cmd, high_arg, low_arg): mp3_cmd_buf[3] = cmd mp3_cmd_buf[5] = high_arg mp3_cmd_buf[6] = low_arg checksum = MP3_checksum() mp3_cmd_buf[7] = ((checksum >> 8) & 0x00FF) print(mp3_cmd_buf[7]) mp3_cmd_buf[8] = (checksum & 0x00FF) print(mp3_cmd_buf[8]) for i in range(10): USART_Transmit(mp3_cmd_buf[i]) mp3_cmd_buf[i] = default_buf[i]
def MP3_checksum(): sum =0 for i in range(1,7): sum += mp3_cmd_buf[i] return -sum
def USART_Transmit(data): global ser print(chr(data)) ser.write(bytes(data))
dfplayer_init() NextPlay()`
In arduino, the dfplayer worked well and Raspberry connected to HC05 Bluetooth and it worked very well.
However, Raspberry and FDplayer are not allowed. Can you look at the chords?
`import serial import time
MP3_PLAYBACK_SOURCE = 0x09 MP3_VOLUME = 0x06 MP3_PLAYBACK_SOURCE_TF = 1
global send default_buf = [0x7E,0xFF, 0x06, 0x00, 0x00, 0x00, 0x00,0x00,0x00, 0xEF] mp3_cmd_buf = [0x7E,0xFF, 0x06, 0x00, 0x00, 0x00, 0x00,0x00,0x00, 0xEF]
global ser ser = serial.Serial( port='/dev/ttyAMA1', baudrate=9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize= serial.EIGHTBITS, timeout=1 )
global loop loop = False
def dfplayer_init(): mp3_send_cmd(MP3_PLAYBACK_SOURCE, 0, MP3_PLAYBACK_SOURCE_TF) time.sleep(0.01) mp3_send_cmd(MP3_VOLUME, 0, 30) time.sleep(0.01)
def Volume(v): mp3_send_cmd(MP3_VOLUME, 0, v)
def Play(): global loop loop = True mp3_send_cmd(0x12, 0, 1)
def NextPlay(): global loop loop = True mp3_send_cmd(0x01, 0, 0)
def Stop(): global loop if loop: loop = False mp3_send_cmd(0x16, 0, 1)
def mp3_send_cmd(cmd, high_arg, low_arg): mp3_cmd_buf[3] = cmd mp3_cmd_buf[5] = high_arg mp3_cmd_buf[6] = low_arg checksum = MP3_checksum() mp3_cmd_buf[7] = ((checksum >> 8) & 0x00FF) print(mp3_cmd_buf[7]) mp3_cmd_buf[8] = (checksum & 0x00FF) print(mp3_cmd_buf[8]) for i in range(10): USART_Transmit(mp3_cmd_buf[i]) mp3_cmd_buf[i] = default_buf[i]
def MP3_checksum(): sum =0 for i in range(1,7): sum += mp3_cmd_buf[i] return -sum
def USART_Transmit(data): global ser print(chr(data)) ser.write(bytes(data))
dfplayer_init() NextPlay()`