|
1,网上找到个MP3模块
这货支持tf卡,插入tf卡,放入几首MP3
2,使用esp32 把16,17 与rx和TX相连接入电源
再把喇叭就如spk1和spk2,这样完成硬件连接
3,查看手册编写程序
- from machine import UART,Pin
- import re,time
- u = UART(2, 115200)
- u.init( baudrate=115200, bits=8, parity=None, stop=1, tx=17, rx=16, rts=-1, cts=-1, timeout=0, timeout_char=1)
- buf=bytearray(8)
- bufcmd=bytearray(10)
- bufcmd[0]=0x7E
- bufcmd[9]=0xEF
- def sendcmd():
- global bufcmd
- for i in range(0,8):
- bufcmd[i+1]=buf[i]
- u.write(bufcmd)
- def checksum(len):
- global buf
- xorsum=0
- for i in range(0,len):
- xorsum=xorsum+buf[i]
- xorsum=0-xorsum
- buf[6]=xorsum>>8
- buf[7]=xorsum & 0x00ff
- def uartcmd(CMD,feedback,dat):
- global buf
- buf[0] = 0xff
- buf[1] = 0x06
- buf[2] = CMD
- buf[3] = feedback
- buf[4] = dat >> 8
- buf[5] = dat
- checksum(6)
- sendcmd()
- def forward():
- uartcmd(03 , 0 , 5)
- def back():
- uartcmd(03 , 0 , 6)
- def left():
- uartcmd(03 , 0 , 7)
- def right():
- uartcmd(03 , 0 , 8)
- def brake():
- uartcmd(03 , 0 , 9)
- def stop():
- uartcmd(03 , 0 , 10)
- def pause():
- uartcmd(0x0e , 0 , 0)
- def readcmd():
- hexcmd=[]
- for i in u.read():
- d=hex(i).replace('0x','')
- d=d.upper()
- hexcmd.append(d)
- print(hexcmd)
复制代码
4,打开esp32 shell 输入相应代码,MP3可以播放了 ,就是喇叭不好有点破音
此内容由EEWORLD论坛网友sanxiawu原创,如需转载或用于商业用途需征得作者同意并注明出处
|
|