Vdrive2 Write Errors

stircrazy

New Member
Hi everyone, I've just started using the Picaxe and am working on a pet datalogger. It takes readings every 10 seconds and writes the results to a USB drive, but every 10 lines or so, I get a wierd string of what looks like extended ASCII characters (please see attached file, log.txt).

I did a debug just before the write to file command to output everything in the scratchpad and everything was perfect, so I think there is something going on during the write command itself that is creating the problem.

Does anyone have any ideas of what is causing this bizarre problem? I thought it might be related to the latest Vdrive firmware that doesn't enumerate the drive when inserted, but when I reflashed to an older version of the firmware, I still got the same sort of problem.

Thanks in advance for any help!

The project contains the following components:
Picaxe 28X1 (A.2 firmware)
Vdrive2 (3.61 LDAP firmware, 1GB Sandisk Cruzer Micro)
DS1307 RTC
DE-ACCM3D Accelerometer
DS18B20 Temperature Sensor
LDR
MS24M Motion Switch

The code is as follows:
Code:
#picaxe 28x1
setfreq m4

'----------------------------------------------------------------------------------------------------
'Symbol Definitions

'Pinouts
						'pin 01 = reset		'Mini momentary pushbutton switch SPST
symbol LDR = 0				'pin 02 = ADC0			'ORP12 light dependent resistor
symbol accel_y = 1			'pin 03 = ADC1			'DE-ACCM3D accelerometer (Y-axis output)
symbol accel_x = 2			'pin 04 = ADC2			'DE-ACCM3D accelerometer (X-axis output)
symbol accel_z = 3			'pin 05 = ADC2			'DE-ACCM3D accelerometer (Z-axis output)
						'pin 06 = serial in		'USB/serial download cable circuit
						'pin 07 = serial out	'USB/serial download cable circuit
						'pin 08 = ground
						'pin 09 = resonator
						'pin 10 = resonator
						'pin 11 = timer clk		'MS24M miniature motion switch
symbol temp = 1			'pin 12 = input 1		'DS18B20 digital temperature sensor
symbol startstop = pin2		'pin 13 = input 2		'Mini momentary pushbutton switch SPST
						'pin 14 = i2c scl		'for DS1307 RTC
						'pin 15 = i2c sda		'for DS1307 RTC
'symbol rx_433 =		 	'pin 16 = input 5		'433 MHz receiver connected through Picaxe 08M
						'pin 17 = ser tx		'connects to RXD on Vdrive2 
						'pin 18 = ser rx		'connects to TXD on Vdrive2
						'pin 19 = ground
						'pin 20 = V+
symbol piezo = 0			'pin 21 = output 0		'Mini Piezo Buzzer
						'pin 22 = output 1 (not used)
						'pin 23 = output 2 (not used)
						'pin 24 = output 3 (not used)
						'pin 25 = output 4 (not used)
						'pin 26 = output 5 (not used)
symbol LED_red = 6			'pin 27 = output 6		'3mm bicolour LED (red)
symbol LED_green = 7		'pin 28 = output 7		'3mm bicolour LED (green)

'Variables
symbol temp_byte = b0
symbol first_byte = b1							'first byte of Vdrive2 response
symbol temp_word = w1

'----------------------------------------------------------------------------------------------------
'Begin Program

main:

	low LED_red
	low LED_green
	low piezo
	hi2csetup i2cmaster,%11010000,i2cslow,i2cbyte   	'setup DS1307 RTC over i2c bus
	hsersetup b9600_4,%01						'setup Vdrive2 over hardware serial pins
	settimer count 65535						'setup internal counter for motion switch

wait_press1:
	nap 1
	if startstop = 0 then wait_press1				'loop until startstop button is pressed
	
wait_unpress1:
	nap 1
	if startstop = 1 then wait_unpress1			'loop until startstop button is released
	
	high LED_green								'steady green LED indicates mission in progress
	sound piezo,(96,8,0,8,96,8)					'double beep indicates mission start

init_vdrive2:									'send Es until Vdrive2 responds correctly
	hserout 0,("E",CR)
	gosub get_response
	if first_byte <> "E" then init_vdrive2

check_disk:									'check for valid USB drive on Vdrive2
	hserout 0,(CR)								'response will start D for yes and N for no 
	gosub get_response
	if first_byte <> "D" then check_disk 

	hserout 0,("opw log.txt",CR)					'open "log.txt" on USB drive
	gosub get_response
	
	let timer = 0								'reset internal counter for motion switch

'----------------------------------------------------------------------------------------------------		
'Mission (read data and save to Vdrive2 every 10 seconds)

mission:

	hi2cin 0,(b9)								'read second
	if startstop = 1 then pausestop
	let temp_byte = b9 AND %00001111				'copy digit of second to temp_byte
	if temp_byte <> 0 then goto mission			'loop until second is a multiple of 10
	
'Read Data

	low LED_green
	high LED_red

	hi2cin 4,(b4)								'read date 
	hi2cin 5,(b5)								'read month
	hi2cin 6,(b6)								'read year
	hi2cin 2,(b7)								'read hour
	hi2cin 1,(b8)								'read minute

	readtemp12 temp,w5
	readadc10 LDR,w6
	readadc10 accel_x,w7
	readadc10 accel_y,w8
	readadc10 accel_z,w9
	let w10 = timer
	let timer = 0								'reset internal counter for motion switch
'	let b22 = wireless
'	let b23 = wireless

'Convert Data to ASCII and Write to Scratchpad

	let ptr = 64
	bcdtoascii b4,@ptrinc,@ptrinc
	bcdtoascii b5,@ptrinc,@ptrinc
	bcdtoascii b6,@ptrinc,@ptrinc
	bcdtoascii b7,@ptrinc,@ptrinc
	bcdtoascii b8,@ptrinc,@ptrinc
	bcdtoascii b9,@ptrinc,@ptrinc
	bintoascii w5,temp_byte,@ptrinc,@ptrinc,@ptrinc,@ptrinc
	bintoascii w6,temp_byte,@ptrinc,@ptrinc,@ptrinc,@ptrinc
	bintoascii w7,temp_byte,@ptrinc,@ptrinc,@ptrinc,@ptrinc
	bintoascii w8,temp_byte,@ptrinc,@ptrinc,@ptrinc,@ptrinc
	bintoascii w9,temp_byte,@ptrinc,@ptrinc,@ptrinc,@ptrinc
	bintoascii w10,temp_byte,@ptrinc,@ptrinc,@ptrinc,@ptrinc
	bintoascii b22,temp_byte,@ptrinc,@ptrinc
	bintoascii b23,temp_byte,@ptrinc,@ptrinc
	
'Save Data to Vdrive2

	let ptr = 64
	hserout 0,("wrf ",$00,$00,$00,$38,CR,@ptrinc,@ptrinc,"/",@ptrinc,@ptrinc,"/20",@ptrinc,@ptrinc,",",@ptrinc,@ptrinc,":",@ptrinc,@ptrinc,":",@ptrinc,@ptrinc,",",@ptrinc,@ptrinc,@ptrinc,@ptrinc,",",@ptrinc,@ptrinc,@ptrinc,@ptrinc,",",@ptrinc,@ptrinc,@ptrinc,@ptrinc,",",@ptrinc,@ptrinc,@ptrinc,@ptrinc,",",@ptrinc,@ptrinc,@ptrinc,@ptrinc,",",@ptrinc,@ptrinc,@ptrinc,@ptrinc,",",@ptrinc,@ptrinc,",",@ptrinc,@ptrinc,LF,CR)
	gosub get_response
		
	low LED_red
	high LED_green

goto mission

'----------------------------------------------------------------------------------------------------		
'Vdrive2 Subroutine to Get Response

get_response:
	pause 250
   get 0,first_byte 							'save the first byte received
	let hserptr = 0							'reset the background receive pointer 
return

'----------------------------------------------------------------------------------------------------
'Pause/Stop Mission

pausestop:
	hserout 0,("wrf ",$00,$00,$00,$1A,CR,"Datalogger Paused/Stopped",LF,CR)
	gosub get_response
	
	hserout 0,("clf log.txt",CR)					'close "log.txt" on USB drive

	low LED_red
	low LED_green
	sound piezo,(96,8,0,8,96,8,0,8,96,8)			'triple beep indicates mission pause/stop

wait_press2:
	nap 1
	if startstop = 0 then wait_press2				'loop until startstop button is pressed
	
wait_unpress2:
	nap 1
	if startstop = 1 then wait_unpress2			'loop until startstop button is released
	
	high LED_green								'steady green LED indicates mission in progress
	sound piezo,(96,8,0,8,96,8)					'double beep indicates mission start
	goto init_vdrive2

end
 

Attachments

Technical

Technical Support
Staff member
It could be that the vdrive is having difficulties keeping up with the long hserout comand.

Try breaking it up into, say, 3 or 4 smaller consequative hserout commands.

Your LF,CR should also read CR,LF

e.g.
Code:
hserout 0,("wrf",$00,$00,$00,$38,CR,@ptrinc,@ptrinc,"/",@ptrinc,@ptrinc,"/20")
hserout 0,(@ptrinc,@ptrinc,",",@ptrinc,@ptrinc,":",@ptrinc,@ptrinc,":",@ptrinc,@ptrinc,",",@ptrinc,@ptrinc,@ptrinc,@ptrinc,",")
hserout 0,(@ptrinc,@ptrinc,@ptrinc,@ptrinc,",",@ptrinc,@ptrinc,@ptrinc,@ptrinc,",",@ptrinc,@ptrinc,@ptrinc,@ptrinc,",",@ptrinc,@ptrinc,@ptrinc,@ptrinc,",")
hserout 0,(@ptrinc,@ptrinc,@ptrinc,@ptrinc,",",@ptrinc,@ptrinc,",",@ptrinc,@ptrinc,CR,LF)
Are your byte counts also right?

e.g.
hserout 0,("wrf ",$00,$00,$00,$1A,CR,"Datalogger Paused/Stopped",LF,CR)
This is 27 bytes, not 26, after the central CR.
hserout 0,("wrf ",$00,$00,$00,$1B,CR,"Datalogger Paused/Stopped",CR,LF)

Note an old verion of the FTDI datasheet said the wrf command must end with CR. This is not true and is corrected in the new version datasheet.
 
Last edited:

stircrazy

New Member
Hi and thanks for the feedback!

I tried switching the CR and LF as you suggested and the Vdrive2 failed to write, so I think the correct order is LF,CR. As for the number of bytes, that is also correct as is (for your example, there are the 26 characters plus the LF character = 27 bytes).

I tried breaking the hserout command into pieces using the suggested code and got no love. I also tried writing the output string to data memory (instead of the scratchpad) and then writing to the Vdrive2 from there, and again, same problem.

Tomorrow I'm going to go through a test cycle using static text instead of the data from the sensors and see if I get the same errors. I'm also going to try contacting Vinculum tech support to see if they can help.

Please let me know if you think of anything else!
 

Technical

Technical Support
Staff member
You do not need a final CR or LF or anything at the end of the write. It just writes the number of bytes you specify at the start of the command.

Make sure you are using the latest version of the FDTI datsheet, earlier versions were misleading.

Because your byte count is wrong, the VDRIVE2 is actually using your final CR as an 'unknown' error check, because you have exceeded your byte count.

The LF CR sequence will not print correctly in Notepad etc - it must be CR LF

the example in the FTDI datsheet to write 10 bytes is
wrf 10<CR>
01 02 03 04 05 06 07 08 09 0A

This equates to
hserout 0,("wrf 10",CR)
hserout 0,($01, $02, $03, $04, $05, $06, $07, $08, $09, $0A)

or is SCS mode
08 20 00 00 00 0A 0d
01 02 03 04 05 06 07 08 09 0a

which is
hserout 0,($08, $20, $00, $00, $00, $0A, CR)
hserout 0,($01, $02, $03, $04, $05, $06, $07, $08, $09, $0A)

Note that there are 10 bytes specified in ascii (not hex) in the 'wrf' line
and then exactly 10 bytes in the second line.
 
Last edited:

stircrazy

New Member
Thanks again for the help. It's working perfectly now. Some interesting points:

  • When upgrading the Vdrive2 using the reflash (FTD) file from the website, you must rename the file to "FTRFB.FTD" for the upgrade to work correctly.
  • If you want to code the length of the write string as ASCII instead of binary (i.e., "wrf 10" instead of "wrf ",$00,$00,$00,0A), you first have to switch to the ASCII Monitor Mode using the "IPA" command.

In case anyone is working on a similar project, here's the code:

Code:
#picaxe 28x1
setfreq m4

'----------------------------------------------------------------------------------------------------
'Symbol Definitions

'Pinouts
						'pin 01 = reset		'Mini momentary pushbutton switch SPST
symbol LDR = 0				'pin 02 = ADC0			'ORP12 light dependent resistor
symbol accel_y = 1			'pin 03 = ADC1			'DE-ACCM3D accelerometer (Y-axis output)
symbol accel_x = 2			'pin 04 = ADC2			'DE-ACCM3D accelerometer (X-axis output)
symbol accel_z = 3			'pin 05 = ADC2			'DE-ACCM3D accelerometer (Z-axis output)
						'pin 06 = serial in		'USB/serial download cable circuit
						'pin 07 = serial out	'USB/serial download cable circuit
						'pin 08 = ground
						'pin 09 = resonator
						'pin 10 = resonator
						'pin 11 = timer clk		'MS24M miniature motion switch
symbol temp = 1			'pin 12 = input 1		'DS18B20 digital temperature sensor
symbol startstop = pin2		'pin 13 = input 2		'Mini momentary pushbutton switch SPST
						'pin 14 = i2c scl		'for DS1307 RTC
						'pin 15 = i2c sda		'for DS1307 RTC
symbol rx_433 = pin5	 	'pin 16 = input 5		'433 MHz receiver connected through Picaxe 08M
						'pin 17 = ser tx		'connects to RXD on Vdrive2 
						'pin 18 = ser rx		'connects to TXD on Vdrive2
						'pin 19 = ground
						'pin 20 = V+
symbol piezo = 0			'pin 21 = output 0		'Mini Piezo Buzzer
						'pin 22 = output 1		'(not used)
						'pin 23 = output 2		'(not used)
						'pin 24 = output 3		'(not used)
						'pin 25 = output 4		'(not used)
						'pin 26 = output 5		'(not used)
symbol LED_red = 6			'pin 27 = output 6		'3mm bicolour LED (red)
symbol LED_green = 7		'pin 28 = output 7		'3mm bicolour LED (green)

'Variables
symbol temp_byte = b0
symbol first_byte = b1							'first byte of Vdrive2 response
symbol second_byte = b2							'second byte of Vdrive2 response
symbol third_byte = b3							'third byte of Vdrive2 response
symbol temp_word = w1


'----------------------------------------------------------------------------------------------------
'Begin Program

main:

	low LED_red
	low LED_green
	low piezo
	hi2csetup i2cmaster,%11010000,i2cslow,i2cbyte   	'setup DS1307 RTC over i2c bus
	hsersetup b9600_4,%01						'setup Vdrive2 over hardware serial pins
	settimer count 65535						'setup internal counter for motion switch

wait_press1:
	nap 1
	if startstop = 0 then wait_press1				'loop until startstop button is pressed
	
wait_unpress1:
	nap 1
	if startstop = 1 then wait_unpress1			'loop until startstop button is released
	
	high LED_green								'steady green LED indicates mission in progress
	sound piezo,(96,8,0,8,96,8)					'double beep indicates mission start

init_vdrive2:									'send Es until Vdrive2 responds correctly
	hserout 0,("E",CR)
	gosub get_response
	if first_byte <> "E" then init_vdrive2

check_disk:									'check for valid USB drive on Vdrive2
	hserout 0,(CR)								'response will start D for yes and N for no 
	gosub get_response
	if first_byte <> "D" then check_disk 

	hserout 0,("FWV",CR)
	gosub get_response

	hserout 0,("opw log.csv",CR)					'open "log.csv" on USB drive
	gosub get_response
	
	hserout 0,("wrf ",$00,$00,$00,$39,CR)
	hserout 0,("Date,Time,Temp,LDR,Motion,Accel_X,Accel_Y,Accel_Z,Rx_433,")
	pause 250
	gosub get_response

	let timer = 0								'reset internal counter for motion switch

'----------------------------------------------------------------------------------------------------		
'Mission (read data and save to Vdrive2 every 10 seconds)

mission:

	hi2cin 0,(b9)								'read second
	if startstop = 1 then pausestop
	let temp_byte = b9 AND %00001111				'copy digit of second to temp_byte
	if temp_byte <> 0 then goto mission			'loop until second is a multiple of 10
	
'Read Data

	low LED_green
	high LED_red

	hi2cin 4,(b4)								'read date 
	hi2cin 5,(b5)								'read month
	hi2cin 6,(b6)								'read year
	hi2cin 2,(b7)								'read hour
	hi2cin 1,(b8)								'read minute

	readtemp12 temp,w5
	readadc10 LDR,w6
	let w7 = timer
	let timer = 0								'reset internal counter for motion switch
	readadc10 accel_x,w8
	readadc10 accel_y,w9
	readadc10 accel_z,w10
	let b22 = rx_433

'Convert Data to ASCII and Write to Scratchpad

	let ptr = 64
	bcdtoascii b4,@ptrinc,@ptrinc
	bcdtoascii b5,@ptrinc,@ptrinc
	bcdtoascii b6,@ptrinc,@ptrinc
	bcdtoascii b7,@ptrinc,@ptrinc
	bcdtoascii b8,@ptrinc,@ptrinc
	bcdtoascii b9,@ptrinc,@ptrinc
	bintoascii w5,temp_byte,@ptrinc,@ptrinc,@ptrinc,@ptrinc
	bintoascii w6,temp_byte,@ptrinc,@ptrinc,@ptrinc,@ptrinc
	bintoascii w7,temp_byte,@ptrinc,@ptrinc,@ptrinc,@ptrinc
	bintoascii w8,temp_byte,@ptrinc,@ptrinc,@ptrinc,@ptrinc
	bintoascii w9,temp_byte,@ptrinc,@ptrinc,@ptrinc,@ptrinc
	bintoascii w10,temp_byte,@ptrinc,@ptrinc,@ptrinc,@ptrinc
	bintoascii b22,temp_byte,@ptrinc,@ptrinc
	
'Save Data to Vdrive2

	let ptr = 64
	hserout 0,("wrf ",$00,$00,$00,$36,CR)
	hserout 0,(LF,@ptrinc,@ptrinc,"/",@ptrinc,@ptrinc,"/20",@ptrinc,@ptrinc,",",@ptrinc,@ptrinc,":",@ptrinc,@ptrinc,":",@ptrinc,@ptrinc,",")
	hserout 0,(@ptrinc,@ptrinc,@ptrinc,@ptrinc,",",@ptrinc,@ptrinc,@ptrinc,@ptrinc,",",@ptrinc,@ptrinc,@ptrinc,@ptrinc,",",@ptrinc,@ptrinc,@ptrinc,@ptrinc,",",@ptrinc,@ptrinc,@ptrinc,@ptrinc,",",@ptrinc,@ptrinc,@ptrinc,@ptrinc,",",@ptrinc,@ptrinc,",")
	pause 250
	gosub get_response

	low LED_red
	high LED_green

goto mission

'----------------------------------------------------------------------------------------------------		
'Vdrive2 Subroutine to Get Response

get_response:
	pause 250

	get 0,first_byte 							'save the first byte received
	get 1,second_byte							'save the second byte received
	get 2,third_byte							'save the third byte received

	if first_byte = "D" and second_byte = "i" and third_byte = "s" then pausestop

	let hserptr = 0							'reset the background receive pointer 

return

'----------------------------------------------------------------------------------------------------
'Pause/Stop Mission

pausestop:
	low LED_red
	low LED_green
	sound piezo,(96,8,0,8,96,8,0,8,96,8)			'triple beep indicates mission pause/stop

	hserout 0,("wrf ",$00,$00,$00,$1A,CR)
	hserout 0,(LF,"Datalogger Paused/Stopped")
	pause 250
	gosub get_response
	
	hserout 0,("clf log.csv",CR)					'close "log.csv" on USB drive
	gosub get_response

wait_press2:
	nap 1
	if startstop = 0 then wait_press2				'loop until startstop button is pressed
	
wait_unpress2:
	nap 1
	if startstop = 1 then wait_unpress2			'loop until startstop button is released
	
	high LED_green								'steady green LED indicates mission in progress
	sound piezo,(96,8,0,8,96,8)					'double beep indicates mission start
	goto init_vdrive2

end
 

Technical

Technical Support
Staff member
Glad you got there, and thanks for posting as we're sure others will find it useful.
 

therowes

Member
I had a similar problem with a 1Gb Freecom stick, but everything worked ok on an unknown make 512Mb stick. I solved the problem by re-formatting the 1Gb stick and thats now ok ?
 

adumas

Member
Hi Stircrazy... I'm just beginning my datalogger project... I've first hard to slog my way working with the Vmusic module and of course ordering parts.

Do you have a schematic of the circuit you put together?

And I'd be curious to learn if you have learned anything new since your last posting? Problems with the code and/or module?

Appreciate the help.

Thanks.
 

stircrazy

New Member
Sorry, I never got past the breadboard stage with this project and have had to put it on hold for a while. I don't have a schematic because I used Excel to diagram the breadboard connections. But I can't find that file now. The pinout section at the top of the file should get you started with the wiring. Sorry I can't be of more help!
 
Top