'--------------------------- Set Picaxe type ---------------------
#picaxe 28X2
'------------------------ Setup Symbols --------------------------
symbol Log_Counter =w0
symbol Counted_Logs =w1
symbol Flight_Trigger=pinC.2
symbol Memory_Add_I =w6
symbol Memory_Add_O =w7
symbol Char1=b16
symbol Log_Time =w10
symbol Log_T =w11
'------------------------ Setup Counters -------------------------
Log_Counter=30 'The number of logs to make during flight (NB max of 8000 redings for 512KBit's Memoru chip 24LC512)
Log_Time=0 '# The time between logs In seconds up op 65535 (NB 0=1Sec ans 1=2Sec)
'----------------------- Setup EEPROM -----------------------------
hi2csetup i2cmaster, %10100000, i2cfast, i2cword
'Is the Flight Pin Pulled Yes/No
if Flight_Trigger=1 then
'Yes (continue)
else
'No
'-----Set i2cEEPROM Add to 0----
Memory_Add_I=0
write 0,b12
write 1,b13
Counted_Logs=0
write 2,b2
write 3,b3
sertxd (cr,lf," @@@@@@@@@@@@ Memory Reset @@@@@@@@@@ ",cr,lf)
Log_T =0
'-------------------------------
goto main
end if
'------------------ Record Count full Yes/No -----------------------
'read counted logs
read 2,b2
read 3,b3
'------------------
if Counted_Logs=Log_Counter then
'Yes
goto Read_Memory
else
'No
goto main
end if
'--------------------------- MAIN ----------------------------------
main:
pause 10'450
low B.1
'-------------------
GoSub Battry_Voltage
GoSub Read_LDR
GoSub Read_temp1
GoSub Read_temp2
'Is the Flight Pin Pulled Yes/No
if Flight_Trigger=1 then
'Yes
if log_Time <log_T then
GoSub Data_To_Memmory
Log_T=0
endif
else
'No
GoSub PC_Disply
end if
'-------------------
high B.1
pause 10'450
Log_T=Log_T+1
sertxd (#log_T," ")
'debug
goto main
'---------------------------Batary Voltage monitor--------------------
Battry_Voltage:
readadc A.0, W4
w4 = w4 * 40/100 'Scale/MAP 40/100
bintoascii W4,b6,b6,b6,b6,b7
return
'----------------------------LDR Light intensity----------------------
Read_LDR:
readadc A.1,W5 ; read ADC1 into variable b0
'bintoascii W5,b18,b18,b18,b18,b19
return
'----------------------------Internal Tempratur-----------------------
Read_temp1:
readtemp C.0,b24 ; read input 1 into variable b0
'readtemp C.0,b25 ; read input 1 into variable b0
return
'----------------------------Externap Tempratur-----------------------
Read_temp2:
readtemp C.1,b26 ; read input 1 into variable b0
return
'----------------------------Disply on PC Whill Flight pin In---------
PC_Disply:
sertxd (" ",b6,",",b7,"V")
sertxd (" LDR ",#w5," ")
if b24 > 127 then
let b25 = b24 - 128
sertxd (" I-Temp -",#b25," ")
else
sertxd (" I-Temp ",#b24," ")
end if
'------------------------
if b26 > 127 then
let b27 = b26 - 128
sertxd (" E-Temp -",#b27,cr,lf)
else
sertxd (" E-Temp ",#b26,cr,lf)
end if
return
'============================= Data to Memory =============================
Data_To_Memmory:
read 0,b12
read 1,b13
'sertxd ("Mem Add ",#W6,cr,lf)
if Log_Counter = Counted_Logs Then
Goto Task_Comp
else
' Increment log counter---------------------------------------------
Counted_Logs=Counted_Logs+1
sertxd (cr,lf,"Writing record ",#Counted_Logs," ")
'-------------------------------------------------------------------
'Write Start Byt to i2cEEPROM -------------------------------------------
writei2c Memory_Add_I,("#") ' Start marker
pause 10 ' wait 10 ms for write
Memory_Add_I=Memory_Add_I+1
'Write Battart voltage to i2cEEPROM -------------------------------
writei2c Memory_Add_I,(b6) ' write the Volt record to memory
pause 10 ' wait 10 ms for write
Memory_Add_I=Memory_Add_I+1
writei2c Memory_Add_I,(b7) ' write the Milie Volt record to memory
pause 10 ' wait 10 ms for write
Memory_Add_I=Memory_Add_I+1
'Write LDR to i2cEEPROM -------------------------------------------
writei2c Memory_Add_I,(b10) ' write LDR record to memory
pause 10 ' wait 10 ms for write
Memory_Add_I=Memory_Add_I+1
writei2c Memory_Add_I,(b11) ' write the LDR record to memory
pause 10 ' wait 10 ms for write
Memory_Add_I=Memory_Add_I+1
'Write Internal Tempratur to i2cEEPROM----------------------------------
writei2c Memory_Add_I,(b24) ' Internal Tempratur to memory
pause 10 ' wait 10 ms for write
Memory_Add_I=Memory_Add_I+1
'Write Ecternal Tempratur to i2cEEPROM----------------------------------
writei2c Memory_Add_I,(b26) ' Ecternal Tempratur to memory
pause 10 ' wait 10 ms for write
Memory_Add_I=Memory_Add_I+1
'Write Stop Byt to i2cEEPROM -------------------------------------------
writei2c Memory_Add_I,("; ") ' write LDR record to memory
pause 10 ' wait 10 ms for write
Memory_Add_I=Memory_Add_I+1
'Store Memory Counter
write 0,b12
write 1,b13
'Store counted logs
write 2,b2
write 3,b3
end if
return
'---------------------------------------------------------------------
Read_Memory:
sertxd (cr,lf,"##################### READING MEMORY ##################",cr,lf)
'Read last Addres
read 0,b12
read 1,b13
sertxd ("End Addres= ",#Memory_Add_I,cr,lf)
For Memory_Add_O=0 to Memory_Add_I
high B.1
'Start byt
pause 10 ' wait 10 ms for write
readi2c Memory_Add_O,(Char1)
pause 10 ' wait 10 ms for write
sertxd (Char1," ")
pause 10
Memory_Add_O=Memory_Add_O+1
'Voltage
readi2c Memory_Add_O,(Char1)
pause 10 ' wait 10 ms for write
sertxd (Char1,",")
pause 10
Memory_Add_O=Memory_Add_O+1
'Millie Voltage
readi2c Memory_Add_O,(Char1)
pause 10 ' wait 10 ms for write
sertxd (Char1,"V ")
pause 10
Memory_Add_O=Memory_Add_O+1
'LDR
readi2c Memory_Add_O,(b4)
pause 10 ' wait 10 ms for write
Memory_Add_O=Memory_Add_O+1
readi2c Memory_Add_O,(b5)
pause 10 ' wait 10 ms for write
Memory_Add_O=Memory_Add_O+1
sertxd ("Light_Intencity=",#W2,",")
pause 10
'Internal Tempratur
readi2c Memory_Add_O,(b4)
pause 10 ' wait 10 ms for write
Memory_Add_O=Memory_Add_O+1
if b4 > 127 then
let b25 = b4 - 128
sertxd (" Inside_Cube-Temperature -",#b25," ")
else
sertxd (" Inside_Cube-Temperature ",#b4," ")
end if
'---------LED Off-----------
low B.1
'External Tempratur
readi2c Memory_Add_O,(b4)
pause 10 ' wait 10 ms for write
Memory_Add_O=Memory_Add_O+1
if b4 > 127 then
let b27 = b4 - 128
sertxd (" Outside-Temperature -",#b27," ")
else
sertxd (" Outside-Temperature ",#b4," ")
end if
'Stop Byt
readi2c Memory_Add_O,(Char1)
pause 10 ' wait 10 ms for write
sertxd (Char1,cr,lf)
pause 10
Next Memory_Add_O
'return
'---------------------------------------------------------------------
Task_Comp:
'pause 1000
high B.1
pause 200
low B.1
pause 200
Goto Task_Comp
'---------------------------------------------------------------------
Then the Camera Code below:
Camera:
high B.5 'Camera On
pause 250
low B.5
pause 250
wait 5
Video:
toggle B.7 ; toggle output 7
pause 10000 ; wait for 10 seconds
wait 15
goto Camera: ; loop back to start