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:
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
-
6.8 KB Views: 53