Posted By

jatkins on 11/16/09


Tagged

decimal longitude temperature GPS latitude coordinates Degrees arduino nmea Sensor Sensors Geography thermometer onewire one-wire 1-wire 1wire


Versions (?)

ARDUINO: Telemetry parser


 / 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
  1. #include <OneWire.h>
  2. #include <DallasTemperature.h>
  3. #include <string.h>
  4. OneWire therm1(8);
  5. OneWire therm2(10);
  6. DallasTemperature sensor_inside(&therm1);
  7. DallasTemperature sensor_outside(&therm2);
  8. 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];
  9. int currentCharIndex = 0, readingLine = 0, i, n_or_s, e_or_w, count = 0, z, indexAfterDelimiter;
  10. double lat, lon, lat_minutes, lon_minutes;
  11.  
  12. void setup() {
  13. // START: temperature sensor initialization code
  14. sensor_inside.begin();
  15. sensor_outside.begin();
  16. // END: temperature sensor initialization code
  17. // Output format: Time(UTC),Latitude(Decimal Degs),Longitude,# of Satellites in view,Altitude(km),Other Alt,Temperature inside (C), Temperature outside (C)
  18. Serial.begin(4800);
  19. }
  20.  
  21. void split() {
  22. itemCount = 0;
  23. for(i=0;i<strlen(nmea);i++) {
  24. if(nmea[i]!=',') {
  25. arrayItem[itemCount][indexAfterDelimiter] = nmea[i];
  26. indexAfterDelimiter++;
  27. }
  28. else {
  29. indexAfterDelimiter = 0;
  30. itemCount++;
  31. }
  32. }
  33. }
  34.  
  35. double get_from_arrayItem(int item_index, int start_index, int end_index) {
  36. char retrieved[end_index-start_index];
  37. for(int i=0;i<=end_index-start_index;i++) {
  38. retrieved[i] = arrayItem[item_index][start_index+i];
  39. }
  40. return atof(retrieved);
  41. }
  42.  
  43. void loop() {
  44. if(Serial.available()) {
  45. incomingByte = Serial.read();
  46. if(incomingByte=='$') { // start of line
  47. readingLine = 1;
  48. }
  49. else if(incomingByte=='*') { // end of useful data
  50. readingLine = 0;
  51. if(nmea[3]=='G'&&nmea[4]=='G'&&nmea[5]=='A') { // check if line starts with $GPGGA
  52. sensor_inside.requestTemperatures();
  53. sensor_outside.requestTemperatures();
  54. split();
  55. lat = get_from_arrayItem(2, 0, 1);
  56. lat_minutes = get_from_arrayItem(2, 2, strlen(arrayItem[2])-1);
  57. lon = get_from_arrayItem(4, 0, 1);
  58. lon_minutes = get_from_arrayItem(4, 2, strlen(arrayItem[4])-1);
  59. for(i=0;i<=sizeof(msg);i++) {
  60. msg[i] = 0;
  61. }
  62. for(i=0;i<10;i++) {
  63. final_time[i] = arrayItem[1][i];
  64. }
  65. for(i=0;i<=sizeof(temp_inside);i++) {
  66. temp_inside[i] = 0;
  67. }
  68. for(i=0;i<=sizeof(temp_outside);i++) {
  69. temp_outside[i] = 0;
  70. }
  71. dtostrf((lat+lat_minutes/60), 9, 7, final_lat);
  72. final_alt[7] = 0; // clear
  73. final_alt[8] = 0; // final_alt's
  74. final_alt[9] = 0; // undefined keys
  75. strlcat(msg, final_time, sizeof(msg));
  76. strlcat(msg, ",", sizeof(msg));
  77. strlcat(msg, arrayItem[3][0]=='S'?"-":"+", sizeof(msg));
  78. strlcat(msg, final_lat, sizeof(msg));
  79. strlcat(msg, ",", sizeof(msg));
  80. strlcat(msg, arrayItem[5][0]=='W'?"-":"+", sizeof(msg));
  81. dtostrf((lon+lon_minutes/60), 9, 7, final_lon);
  82. strlcat(msg, final_lon, sizeof(msg));
  83. strlcat(msg, ",", sizeof(msg));
  84. strlcat(msg, arrayItem[7], sizeof(msg));
  85. strlcat(msg, ",", sizeof(msg));
  86. dtostrf((atof(arrayItem[9])/1000), 6, 3, final_alt);
  87. strlcat(msg, final_alt, sizeof(msg));
  88. strlcat(msg, ",", sizeof(msg));
  89. strlcat(msg, arrayItem[11], sizeof(msg));
  90. strlcat(msg, ",", sizeof(msg));
  91. dtostrf(sensor_inside.getTempCByIndex(0), 5, 2, temp_inside);
  92. strlcat(msg, temp_inside, sizeof(msg));
  93. strlcat(msg, ",", sizeof(msg));
  94. dtostrf(sensor_outside.getTempCByIndex(0), 5, 2, temp_outside);
  95. strlcat(msg, temp_outside, sizeof(msg));
  96. strlcat(msg, ",", sizeof(msg));
  97. Serial.println(msg);
  98. }
  99. for(i=0;i<71;i++) {
  100. nmea[i] = 0;
  101. }
  102. currentCharIndex = 0;
  103. }
  104. if(readingLine==1) {
  105. nmea[currentCharIndex] = incomingByte;
  106. currentCharIndex++;
  107. }
  108. }
  109. }

Report this snippet  

You need to login to post a comment.