Reading data from a VDRIVE2 into a Picaxe 28X1/40X1

reuben38121

New Member
How do you do this? Any suggestions/code snippets. I am using the code and setup which BCJKiwi has designed, but I cannot work out how to read from the VDrive. Any help would be appreciated
 

100317

New Member
Vdrive & Vmusic

Hi,

Try a forum search using "VMUSIC". I think the V* modules are identical.
I postet a while ago an example how to write to a Vmusic module.

Sorry, but my Vmusic module is in use, so i cannot test it.

I have no experience, how to read from these modules.

But you can try this:

hserout 0,("opr filename.txt",CR) ' open the file

hserout 0,("rdf ",$00,$00,$00,$XX,CR) 'read from file
where the XX is the number of bytes, you want to read.
the result should be in the scratchpad of Picaxe.

Good luck!

Hans
 

BCJKiwi

Senior Member
@Reuben
The code presented in the code snippets section (assuming that is the code referred to) is, as the post says, a rework of Technical's VMusic2 sample from the old format forum.

The code presented was tested and working with the provisos and commands shown.
The code sample never really got much past creating the file (see below) but Hans has provided the key in his post above. Careful study of the manual and plenty of testing (with sertxd to see what the serial data stream is doing and what responses etc are really happening) is the only way forward.

If you could explain exactly what is working and which specific parts you are having trouble with, then others may be able to assist as many others appear to have used this device. Perhaps I should add that I no longer use VDrive2 as serial was not available in my project and I could not get SPI to work at an acceptable code size or speed so now use uAlfat-TF and i2c with a 28X1. So have a spare VDrive2 sitting on the shelf!
 
Last edited:

centrex

Senior Member
I have a vdrive up and running logging some data to a 256meg usb stick with no problems using BCJKiwi code snippet, with alot of the testing code removed.
I would like to know if anyone has carried this further and do they have schematics of their projects.
The biggest problem that I have is then using the data in Excel, even a logg of 100 items is a problem.
The code snippet provided by BCJ for running a real time works fine all displayed on a 4x20 lcd.
Hopefully this will all be part of the logger.
regards
centrex
 

centrex

Senior Member
Attached is the cut down version of BCJKiwi code to write data to a usb stick.
It is logging data read by adc0 and is a semicolon delimiterd file so that I can down load it in Excel.
The code has most of the sertxd commands removed along with the explanations.
A short delay has been used between reads so that it does not take forever as it might if logging real data.
hope this is of some use.
credits to BCJKiwi.
 

Attachments

centrex

Senior Member
My aplogies a gremlin krept into the code that I sent a while ago it doesnt work.

This does most of the testing bits are remed out.
It makes two files 'log.txt' has the data 'num.txt has the contents of the loopcounter.


Code:
; Interfacing a VDrive2 module to PICAXE-28X1
; 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 an Imation nano 1GB USB stick.
symbol first_byte = b0
symbol point = b1
symbol temp = b2
symbol loopcounter = b3
symbol adcvalue = b8
; set picaxe type
#picaxe 28x1
'setfreq m8
 
; set COM port used for download
;#com 1
; open terminal after download
; This is to view the 'sertxd' debugging comments
#terminal 4800
 
setup:
; setup serial hardware 
; at 9600 with background receive
hsersetup b9600_4,%01
low 0 ; ensure CTS is low
 pause 2000
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
 high 2
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 
;now interact with disk
'Disk:
'Get firmware version 
'sertxd ("<Sent> FWV",CR,LF)
'hserout 0,("FWV",CR)
'gosub get_fileresponse


; create a log file called 'log.txt'
; if you send 11 chars as the file name the last three will become the extension
; the '.' is inserted automatically 
; Filename cannot include spaces

for loopcounter = 1 to 100
gosub openfile1:
readadc 0,adcvalue
sertxd (#adcvalue,"  ",#loopcounter,CR,LF)

bintoascii adcvalue,b5,b6,b7 ; convert loopcounter byte to 3 ascii digits
      ; and write 8 bytes loop_xyz

hserout 0,("wrf ",$00,$00,$00,$04,CR,b5,b6,b7,";",CR)
pause 200
'sertxd (#loopcounter,"  loopcounter",CR,LF)
'next
gosub closefile1
'high 1			' turns on led to indicate finish
				'b9,b10,b11,";"

'stop

pause 200
gosub openfile2

bintoascii loopcounter,b9,b10,b11 
hserout 0,("wrf ",$00,$00,$00,$04,CR,b9,b10,b11,";",CR)
'pause 100
'sertxd (#loopcounter,"  loopcounter",CR,LF)

gosub closefile2
pause 200
next
high 1			' turns on led to indicate finish
low 2				'b9,b10,b11,";"

stop



; 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
  ' sertxd (#point,"   ",#first_byte,13,10) 
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

openfile1:
'sertxd ("<Sent> Open file",CR,LF)
hserout 0,("opw Log.txt",CR)
gosub get_response
'sertxd ("<Sent> write to file",CR,LF)
return

closefile1:
'sertxd ("<Sent> Close file",CR,LF)
hserout 0,("clf Log.txt",CR)
return

openfile2:
'sertxd ("<Sent> Open file",CR,LF)
hserout 0,("opw Num.txt",CR)
gosub get_response
'sertxd ("<Sent> write to file",CR,LF)
return

closefile2:
'sertxd ("<Sent> Close file",CR,LF)
hserout 0,("clf Num.txt",CR)
return



get_fileresponse:
   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 <> ">" ; 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 
   pause 1000
return
 

reuben38121

New Member
Yeah, I can make it so that I can see the data in the file when I look at it through the Serial Terminal (Sertxd), but I cannot save the data into a byte/word (it comes out as random numbers). I think it is because the VDRIVE outputs an ascii value, but I cannot work out how to convert this back to binary/decimal. I checked the PICAXE manual, and they had one reference to the command 'asciitobin', but that was all I could see, and the programming editor would not recognise it as a valid command. I think this would be the perfect command for me.
 

100317

New Member
Reuben!

I have read the program several times. I do not understand what you want to do. Where should the data be sent?
I have modified your program, but have not tested.

Hans
 

Attachments

reuben38121

New Member
I want to read the entire file (which will only be a byte or so) into a word variable and then write it into an eeprom location
 

reuben38121

New Member
Fixed!

I have sorted this problem, and am building a Visual C# interface to write the values to the VDRIVE that the PICAXE can read. Thanks all for your help.
 
Top