/ Published in: Processing
- Temperature sensors are programmed to operate in external power mode (not parasite power)\r\n* Libraries required: OneWire and DallasTemperature\r\n* The GPS parser was programmed purely by myself; the temperature sensing code is derived from the sample code for the DallasTemperature library, which is licensed under the LGPL
Expand |
Embed | Plain Text
#include <OneWire.h> #include <DallasTemperature.h> #include <string.h> OneWire therm1(8); OneWire therm2(10); DallasTemperature sensor_inside(&therm1); DallasTemperature sensor_outside(&therm2); char incomingByte, nmea[71], final_lat[9], final_lon[11], final_time[10], final_alt[9], msg[70], arrayItem[15][20], itemCount, temp_inside[10], temp_outside[10]; int currentCharIndex = 0, readingLine = 0, i, n_or_s, e_or_w, count = 0, z, indexAfterDelimiter; double lat, lon, lat_minutes, lon_minutes; void setup() { // START: temperature sensor initialization code sensor_inside.begin(); sensor_outside.begin(); // END: temperature sensor initialization code // Output format: Time(UTC),Latitude(Decimal Degs),Longitude,# of Satellites in view,Altitude(km),Other Alt,Temperature inside (C), Temperature outside (C) Serial.begin(4800); } void split() { itemCount = 0; for(i=0;i<strlen(nmea);i++) { if(nmea[i]!=',') { arrayItem[itemCount][indexAfterDelimiter] = nmea[i]; indexAfterDelimiter++; } else { indexAfterDelimiter = 0; itemCount++; } } } double get_from_arrayItem(int item_index, int start_index, int end_index) { char retrieved[end_index-start_index]; for(int i=0;i<=end_index-start_index;i++) { retrieved[i] = arrayItem[item_index][start_index+i]; } return atof(retrieved); } void loop() { if(Serial.available()) { incomingByte = Serial.read(); if(incomingByte=='$') { // start of line readingLine = 1; } else if(incomingByte=='*') { // end of useful data readingLine = 0; if(nmea[3]=='G'&&nmea[4]=='G'&&nmea[5]=='A') { // check if line starts with $GPGGA sensor_inside.requestTemperatures(); sensor_outside.requestTemperatures(); split(); lat = get_from_arrayItem(2, 0, 1); lat_minutes = get_from_arrayItem(2, 2, strlen(arrayItem[2])-1); lon = get_from_arrayItem(4, 0, 1); lon_minutes = get_from_arrayItem(4, 2, strlen(arrayItem[4])-1); for(i=0;i<=sizeof(msg);i++) { msg[i] = 0; } for(i=0;i<10;i++) { final_time[i] = arrayItem[1][i]; } for(i=0;i<=sizeof(temp_inside);i++) { temp_inside[i] = 0; } for(i=0;i<=sizeof(temp_outside);i++) { temp_outside[i] = 0; } dtostrf((lat+lat_minutes/60), 9, 7, final_lat); final_alt[7] = 0; // clear final_alt[8] = 0; // final_alt's final_alt[9] = 0; // undefined keys strlcat(msg, final_time, sizeof(msg)); strlcat(msg, ",", sizeof(msg)); strlcat(msg, arrayItem[3][0]=='S'?"-":"+", sizeof(msg)); strlcat(msg, final_lat, sizeof(msg)); strlcat(msg, ",", sizeof(msg)); strlcat(msg, arrayItem[5][0]=='W'?"-":"+", sizeof(msg)); dtostrf((lon+lon_minutes/60), 9, 7, final_lon); strlcat(msg, final_lon, sizeof(msg)); strlcat(msg, ",", sizeof(msg)); strlcat(msg, arrayItem[7], sizeof(msg)); strlcat(msg, ",", sizeof(msg)); dtostrf((atof(arrayItem[9])/1000), 6, 3, final_alt); strlcat(msg, final_alt, sizeof(msg)); strlcat(msg, ",", sizeof(msg)); strlcat(msg, arrayItem[11], sizeof(msg)); strlcat(msg, ",", sizeof(msg)); dtostrf(sensor_inside.getTempCByIndex(0), 5, 2, temp_inside); strlcat(msg, temp_inside, sizeof(msg)); strlcat(msg, ",", sizeof(msg)); dtostrf(sensor_outside.getTempCByIndex(0), 5, 2, temp_outside); strlcat(msg, temp_outside, sizeof(msg)); strlcat(msg, ",", sizeof(msg)); Serial.println(msg); } for(i=0;i<71;i++) { nmea[i] = 0; } currentCharIndex = 0; } if(readingLine==1) { nmea[currentCharIndex] = incomingByte; currentCharIndex++; } } }
You need to login to post a comment.
