So to identify a track I have a Psion data file that relates the track number to the track name. And on the PC I have some Python code (which I found on the web at https://github.com/Neutrino-1/Arduino-Soundpod) which writes tracks onto the SD card. I modified the code to build a Psion data file with an index to the track names. If you want to change the music on the SD card you have to delete everything and re-write, or the index will be wrong. I'm using it with the CommsLink I built previously, I modified that with a potential divider on the output to give 3.3V to the DFplayer and the buffer chip I'm using provides a level shift to 5V on the input to the Psion. The MP3 player is sitting on a second board above the CommsLink, which keeps it small and neat. The buttons on it are for previous and next track, or a long press changes the volume. One nice thing about it is that it's powered separately from the Psion, so the Psion can switch off and the MP3 player keeps going, you can then wake the Psion up later to check or change a track.
The software is all in a single OPL script (shown below), but I think it would be neater if I break it up into separate functions, as I'm having to use quite a few GOTO and IF statements, which could be removed. The advantage of how it is at the moment is that I can view the whole thing in one script on the PC. I know about the GOSUB option for one of the PC translators, but I was trying to keep it simple.
Any comments on the code and how it could be, or the hardware are most welcome.
MartinP
Code: Select all
MP3:
rem for DF player, by Martin Prest 2023
rem set HAND, TEOL and REOL to NONE in COMMS SETUP
LOCAL M%,C%(8),I%,L%,IN%(10),DL%,DH%,CKL%,CKH%,Q%,S%,D%,CK,F%
Q%=0 :rem set Query to none
L%=8 :rem length of command (in bytes)
LSET:(9600,0,8,1,0,0,0)
C%(1) = $7E :rem start of packet
C%(2) = $FF :rem version
C%(3) = 6 :rem length
C%(4) = 0 :rem command
C%(5) = 0 :rem response 0-no, 1-yes
C%(6) = 0 :rem data-hi
C%(7) = 0 :rem data-lo
C%(8) = $EF :rem end
rem setup
C%(4)=6 :rem volume
C%(7)=15 :rem max is 30
S%=0 :rem 1-do or 0-don't run SETUP1
GOTO SEND::
SETUP1::
C%(4)=$0F :rem play folder + track - stops current track
C%(6)=2 :rem folder 2
C%(7)=1 :rem track 1
S%=0
GOTO SEND::
START::
CLS
M%=MENU("NEXT,PREV,STOP,VOL+,VOL-,VOL?,TRACK?,MODE?,REPT,EQ?,FOLDERS?,TRACKS?,PAUSE,PLAY")
IF M%=0 :STOP
ELSEIF M%=1
C%(4)=1 :rem play next track
ELSEIF M%=2
C%(4)=2 :rem play prev track
ELSEIF M%=3
C%(4)=$16 :rem stop
ELSEIF M%=4
C%(4)=4 :rem vol+
ELSEIF M%=5
C%(4)=5 :rem vol-
ELSEIF M%=6
C%(4)=$43 :rem vol?
Q%=1 :rem Vol query
ELSEIF M%=7
C%(4)=$4C :rem Track?
Q%=2 :rem Track query
ELSEIF M%=8
C%(4)=$45 :rem Mode?
Q%=3 :rem Mode query
ELSEIF M%=9
M%=MENU("STOP,ON")
IF M%=0 :GOTO START:: :ENDIF
C%(4)=$11 :rem set play repeat all
C%(7)=M%-1 :rem repeat: 0-stop, 1-on
ELSEIF M%=10
C%(4)=$44 :rem Equaliser?
Q%=4 :rem EQ query
ELSEIF M%=11
C%(4)=$4F :rem No. of folders?
Q%=5 :rem folder query
ELSEIF M%=12
C%(4)=$4E :rem No. of tracks in folder? -stops play
CLS
PRINT"Folder:"
INPUT F%
CLS
C%(7)=F% :rem folder
Q%=6 :rem tracks query
ELSEIF M%=13
C%(4)=$0E :rem pause
ELSEIF M%=14
C%(4)=$0D :rem play -does nothing?
ENDIF
SEND::
IF Q%>0
L%=7 :rem set command length for query
ENDIF
I%=1
WHILE I%<=L%
LPRINT CHR$(C%(I%))
I%=I%+1
ENDWH
C%(7)=0 :rem reset data-lo
IF S%=1
GOTO SETUP1::
ENDIF
IF Q%=0 :GOTO START:: :ENDIF
rem query
IN%(1)=ASC(TRIG$:(1,1,CHR$(239))) :rem send last byte of packet to trigger response
I%=2
WHILE I%<=10
IN%(I%)=ASC(LINPUT$:(1,1))
I%=I%+1
ENDWH
DH%=IN%(6)
DL%=IN%(7)
CKH%=IN%(8)
CKL%=IN%(9)
CK = 65535-IN%(2)-IN%(3)-IN%(4)-IN%(5)-IN%(6)-IN%(7)+1
IF CK-CKL%-FLT(CKH%)*256.=0
rem PRINT "CHECKSUM OK"
ELSE
PRINT "CHECKSUM BAD!"
GET
GOTO START::
ENDIF
IF Q%=2 :GOTO TRACK::
ELSEIF Q%=3 :GOTO MODE::
ELSEIF Q%=4 :GOTO EQ::
ELSEIF Q%=5 :GOTO FDRS::
ELSEIF Q%=6 :GOTO TRKS::
ENDIF
rem Q%=1 Vol?
PRINT "VOL:",DL%
GET
GOTO DONE::
TRACK::
PRINT "TRACK:",DL%+256*DH%
GET
OPEN "A:music",A,track$
POSITION DL%+256.*DH%
D%=DISP(-1,"")
CLOSE
GOTO DONE::
MODE::
PRINT "Mode:",DL% :rem 0-all, 1-folder, 2-single, 3-random
GET
GOTO DONE::
EQ::
PRINT "EQ:",DL% :rem 0-norm, 1-Pop, 2-Rock, 3-Jazz, 4-Classic, 5-base
GET
GOTO DONE::
FDRS::
PRINT "Folders:",DL%
GET
GOTO DONE::
TRKS::
PRINT "Tracks:",DL%+256.*DH%
GET
DONE::
Q%=0 :rem reset Query to none
L%=8 :rem restore full command length
GOTO START::