diff --git a/accel.py b/accel.py index 46f2d78..3f25eff 100644 --- a/accel.py +++ b/accel.py @@ -19,39 +19,47 @@ # Make sure the out file is opened properly while 1: - try: - f1 = open('acceleration.csv','a') - # raise IOError - print "Successfully opened", f1.name - f1.write("Month,Day,Hour,Minute,Second,Xraw,Yraw,Zraw,X,Y,Z,Norm\n") - break - except Exception as err: - print 'Error:', err - time.sleep(1) + try: + f1 = open('acceleration.csv','a') + f2 = open('acceleration_errors.csv','a') + print "Successfully opened", f1.name + print "Successfully opened", f2.name + f1.write("Month,Day,Hour,Minute,Second,Xraw,Yraw,Zraw,X,Y,Z,Norm\n") + f2.write("Month,Day,Hour,Minute,Second,Error\n") + break + except Exception as error1: + print 'Error ' + str(error1) + time.sleep(1) # Get accelerometer values and write them to file -while 1 : - try: - now = datetime.datetime.now() - rawX = ADC.read("P9_36") - rawY = ADC.read("P9_38") - rawZ = ADC.read("P9_40") - - # Convert raw values to g values - # Reference: http://beagleboard.org/support/BoneScript/accelerometer/ - Xvalue = ((rawX * 3.6) - zeroOffsetX)/conversionFactorX - Yvalue = ((rawY * 3.6) - zeroOffsetY)/conversionFactorY - Zvalue = ((rawZ * 3.6) - zeroOffsetZ)/conversionFactorZ - - # raw input is multiplied by 3.6 because it has to be multiplied by 1.8 to get voltage and since it is hooked up to a voltage - # divider it also needs to be multiplied by 2 to get the original voltage - #print 'X =', str(Xvalue), 'Y =', str(Yvalue), 'Z =', str(Zvalue) - a = np.array([Xvalue, Yvalue, Zvalue]) - #print 'Norm =', str(np.linalg.norm(a)) - #print 'Xraw =', str(rawX * 3.6), 'Yraw =', str(rawY * 3.6), 'Zraw =', str(rawZ * 3.6) - f1.write(str(now.month)+','+str(now.day)+','+str(now.hour)+','+str(now.minute)+','+str(now.second)+','+str(rawX)+','+str(rawY)+','+str(rawZ)+','+str(Xvalue)+','+str(Yvalue)+','+str(Zvalue)+','+str(np.linalg.norm(a))+'\n') - except Exception as err: - print 'Error:', err - time.sleep(1) +while 1: + try: + now = datetime.datetime.now() + rawX = ADC.read("P9_36") + rawY = ADC.read("P9_38") + rawZ = ADC.read("P9_40") + + # Convert raw values to g values + # Reference: http://beagleboard.org/support/BoneScript/accelerometer/ + Xvalue = ((rawX * 3.6) - zeroOffsetX)/conversionFactorX + Yvalue = ((rawY * 3.6) - zeroOffsetY)/conversionFactorY + Zvalue = ((rawZ * 3.6) - zeroOffsetZ)/conversionFactorZ + + # raw input is multiplied by 3.6 because it has to be multiplied by 1.8 to get voltage and since it is hooked up to a voltage + # divider it also needs to be multiplied by 2 to get the original voltage + print 'X: ' + str(Xvalue) + print 'Y: ' + str(Yvalue) + print 'Z: ' + str(Zvalue) + a = np.array([Xvalue, Yvalue, Zvalue]) + print 'Norm: ' + str(np.linalg.norm(a)) + print 'Xraw: ' + str(rawX * 3.6) + print 'Yraw: ' + str(rawY * 3.6) + print 'Zraw: ' + str(rawZ * 3.6) + f1.write(str(now.month)+','+str(now.day)+','+str(now.hour)+','+str(now.minute)+','+str(now.second)+','+str(rawX)+','+str(rawY)+','+str(rawZ)+','+str(Xvalue)+','+str(Yvalue)+','+str(Zvalue)+','+str(np.linalg.norm(a))+'\n') + except Exception as error2: + print 'Error ' + str(error2) + f2.write(str(now.month)+','+str(now.day)+','+str(now.hour)+','+str(now.minute)+','+str(now.second)+','+str(error2)+'\n'); + time.sleep(1) -f1.close() \ No newline at end of file +f1.close() +f2.close() \ No newline at end of file diff --git a/accel_card.py b/accel_card.py index 2fae8c1..3a321d5 100644 --- a/accel_card.py +++ b/accel_card.py @@ -19,41 +19,47 @@ # Make sure the out file is opened properly while 1: - try: - f1 = open('/media/CARD/acceleration2.csv','a') - # raise IOError - print "Successfully opened", f1.name - f1.write("Month,Day,Hour,Minute,Second,Xraw,Yraw,Zraw,X,Y,Z,Norm\n") - break - - except Exception as err: - print 'Error:', err - time.sleep(1) + try: + f1 = open('/media/CARD/acceleration2.csv','a') + f2 = open('/media/CARD/acceleration_errors2.csv','a') + print "Successfully opened", f1.name + print "Successfully opened", f2.name + f1.write("Month,Day,Hour,Minute,Second,Xraw,Yraw,Zraw,X,Y,Z,Norm\n") + f2.write("Month,Day,Hour,Minute,Second,Error\n") + break + except Exception as error1: + print 'Error ' + str(error1) + time.sleep(1) # Get accelerometer values and write them to file -while 1 : - try: - now = datetime.datetime.now() - rawX = ADC.read("P9_36") - rawY = ADC.read("P9_38") - rawZ = ADC.read("P9_40") - - # Convert raw values to g values - # Reference: http://beagleboard.org/support/BoneScript/accelerometer/ - Xvalue = ((rawX * 3.6) - zeroOffsetX)/conversionFactorX - Yvalue = ((rawY * 3.6) - zeroOffsetY)/conversionFactorY - Zvalue = ((rawZ * 3.6) - zeroOffsetZ)/conversionFactorZ - - # raw input is multiplied by 3.6 because it has to be multiplied by 1.8 to get voltage and since it is hooked up to a voltage - # divider it also needs to be multiplied by 2 to get the original voltage - #print 'X =', str(Xvalue), 'Y =', str(Yvalue), 'Z =', str(Zvalue) - a = np.array([Xvalue, Yvalue, Zvalue]) - #print 'Norm =', str(np.linalg.norm(a)) - #print 'Xraw =', str(rawX * 3.6), 'Yraw =', str(rawY * 3.6), 'Zraw =', str(rawZ * 3.6) - f1.write(str(now.month)+','+str(now.day)+','+str(now.hour)+','+str(now.minute)+','+str(now.second)+','+str(rawX)+','+str(rawY)+','+str(rawZ)+','+str(Xvalue)+','+str(Yvalue)+','+str(Zvalue)+','+str(np.linalg.norm(a))+'\n') - except Exception as err: - print 'Error:', err +while 1: + try: + now = datetime.datetime.now() + rawX = ADC.read("P9_36") + rawY = ADC.read("P9_38") + rawZ = ADC.read("P9_40") + + # Convert raw values to g values + # Reference: http://beagleboard.org/support/BoneScript/accelerometer/ + Xvalue = ((rawX * 3.6) - zeroOffsetX)/conversionFactorX + Yvalue = ((rawY * 3.6) - zeroOffsetY)/conversionFactorY + Zvalue = ((rawZ * 3.6) - zeroOffsetZ)/conversionFactorZ - time.sleep(1) + # raw input is multiplied by 3.6 because it has to be multiplied by 1.8 to get voltage and since it is hooked up to a voltage + # divider it also needs to be multiplied by 2 to get the original voltage + print 'X: ' + str(Xvalue) + print 'Y: ' + str(Yvalue) + print 'Z: ' + str(Zvalue) + a = np.array([Xvalue, Yvalue, Zvalue]) + print 'Norm: ' + str(np.linalg.norm(a)) + print 'Xraw: ' + str(rawX * 3.6) + print 'Yraw: ' + str(rawY * 3.6) + print 'Zraw: ' + str(rawZ * 3.6) + f1.write(str(now.month)+','+str(now.day)+','+str(now.hour)+','+str(now.minute)+','+str(now.second)+','+str(rawX)+','+str(rawY)+','+str(rawZ)+','+str(Xvalue)+','+str(Yvalue)+','+str(Zvalue)+','+str(np.linalg.norm(a))+'\n') + except Exception as error2: + print 'Error ' + str(error2) + f2.write(str(now.month)+','+str(now.day)+','+str(now.hour)+','+str(now.minute)+','+str(now.second)+','+str(error2)+'\n'); + time.sleep(1) -f1.close() \ No newline at end of file +f1.close() +f2.close() \ No newline at end of file diff --git a/check_experiments.sh b/check_experiments.sh new file mode 100755 index 0000000..5e78609 --- /dev/null +++ b/check_experiments.sh @@ -0,0 +1,13 @@ +#!/bin/bash + + +ps aux | grep gps_raw +ps aux | grep pressure_kPa +ps aux | grep pressure_kPa_card +ps aux | grep temp +ps aux | grep temp_card +ps aux | grep extTemp +ps aux | grep extTemp_card +ps aux | grep accel +ps aux | grep accel_card + diff --git a/extTemp.py b/extTemp.py index 155b94b..97011db 100644 --- a/extTemp.py +++ b/extTemp.py @@ -8,39 +8,45 @@ #See June 4 comment on http://ealmberg.blogspot.com/2015/06/4-june-15.html -Bvalue = 3348 #Beta -Ro = 1000 #Resistance at 25 C -To = 298.15 #Room temperature in Kelvin +Bvalue = 3348 #Beta +Ro = 1000 #Resistance at 25 C +To = 298.15 #Room temperature in Kelvin # Make sure the out file is opened properly while 1: - try: - outfile = open('externalTemp.csv','a') - #raise IOError - print "Successfully opened", outfile.name - outfile.write("Month,Day,Hour,Minute,Second,ADC,Resistance,Kelvin,Celsius,Fahrenheit\n") - break - except Exception as err: - print 'Error:', err - time.sleep(1) + try: + f1 = open('externalTemp.csv','a') + f2 = open('externalTemp_errors.csv', 'a') + print "Successfully opened", f1.name + print "Successfully opened", f2.name + f1.write("Month,Day,Hour,Minute,Second,ADC,Resistance,Kelvin,Celsius,Fahrenheit\n") + f2.write("Month,Day,Hour,Minute,Second,Error\n") + break + except Exception as error1: + print 'Error ' + str(error1) + time.sleep(1) # Get thermistor values and write them to file while 1: - try: - now = datetime.datetime.now() - - adcValue = ADC.read("P9_35") - R = Ro/((1/adcValue) - 1) #Get measured resistance - kelvin = 1.0/To + (1.0/Bvalue)*mt.log(R/Ro) #Formula from above blogspot address - kelvin = 1.0/kelvin - celsius = kelvin - 273.15 - fahrenheit = celsius*(9/5.0) + 32.0 - - outfile.write(str(now.month)+','+str(now.day)+','+str(now.hour)+','+str(now.minute)+','+str(now.second)+','+str(adcValue)+','+str(R)+','+str(kelvin)+','+str(celsius)+','+str(fahrenheit)+'\n') - print str(kelvin) + 'K', str(celsius) + ' C', str(fahrenheit) + ' F' - except Exception as err: - print 'Error:', err - - time.sleep(1) - -outfile.close() \ No newline at end of file + try: + now = datetime.datetime.now() + + adcValue = ADC.read("P9_35") + R = Ro/((1/adcValue) - 1) #Get measured resistance + T = 1.0/To + (1.0/Bvalue)*mt.log(R/Ro) #Formula from above blogspot address + + t_k = 1.0/T #Temperature in Kelvin + print str(t_k) + 'K' + t_c = 1.0/T - 273.15 #Convert to celsius + print str(t_c) + 'C' + t_f = t_c*(9/5.0) + 32.0 #Convert to Fahrenheit + print str(t_f) + 'F' + + f1.write(str(now.month)+','+str(now.day)+','+str(now.hour)+','+str(now.minute)+','+str(now.second)+','+str(adcValue)+','+str(R)+','+str(t_k)+','+str(t_c)+','+str(t_f)+'\n'); + except Exception as error2: + print 'Error ' + str(error2) + f2.write(str(now.month)+','+str(now.day)+','+str(now.hour)+','+str(now.minute)+','+str(now.second)+','+str(error2)+'\n'); + time.sleep(1) + +f1.close() +f2.close() diff --git a/extTemp_card.py b/extTemp_card.py index c4c9a14..6c76edc 100644 --- a/extTemp_card.py +++ b/extTemp_card.py @@ -8,39 +8,45 @@ #See June 4 comment on http://ealmberg.blogspot.com/2015/06/4-june-15.html -Bvalue = 3348 #Beta -Ro = 1000 #Resistance at 25 C -To = 298.15 #Room temperature in Kelvin +Bvalue = 3348 #Beta +Ro = 1000 #Resistance at 25 C +To = 298.15 #Room temperature in Kelvin # Make sure the out file is opened properly while 1: - try: - outfile = open('/media/CARD/externalTemp2.csv','a') - #raise IOError - print "Successfully opened", outfile.name - outfile.write("Month,Day,Hour,Minute,Second,ADC,Resistance,Kelvin,Celsius,Fahrenheit\n") - break - except Exception as err: - print 'Error:', err - time.sleep(1) - -# Get thermisotr values and write them to file + try: + f1 = open('/media/CARD/externalTemp2.csv','a') + f2 = open('/media/CARD/externalTemp_errors2.csv', 'a') + print "Successfully opened", f1.name + print "Successfully opened", f2.name + f1.write("Month,Day,Hour,Minute,Second,ADC,Resistance,Kelvin,Celsius,Fahrenheit\n") + f2.write("Month,Day,Hour,Minute,Second,Error\n") + break + except Exception as error1: + print 'Error ' + str(error1) + time.sleep(1) + +# Get thermistor values and write them to file while 1: - try: - now = datetime.datetime.now() - - adcValue = ADC.read("P9_35") - R = Ro/((1/adcValue) - 1) #Get measured resistance - kelvin = 1.0/To + (1.0/Bvalue)*mt.log(R/Ro) #Formula from above blogspot address - kelvin = 1.0/kelvin - celsius = kelvin - 273.15 - fahrenheit = celsius*(9/5.0) + 32.0 - - outfile.write(str(now.month)+','+str(now.day)+','+str(now.hour)+','+str(now.minute)+','+str(now.second)+','+str(adcValue)+','+str(R)+','+str(kelvin)+','+str(celsius)+','+str(fahrenheit)+'\n') - print str(kelvin) + 'K', str(celsius) + ' C', str(fahrenheit) + ' F' - except Exception as err: - print 'Error:', err - - time.sleep(1) - -outfile.close() \ No newline at end of file + try: + now = datetime.datetime.now() + + adcValue = ADC.read("P9_35") + R = Ro/((1/adcValue) - 1) #Get measured resistance + T = 1.0/To + (1.0/Bvalue)*mt.log(R/Ro) #Formula from above blogspot address + + t_k = 1.0/T #Temperature in Kelvin + print str(t_k) + 'K' + t_c = 1.0/T - 273.15 #Convert to celsius + print str(t_c) + 'C' + t_f = t_c*(9/5.0) + 32.0 #Convert to Fahrenheit + print str(t_f) + 'F' + + f1.write(str(now.month)+','+str(now.day)+','+str(now.hour)+','+str(now.minute)+','+str(now.second)+','+str(adcValue)+','+str(R)+','+str(t_k)+','+str(t_c)+','+str(t_f)+'\n'); + except Exception as error2: + print 'Error ' + str(error2) + f2.write(str(now.month)+','+str(now.day)+','+str(now.hour)+','+str(now.minute)+','+str(now.second)+','+str(error2)+'\n'); + time.sleep(1) + +f1.close() +f2.close() diff --git a/main.py b/main.py deleted file mode 100644 index 8b028b4..0000000 --- a/main.py +++ /dev/null @@ -1,139 +0,0 @@ -import Adafruit_BBIO.ADC as ADC -import Adafruit_BBIO.UART as UART -import time -import datetime -import numpy as np -import serial -from pynmea import nmea -from Adafruit_I2C import Adafruit_I2C - -# Addresses for reading x,y,z axes of the magnotomer. They are stored in registers and read as most significant bits (msb) and least $ -# See page 11: -#http://www51.honeywell.com/aero/common/documents/myaerospacecatalog-documents/Defense_Brochures-documents/HMC5883L_3-Axis_Digital_Co$ - -gprmc = nmea.GPRMC() -mag_addr = 0x1E -config_register = 0x01 -X_msb = 0x03 -X_lsb = 0x04 -Z_msb = 0x05 -Z_lsb = 0x06 -Y_msb = 0x07 -Y_lsb = 0x08 - -i2c = Adafruit_I2C(mag_addr) - -UART.setup("UART2") - -ser = serial.Serial(port = "/dev/ttyO2", baudrate=9600) -ser.close() -ser.open() - -ADC.setup() - -# Based on observation of high and low raw readings of the accelerometer X 3.6 V. Then took the average of each. -zeroOffsetZ = 1.672 -zeroOffsetX = 1.595 -zeroOffsetY = 1.614 - -#The sensitivity or conversion factor is the average for each axis of the accelerometer minus low raw reading. -conversionFactorZ = 0.322 -conversionFactorY = 0.325 -conversionFactorX = 0.319 - -# Values off of the datasheet for Thermistor, to calculate temp -Bvalue = 3348 #Beta -Ro = 1000 #Resistance at 25 C -To = 298.15 #Room temperature Kelvin - -#create files and headers that we will save our data too -f1 = open('Data.csv','a') -f2 = open('rawData.csv','a'); -f1.write("Datestamp,Timestamp,Latitude,Longitude,Speed,Course,Accel Z,Accel Y,Accel X,Accel Norm,Mag Z,Mag Y,Mag X,Mag Norm,Int Temp,Ext Temp,Pressure,Sound,\n") -f2.write("Datestamp,Timestamp,Latitude,Longitude,Speed,Course,Accel Z,Accel Y,Accel X,Mag Z,May Y,Mag X,Int Temp,Ext Temp,Pressure,Sound\n") - -while 1 : - -# get gps data - gps = ser.readline() - while(not gps.startswith('$GPRMC')): - gps = ser.readline() - gprmc.parse(gps) - -# I2C code for reading the magnetometer - counter = 0 - for counter in xrange(0,10): #send the commands several times to ensure Magnetometer receives the command - Adafruit_I2C.write8(i2c, 0x00, 0x18) # 1 Average, 15 Hz, normal measurement - Adafruit_I2C.write8(i2c, 0x01, 0x20) # Set Gain - Adafruit_I2C.write8(i2c, 0x02, 0x00) # Continuous measurement - counter += 1 - z_l = Adafruit_I2C.readU8(i2c, Z_lsb) #Data is stored in 2 registers on the chip, the Least significant and the - z_m = Adafruit_I2C.readS8(i2c, Z_msb) #most significant. Both must be read and the two combined into the actual number - Zmag_raw = z_m << 8 | z_l - Zmag = Zmag_raw/2048.0 * 1.3 #Calculate Gauss value from the raw 12 bit number - - y_l = Adafruit_I2C.readU8(i2c, Y_lsb) #rinse and repeat for each axis - y_m = Adafruit_I2C.readS8(i2c, Y_msb) - Ymag_raw = y_m << 8 | y_l - Ymag = Ymag_raw/2048.0 * 1.3 - - x_l = Adafruit_I2C.readU8(i2c, X_lsb) - x_m = Adafruit_I2C.readS8(i2c, X_msb) - Xmag_raw = x_m << 8 | x_l - Xmag = Xmag_raw/2048.0 * 1.3 - - mag_vector = np.array([Xmag,Ymag,Zmag]) -# print 'Norm = ' + str(np.linalg.norm(mag_vector)); - -# read accelerometer axes, thermistors, and pressure sensor - Zaccel_raw = ADC.read("P9_40") - Yaccel_raw = ADC.read("P9_38") - Xaccel_raw = ADC.read("P9_36") - rawT_int = ADC.read("P9_37") #Inside payload thermistor - rawT_ext = ADC.read("P9_35") #External thermistor - rawP = ADC.read("P9_39") # read pressure sensor - - #convert raw voltage to pressure Kpa - formula derived from data sheet, page 11: http://sensing.honeywell.com/index.php?ci_id=151133 - p = ((rawP * 1.8 * 2 -.33)/1.65)*100 - - # Calculate Kelvin for internal thermistor - R = 1000/((1/rawT_int) - 1) #Get measured resistance - T_int = 1.0/To + (1.0/Bvalue)*np.log(R/Ro) #Formula from above blogspot address - T_int = 1.0/T_int - - # Calculate Kelvin for external thermistor - R = 1000/((1/rawT_ext) - 1) #Get measured resistance - T_ext = 1.0/To + (1.0/Bvalue)*np.log(R/Ro) #Formula from above blogspot address - T_ext = 1.0/T_ext - - # Calculate acceleration - Zaccel = ((Zaccel_raw * 3.6) - zeroOffsetZ)/conversionFactorZ; - Yaccel = ((Yaccel_raw * 3.6) - zeroOffsetY)/conversionFactorY; - Xaccel = ((Xaccel_raw * 3.6) - zeroOffsetX)/conversionFactorX; - - # raw input is multiplied by 3.6 because it has to be multiplied by 1.8 to get voltage and since it is hooked up to a voltage - # divider it also needs to be multiplied by 2 to get the original voltage - - #Below are the print statements used for debugging - - #print 'Z = '+str(Zvalue) + ' Y = ' + str(Yvalue) + ' X = ' + str(Xvalue); - accel_vector = np.array([Zaccel, Yaccel, Xaccel]) - #print 'Norm = ' + str(np.linalg.norm(a)); - #print 'Zraw = ' + str(rawZ * 3.6) + ' Yraw = ' + str(rawY * 3.6) + ' Xraw = ' + str(rawX * 3.6); - - #Console print the calculated temperature - #print str(T_int) + ' K' - #t_c = T_int - 273.15 #Convert to celsius - #print str(t_c) + ' C' - #t_f = t_c*(9/5.0) + 32.0 #Convert to Fahrenheit - #print str(t_f) - - #print str(rawPressure) + ' ' + str(p) - #write to csv file - - f1.write(gprmc.datestamp+','+gprmc.timestamp+','+gprmc.lat + gprmc.lat_dir+','+gprmc.lon + gprmc.lon_dir+','+gprmc.spd_over_grnd+','+gprmc.true_course+','+str(Zaccel)+','+str(Yaccel)+','+str(Xaccel)+','+str(np.linalg.norm(accel_vector))+','+str(Zmag)+','+str(Ymag)+','+str(Xmag)+','+str(np.linalg.norm(mag_vector))+','+str(T_int)+','+str(T_ext)+','+str(p)+'\n') - f2.write(gprmc.datestamp+','+gprmc.timestamp+','+gprmc.lat + gprmc.lat_dir+','+gprmc.lon + gprmc.lon_dir+','+gprmc.spd_over_grnd+','+gprmc.true_course+','+ str(Zaccel_raw)+','+str(Yaccel_raw)+','+str(Xaccel_raw)+','+ str(Zmag_raw)+','+str(Ymag_raw)+','+str(Xmag_raw)+','+str(rawT_int)+','+str(rawT_ext)+','+str(rawP)+'\n'); - print "datapoint" - time.sleep(1) -f1.close() -f2.close() diff --git a/pressure_kPa.py b/pressure_kPa.py index 0771def..36512a9 100755 --- a/pressure_kPa.py +++ b/pressure_kPa.py @@ -8,27 +8,30 @@ while 1: try: f1 = open('pressure.csv', 'a') - if not f1.closed: - f1.write("Month,Day,Hour,Minute,Second,p,rawP\n") - break + f2 = open('pressure_errors.csv', 'a') + print "Successfully opened", f1.name + print "Successfully opened", f2.name + f1.write("Month,Day,Hour,Minute,Second,p,rawP\n") + f2.write("Month,Day,Hour,Minute,Second,Error\n") + break except Exception as error1: print 'Error ' + str(error1) time.sleep(1) while 1: - now = datetime.datetime.now() - rawP = ADC.read("P9_39") - p = ((rawP * 1.8 * 2 -.33)/1.65)*100 - print str(rawP) + ' ' + str(p) try: + now = datetime.datetime.now() + + rawP = ADC.read("P9_39") + print 'Raw Pressure: ' + str(rawP) + p = ((rawP * 1.8 * 2 -.33)/1.65)*100 + print 'Pressure: ' + str(p) + f1.write(str(now.month)+','+str(now.day)+','+str(now.hour)+','+str(now.minute)+','+str(now.second)+','+str(p)+','+str(rawP)+'\n') - time.sleep(1) except Exception as error2: print 'Error ' + str(error2) + f2.write(str(now.month)+','+str(now.day)+','+str(now.hour)+','+str(now.minute)+','+str(now.second)+','+str(error2)+'\n'); + time.sleep(1) -try: - f1.close() - if f1.closed: - pass -except Exception as error3: - print 'Error ' + str(error3) +f1.close() +f2.close() diff --git a/pressure_kPa_card.py b/pressure_kPa_card.py index 49ffeb9..f19b8cb 100644 --- a/pressure_kPa_card.py +++ b/pressure_kPa_card.py @@ -8,27 +8,30 @@ while 1: try: f1 = open('/media/CARD/pressure2.csv', 'a') - if not f1.closed: - f1.write("Month,Day,Hour,Minute,Second,p,rawP\n") - break + f2 = open('/media/CARD/pressure_errors2.csv', 'a') + print "Successfully opened", f1.name + print "Successfully opened", f2.name + f1.write("Month,Day,Hour,Minute,Second,p,rawP\n") + f2.write("Month,Day,Hour,Minute,Second,Error\n") + break except Exception as error1: print 'Error ' + str(error1) time.sleep(1) while 1: - now = datetime.datetime.now() - rawP = ADC.read("P9_39") - p = ((rawP * 1.8 * 2 -.33)/1.65)*100 - print str(rawP) + ' ' + str(p) try: + now = datetime.datetime.now() + + rawP = ADC.read("P9_39") + print 'Raw Pressure: ' + str(rawP) + p = ((rawP * 1.8 * 2 -.33)/1.65)*100 + print 'Pressure: ' + str(p) + f1.write(str(now.month)+','+str(now.day)+','+str(now.hour)+','+str(now.minute)+','+str(now.second)+','+str(p)+','+str(rawP)+'\n') - time.sleep(1) except Exception as error2: print 'Error ' + str(error2) + f2.write(str(now.month)+','+str(now.day)+','+str(now.hour)+','+str(now.minute)+','+str(now.second)+','+str(error2)+'\n'); + time.sleep(1) -try: - f1.close() - if f1.closed: - pass -except Exception as error3: - print 'Error ' + str(error3) \ No newline at end of file +f1.close() +f2.close() diff --git a/start_experiments.sh b/start_experiments.sh deleted file mode 100644 index a2ecf7e..0000000 --- a/start_experiments.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - - -nohup pressure_kPa.py & -nohup temp.py & -nohup extTemp.py & \ No newline at end of file diff --git a/start_experiments_with_comp.sh b/start_experiments_with_comp.sh new file mode 100755 index 0000000..06474aa --- /dev/null +++ b/start_experiments_with_comp.sh @@ -0,0 +1,12 @@ +#!/bin/bash + + +python gps_raw.py +python pressure_kPa.py +python pressure_kPa_card.py +python temp.py +python temp_card.py +python extTemp.py +python extTemp_card.py +python accel.py +python accel_card.py \ No newline at end of file diff --git a/start_experiments_without_comp.sh b/start_experiments_without_comp.sh new file mode 100755 index 0000000..6f0c5cc --- /dev/null +++ b/start_experiments_without_comp.sh @@ -0,0 +1,12 @@ +#!/bin/bash + + +nohup python gps_raw.py & +nohup python pressure_kPa.py & +nohup python pressure_kPa_card.py & +nohup python temp.py & +nohup python temp_card.py & +nohup python extTemp.py & +nohup python extTemp_card.py & +nohup python accel.py & +nohup python accel_card.py & \ No newline at end of file diff --git a/temp.py b/temp.py index 7dba8ec..2e01904 100644 --- a/temp.py +++ b/temp.py @@ -9,47 +9,44 @@ #See June 4 comment on http://ealmberg.blogspot.com/2015/06/4-june-15.html Bvalue = 3348 #Beta -Ro = 1000 #Resistance at 25 C - room temperature -To = 298.15 #Room temperature Kelvin +Ro = 1000 #Resistance at 25 C +To = 298.15 #Room temperature in Kelvin -while 1 +# Make sure the out file is opened properly +while 1: try: - f1 = open('temp.csv', 'a') - #raise IOError - if not f1.closed: - print "Successfully opened", f1.name - f1.write("Month,Day,Hour,Minute,Second,ADC,Resistance,Kelvin,Celsius,Fahrenheit\n") - break - except Exception as error1: - print 'Error ' + str(error1) - time.sleep(1) - + f1 = open('temp.csv', 'a') + f2 = open('temp_errors.csv', 'a') + print "Successfully opened", f1.name + print "Successfully opened", f2.name + f1.write("Month,Day,Hour,Minute,Second,ADC,Resistance,Kelvin,Celsius,Fahrenheit\n") + f2.write("Month,Day,Hour,Minute,Second,Error\n") + break + except Exception as error1: + print 'Error ' + str(error1) + time.sleep(1) + +# Get thermistor values and write them to file while 1: - try: - now = datetime.datetime.now() - - adcValue = ADC.read("P9_37") - R = Ro/((1/adcValue) - 1) #Get measured resistance - T = 1.0/To + (1.0/Bvalue)*mt.log(R/Ro) #Formula from above blogspot address - - t_k = 1.0/T #Temperature in Kelvin - print str(t_k) + 'K' - t_c = 1.0/T - 273.15 #Convert to celsius - print str(t_c) + 'C' - t_f = t_c*(9/5.0) + 32.0 #Convert to Fahrenheit - print str(t_f) + 'F' - #print str(adcValue) +', ' + str(1/adcValue) + ', ' + str(1/adcValue - 1) + ', ' + str(R) - #print unichr(176) - #print u"\u00B0" - f1.write(str(now.month)+','+str(now.day)+','+str(now.hour)+','+str(now.minute)+','+str(now.second)+','+str(adcValue)+','+str(R)+','+str(t_k)+','+str(t_c)+','+str(t_f)+'\n'); - except Exception as error2: - print 'Error ' + str(error2) - - time.sleep(1) - -try: - f1.close() - if f1.closed: - pass -except Exception as error3: - print 'Error ' + str(error3) + try: + now = datetime.datetime.now() + + adcValue = ADC.read("P9_37") + R = Ro/((1/adcValue) - 1) #Get measured resistance + T = 1.0/To + (1.0/Bvalue)*mt.log(R/Ro) #Formula from above blogspot address + + t_k = 1.0/T #Temperature in Kelvin + print str(t_k) + 'K' + t_c = 1.0/T - 273.15 #Convert to celsius + print str(t_c) + 'C' + t_f = t_c*(9/5.0) + 32.0 #Convert to Fahrenheit + print str(t_f) + 'F' + + f1.write(str(now.month)+','+str(now.day)+','+str(now.hour)+','+str(now.minute)+','+str(now.second)+','+str(adcValue)+','+str(R)+','+str(t_k)+','+str(t_c)+','+str(t_f)+'\n'); + except Exception as error2: + print 'Error ' + str(error2) + f2.write(str(now.month)+','+str(now.day)+','+str(now.hour)+','+str(now.minute)+','+str(now.second)+','+str(error2)+'\n'); + time.sleep(1) + +f1.close() +f2.close() diff --git a/temp_card.py b/temp_card.py index 543ec80..0170e81 100644 --- a/temp_card.py +++ b/temp_card.py @@ -9,47 +9,44 @@ #See June 4 comment on http://ealmberg.blogspot.com/2015/06/4-june-15.html Bvalue = 3348 #Beta -Ro = 1000 #Resistance at 25 C - room temperature -To = 298.15 #Room temperature Kelvin +Ro = 1000 #Resistance at 25 C +To = 298.15 #Room temperature in Kelvin -while 1 +# Make sure the out file is opened properly +while 1: try: - f1 = open('/media/CARD/temp2.csv', 'a') - #raise IOError - if not f1.closed: - print "Successfully opened", f1.name - f1.write("Month,Day,Hour,Minute,Second,ADC,Resistance,Kelvin,Celsius,Fahrenheit\n") - break - except Exception as error1: - print 'Error ' + str(error1) - time.sleep(1) - + f1 = open('/media/CARD/temp2.csv', 'a') + f2 = open('/media/CARD/temp_errors2.csv', 'a') + print "Successfully opened", f1.name + print "Successfully opened", f2.name + f1.write("Month,Day,Hour,Minute,Second,ADC,Resistance,Kelvin,Celsius,Fahrenheit\n") + f2.write("Month,Day,Hour,Minute,Second,Error\n") + break + except Exception as error1: + print 'Error ' + str(error1) + time.sleep(1) + +# Get thermistor values and write them to file while 1: - try: - now = datetime.datetime.now() - - adcValue = ADC.read("P9_37") - R = Ro/((1/adcValue) - 1) #Get measured resistance - T = 1.0/To + (1.0/Bvalue)*mt.log(R/Ro) #Formula from above blogspot address - - t_k = 1.0/T #Temperature in Kelvin - print str(t_k) + 'K' - t_c = 1.0/T - 273.15 #Convert to celsius - print str(t_c) + 'C' - t_f = t_c*(9/5.0) + 32.0 #Convert to Fahrenheit - print str(t_f) + 'F' - #print str(adcValue) +', ' + str(1/adcValue) + ', ' + str(1/adcValue - 1) + ', ' + str(R) - #print unichr(176) - #print u"\u00B0" - f1.write(str(now.month)+','+str(now.day)+','+str(now.hour)+','+str(now.minute)+','+str(now.second)+','+str(adcValue)+','+str(R)+','+str(t_k)+','+str(t_c)+','+str(t_f)+'\n'); - except Exception as error2: - print 'Error ' + str(error2) - - time.sleep(1) - -try: - f1.close() - if f1.closed: - pass -except Exception as error3: - print 'Error ' + str(error3) + try: + now = datetime.datetime.now() + + adcValue = ADC.read("P9_37") + R = Ro/((1/adcValue) - 1) #Get measured resistance + T = 1.0/To + (1.0/Bvalue)*mt.log(R/Ro) #Formula from above blogspot address + + t_k = 1.0/T #Temperature in Kelvin + print str(t_k) + 'K' + t_c = 1.0/T - 273.15 #Convert to celsius + print str(t_c) + 'C' + t_f = t_c*(9/5.0) + 32.0 #Convert to Fahrenheit + print str(t_f) + 'F' + + f1.write(str(now.month)+','+str(now.day)+','+str(now.hour)+','+str(now.minute)+','+str(now.second)+','+str(adcValue)+','+str(R)+','+str(t_k)+','+str(t_c)+','+str(t_f)+'\n'); + except Exception as error2: + print 'Error ' + str(error2) + f2.write(str(now.month)+','+str(now.day)+','+str(now.hour)+','+str(now.minute)+','+str(now.second)+','+str(error2)+'\n'); + time.sleep(1) + +f1.close() +f2.close() \ No newline at end of file