Steven and Joey's Spectacular Space Adventure
Pages
Home
Spot Powered Tracking
Flight Data Logger and Code
Trackuino-Nano Radio Tracking
Flight Data Logger and Code
This Code is similar to the standalone GPS logger except it also includes a humidity sensor, altimeter,temperature sensor, and barametric pressure sensor.
All data is logged to a .csv file on an SD Card which can be viewed in Excel.
/* This Sketch uses the TinyGPS library and SD card library to log GPS data and save it on a SD card. Important: This version is intended for Arduino 1.0.1 IDE. It will not compile in earlier versions. Be sure the following files are present in the libraries folder: TinyGPS.h Adafruit_BMP085.h Written By: Joseph Magnus Date: 10/18/2012 */ #include
//Standard Software Serial Library #include
// Version for 1.0.1 #include
// Standard Arduino SD card Library #include
#include
File myFile; Adafruit_BMP085 bmp; TinyGPS gps; SoftwareSerial nss(6, 255); //Yellow wire to pin 6. (Based on using Parallax 28500-RT PMB-648 GPS SiRF III Internal Antenna) int led = 13; //Pin 13 is declared as led //declare variables for GPS float flat, flon; unsigned long age, time, date, speed, course, satellites, altitude, speedmps; //end variable declaration for GPS //Declare variable declaration for Humidity Sensor int humPin = 0; //// Humidity sensor on Analog pin 0 //end variable declaration for Humidity Sensor //declare variables for temp sensor int tempPin = 2; // TMP-36 on Analog pin 2 int tempReading = 0; float temperatureC = 0; float temperatureF = 0; const int interval = 10*100; // the interval between sensor reads, in ms long lastReadTime = 0; // the last time you read the sensor, in ms //end variable declaration for temp sensor //Setup void setup() { Serial.begin(9600); nss.begin(4800); bmp.begin(); pinMode(led, OUTPUT); digitalWrite(led, HIGH); Serial.println("Flight_DATA_LOGGER"); Serial.println("WRITTEN BY: Joseph Magnus"); delay(1000); Serial.println("...................."); delay(1000); Serial.println("***"); //Initialize Barometer Serial.println("Initializing Barometer..."); delay(1000); Serial.println("Initialization Completed Successfully!"); // End initialize Barometer // Initialize SD card Serial.println("Initializing SD card..."); delay(2000); pinMode(10, OUTPUT); //Set SD Card Pin to digital pin 10 if (!SD.begin(10)) //If no SD card available then fail { Serial.println("Initialization Failed!"); return; } Serial.println("Initialization Completed Successfully!"); // End initialize SD Card digitalWrite(led, LOW); } //End Setup //Begin Loop void loop() { bool newdata = true; unsigned long start = millis(); while (millis() - start < 5000) { // Update every 5 seconds if (feedgps()) newdata = true; } if (newdata) { gpsdump(gps); } } void gpsdump(TinyGPS &gps) { //Start GPS read gps.f_get_position(&flat, &flon, &age); gps.get_datetime(&date, &time); speedmps = gps.f_speed_mps(); satellites = gps.satellites(); altitude = gps.f_altitude(); course = gps.course(); //End GPS read delay(1000); //Start TMP36 temp sensor read tempReading = analogRead(tempPin); // READ TEMPERATURE float tempVoltage = tempReading * 5; // convert readings to voltage, using 5V power supply tempVoltage /= 1024.0; temperatureC = (tempVoltage - 0.5) * 100 ; // now print out the temperature degrees C temperatureF = (temperatureC * 9.0 / 5.0) + 32.0; // now convert to Fahrenheight //End TMP36 temp sensor read //Start Humidity sensor read int humReading = analogRead(humPin); // read the value from the pin double volt = humReading / 1023.0 * 5; // convert it into voltage (Vcc = 5V) double sensorRH = 161.*volt/5 - 25.8; // calculate the sensor humitidy double trueRH = sensorRH / (1.0546 - 0.0026*temperatureC);// adapt this for the given temperature //end humidity sensor reading //Print data to Serial Debug Serial.println("Data Prints Correctly"); Serial.print(flat, 4); Serial.print(", "); Serial.print(flon, 4); Serial.print(", "); Serial.print(date); Serial.print(", "); Serial.println(time); //End Serial print digitalWrite(led, HIGH); //LED on before opening file // Open Tracking.csv from SD Card myFile = SD.open("tracking.csv", FILE_WRITE); // if the file opened okay, write to it: if (myFile) { Serial.print("Writing to Tracking.csv..."); myFile.print(flat, 4); myFile.print(", "); myFile.print(flon, 4); myFile.print(", "); myFile.print(altitude); myFile.print(", "); myFile.print(date); myFile.print(", "); myFile.print(time); myFile.print(", "); myFile.print(satellites); myFile.print(", "); myFile.print(course); myFile.print(", "); myFile.print(speedmps); myFile.print(", "); myFile.print(bmp.readTemperature()); myFile.print(", "); myFile.print(bmp.readPressure()); myFile.print(", "); myFile.print(bmp.readAltitude()); myFile.print(", "); myFile.print(temperatureC); myFile.print(", "); myFile.print(temperatureF); myFile.print(", "); myFile.print(sensorRH); myFile.print(", "); myFile.println(trueRH); delay(200); // close the file: myFile.close(); digitalWrite(led, LOW); Serial.println("done."); } else { // if the file didn't open, print an error: Serial.println("error opening tracking.csv"); } } // Feed data as it becomes available bool feedgps() { while (nss.available()) { if (gps.encode(nss.read())) return true; } return true; }
No comments:
Post a Comment
Home
Subscribe to:
Posts (Atom)
No comments:
Post a Comment