#!/usr/bin.python

import sys, time
import Adafruit_BBIO.ADC as ADC
import Adafruit_BMP.BMP085 as BMP085
from datetime import datetime
sys.path.insert(0, './libraries')
from Adafruit_HMC6352 import HMC6352

gyroPin = 'P9_35'
accelXPin = 'P9_36'
accelYPin = 'P9_38'
accelZPin = 'P9_40'

bmp = BMP085.BMP085()
hmc = HMC6352()

f = open('data.csv', 'w')

def setup():
	ADC.setup()
	f.write("Year; Month; Day; Hours; Minutes; Seconds; Compass; Gyroscope; Accel X; Accel Y; Accel Z; Altitude\n")


def loop():
	getTime()
	getHeading()
	getGyro()
	getAccel("P9_36")
	getAccel("P9_38")
	getAccel("P9_40")
	getAltitude()
	print "."

def getTime():
	now = datetime.now()
	storeData(now.year, "; ")
	storeData(now.month, "; ")
	storeData(now.day, "; ")
	storeData(now.hour, "; ")
	storeData(now.minute, "; ")
	storeData(now.second, "; ")


def getHeading():
	value = hmc.readData()
	storeData(value, "; ")


def getGyro():
	value = ADC.read(gyroPin)
	storeData(value, "; ")

def getAccel(axis):
	zeroOffset = 0.4584
	conversionFactor = 0.0917
	rawRead = ADC.read(axis)
	value = (rawRead - zeroOffset) / conversionFactor
	storeData(value, "; ")

def getAltitude():
	value = bmp.read_altitude()
	storeData(value, "\n")

def storeData(data, chr):
	f.write(str(data)+chr)
setup()
while True:
	loop()

f.close()

@@ -200,16 +200,31 @@
 MC6352%0A%0A
+line = %220.0%5Cn%22%0A
 gyroPin 
@@ -513,16 +513,40 @@
 loop():%0A
+%09global line%0A%09line = %22%22%0A
 %09getTime
@@ -650,17 +650,43 @@
 ()%0A%09
-print %22.%22
+getTemp()%0A%09print %22*%22%0A%09f.write(line)
 %0A%0Ade
@@ -698,16 +698,29 @@
 Time():%0A
+%09global line%0A
 %09now = d
@@ -734,25 +734,27 @@
 .now()%0A%09
-storeData
+line += str
 (now.yea
@@ -754,34 +754,35 @@
 now.year
-, 
+)+
 %22; %22
-)
 %0A%09
-storeData
+line += str
 (now.mon
@@ -787,34 +787,35 @@
 onth
-, 
+)+
 %22; %22
-)
 %0A%09
-storeData
+line += str
 (now.day
 , %22;
@@ -810,34 +810,35 @@
 (now.day
-, 
+)+
 %22; %22
-)
 %0A%09
-storeData
+line += str
 (now.hou
@@ -838,34 +838,35 @@
 now.hour
-, 
+)+
 %22; %22
-)
 %0A%09
-storeData
+line += str
 (now.min
@@ -872,26 +872,27 @@
 nute
-, 
+)+
 %22; %22
-)
 %0A%09
-storeData
+line += str
 (now
@@ -898,24 +898,22 @@
 w.second
-, 
+)+
 %22; %22
-)%0A
 %0A%0Adef ge
@@ -920,24 +920,37 @@
 tHeading():%0A
+%09global line%0A
 %09value = hmc
@@ -962,39 +962,39 @@
 Data()%0A%09
-storeData
+line += str
 (value
-, 
+)+
 %22; %22
-)%0A
 %0A%0Adef ge
@@ -998,24 +998,37 @@
  getGyro():%0A
+%09global line%0A
 %09value = ADC
@@ -1043,38 +1043,39 @@
 roPin)%0A%09
-storeData
+line += str
 (value
-, 
+)+
 %22; %22
-)
 %0A%0Adef ge
@@ -1088,16 +1088,29 @@
 (axis):%0A
+%09global line%0A
 %09zeroOff
@@ -1231,30 +1231,31 @@
 or%0A%09
-storeData
+line += str
 (value
-, 
+)+
 %22; %22
-)
 %0A%0Ade
@@ -1271,16 +1271,29 @@
 tude():%0A
+%09global line%0A
 %09value =
@@ -1318,81 +1318,118 @@
 ()%0A%09
-storeData(value, %22%5Cn%22)%0A%0Adef storeData(data, chr):%0A%09f.write(str(data)+chr)
+line += str(value)+%22; %22%0A%0Adef getTemp():%0A%09global line%0A%09value = bmp.read_temperature()%0A%09line += str(value)+%22%5Cn%22%0A
 %0Aset

Add temperature information