VMusic2 Tecnical's sample in new forum format

BCJKiwi

Senior Member
#1
VMusic2 Technical's sample in new forum format

Since the old forum has not been converted yet, this is the sample code from technical edited for the new forum.

I currently have a VDrive2 with firmware 03.54 and it creates the log.txt file OK

Code:
; Interfacing a VMUSIC2 module to PICAXE-28X1 - By technical - edited to new froum format BCJKiwi
; Also shows how to create a log file (this also suits VDRIVE2)
; Hardware Setup
; VDrive2        -  PICAXE-28X1
; 1 Black GND    -  0V               Leg 8,19
; 2 Brown RTS    -  CTS input4 C4    Leg 15 (not used)
; 3 Red V+       -  V+               Leg 20
; 4 Orange RXD   -  HTXD input6 C6   Leg 17  
; 5 Yellow TXD   -  HRXD input7 C7   Leg 18
; 6 Green CTS    -  RTS output0 B0   Leg 21 (not essential, can tie to 0V)
; 7
; 8 Blue RI      -  not connected
; Note RXD on VDrive2 connects to TXD on PICAXE etc.
 
; Tested with a Sandisk 1GB Micro Cruzer with MP3 files called
; "1.mp3", "2.mp3", "3.mp3" in the root folder
; Sound was output using normal computer style speakers.
; IMPORTANT NOTE: Upon powerup it can take over a minute for the 
; VMUSIC2 to enumerate the 1GB memory stick. During this time it looks
; like nothing at all is happening. This had us confused for many hours,
; thinking that the module was not working!
; After powerup have a cup of coffee and wait for the LED on VMUSIC2 
; to go green. The drive LED should also be on - if not try reinserting.
symbol first_byte = b0
symbol point = b1
symbol temp = b2
symbol loopcounter = b3
; set picaxe type
#picaxe 28x1
setfreq m4
; set COM port used for download
;#com 4
; open terminal after download
; This is to view the 'sertxd' debugging comments
#terminal 9600
setup:
; setup serial hardware 
; at 9600 with background receive
hsersetup b9600_4,%01
low 0 ; ensure CTS is low
init:
; Send Es until the unit responds correctly
sertxd ("<Sent> E",CR,LF)
hserout 0,("E",CR)
gosub get_response
if first_byte <> "E" then init
main:
; check to see if a drive is actually inserted
; response will start D for yes and N for no
sertxd ("<Sent> Check Drive",CR,LF)
hserout 0,(CR)
gosub get_response
if first_byte <> "D" then main 
; play track 1.mp3
; response will start D if ok, C if not
sertxd ("<Sent> Play track 1",CR,LF)
hserout 0,("vpf 1.mp3",CR)
gosub get_response
if first_byte <> "D" then main 
;now playing a track
playing:
sertxd ("Playing 10 seconds of track 1",CR,LF)
pause 10000
sertxd ("...pausing for 5 seconds...",CR,LF)
sertxd ("<Sent> e",CR,LF)
hserout 0,("e") ;note no CR here
pause 5000
sertxd ("...playing another 10 seconds of track",CR,LF)
sertxd ("<Sent> CR",CR,LF)
hserout 0,(CR) 
gosub get_response
pause 10000
sertxd ("<Sent> Stopping track",CR,LF)
hserout 0,("vst",CR)
gosub get_response
; create a log file called 'log' (for some reason 'log.txt' didn't work)
; create a log file called 'log.txt' works with fw 03.54 bcjkiwi
; if you send 11 chars as the file name the last three will become the extension
; the '.' is inserted automatically 
; Filename cannot include spaces
sertxd ("<Sent> Open file",CR,LF)
hserout 0,("opw log",CR)
gosub get_response
sertxd ("<Sent> write to file",CR,LF)
bintoascii loopcounter,b5,b6,b7 ; convert loopcounter byte to 3 ascii digits
      ; and write 8 bytes loop_xyz
hserout 0,("wrf ",$00,$00,$00,$08,CR,"loop_",b5,b6, b7,CR)
gosub get_response
sertxd ("<Sent> Close file",CR,LF)
hserout 0,("clf log",CR)
gosub get_response
inc loopcounter ; increment counter
goto main
 
; Sub procedure to receive background bytes
get_response:
pause 1000 ; wait a while 
sertxd ("<Response> ")
point = 0 ; reset local pointer
get point,first_byte ; Save the first reply byte
do
get point,temp ; get returned byte
sertxd (temp) ; transmit it
inc point ; increment pointer
loop while temp <> CR ; if not CR loop
sertxd (LF) ; Add a LF to the received CR
sertxd (CR,LF) ; Do another blank line
hserptr = 0 ; reset the background receive pointer 
return
 
; Other Useful Commands
; Play all tracks hserout 0,("w3a",CR)
; Stop track hserout 0,("vst",CR)
; Skip to Next Track hserout 0,("vsf",CR)
; Skip to Start of current Track hserout 0,("vsb",CR)
; Skip to Previous Track hserout 0,("vsb",CR,"vsb",CR)
; Pause hserout 0,("e") ; note no CR here
; Resume (after pause) hserout 0,(CR)
; Set Volume hserout 0,("vwr",$0B,vol_right,vol_left,CR)
  ; where $00 = maximum volume,$FE is the minimum
; Suspend disk hserout 0,("sud",CR)
; Wakeup disk hserout 0,("wkd",CR)
; Get firmware version hserout 0,("fwv",CR)
 
Last edited:
Top