Adafruit GPS logger shield plus additional sensors

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
JaBo
 
Posts: 14
Joined: Wed Jul 02, 2014 12:59 am

Adafruit GPS logger shield plus additional sensors

Post by JaBo »

Dear all,

I want to use an Arduino Uno, an Adafruit Ultimate GPS Shield and 3 Melexis MLX90614 IR sensors to log and geotag the sensors temperature data.
Using the AdafruitMLX library I managed to log the temperature data (ambient and object) of the MLX sensors (http://forums.adafruit.com/viewtopic.ph ... 89#p293089). Following a tutorial from Paul McWorther (http://www.toptechboy.com/arduino/lesso ... ta-logger/) I was able to log GPS time and position data to the SD card of the GPS shield.
Trying to combine the two codes I got stuck.
My code is compiling, but no data are written on the SD card or printed to the serial monitor.
As soon as I outcomment the MLX code from the GPS code the files are created and the GPS data are wriitten to the SD card.

My code (MLX code is marked with /******/):
[img]

Code: Select all

/***** new code ************/
#include <Wire.h>
#include <Adafruit_MLX90614.h>
/*******************************/

#include <SD.h> //Load SD card library
#include<SPI.h> //Load SPI Library

#include <Adafruit_GPS.h>    //Install the adafruit GPS library
#include <SoftwareSerial.h> //Load the Software Serial library
SoftwareSerial mySerial(8,7); //Initialize the Software Serial port
Adafruit_GPS GPS(&mySerial); //Create the GPS Object

String NMEA1; //Variable for first NMEA sentence
String NMEA2; //Variable for second NMEA sentence
char c; //to read characters coming from the GPS
float deg; //Will hold positin data in simple degree format
float degWhole; //Variable for the whole part of position 
float degDec;  //Variable for the decimal part of degree

int chipSelect = 10; //chipSelect pin for the SD card Reader
File mySensorData; //Data object you will write your sesnor data to

/******************* Melexis Objects ***************************************/
Adafruit_MLX90614 mlx_1 = Adafruit_MLX90614(0x5A); // default address is 0x5A
Adafruit_MLX90614 mlx_2 = Adafruit_MLX90614(0x5B);
Adafruit_MLX90614 mlx_3 = Adafruit_MLX90614(0x5C);
/***************************************************************************/

void setup() {
  
  Wire.begin(); 
  mlx_1.begin();
  mlx_2.begin();
  mlx_3.begin();
  
  Serial.begin(115200); //Turn on serial monitor
  GPS.begin(9600); //Turn on GPS at 9600 baud
  GPS.sendCommand("$PGCMD,33,0*6D");  //Turn off antenna update nuisance data
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); //Request RMC and GGA Sentences only
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_5HZ); //Set update rate to 1 hz
  delay(10); 
  
  pinMode(10, OUTPUT); //Must declare 10 an output and reserve it to keep SD card happy
  SD.begin(chipSelect); //Initialize the SD card reader
  
  if (SD.exists("NMEA.txt")) { //Delete old data files to start fresh
    SD.remove("NMEA.txt");
  }
  if (SD.exists("GPSData.txt")) { //Delete old data files to start fresh
    SD.remove("GPSData.txt");
  }

}

void loop() {
  
  readGPS();

  if(GPS.fix==0) { //Only save data if we have a fix
  mySensorData = SD.open("NMEA.txt", FILE_WRITE); //Open file on SD card for writing
  mySensorData.println(NMEA1); //Write first NMEA to SD card
  mySensorData.println(NMEA2); //Write Second NMEA to SD card
  mySensorData.close();  //Close the file
  
 
  mySensorData = SD.open("GPSData.txt", FILE_WRITE);
  
  degWhole=float(int(GPS.longitude/100)); //gives me the whole degree part of Longitude
  degDec = (GPS.longitude - degWhole*100)/60; //give me fractional part of longitude
  deg = degWhole + degDec; //Gives complete correct decimal form of Longitude degrees
  if (GPS.lon=='W') {  //If you are in Western Hemisphere, longitude degrees should be negative
    deg= (-1)*deg;
  }
  mySensorData.print(deg,4); //writing decimal degree longitude value to SD card
  mySensorData.print(","); //write comma to SD card
  
  degWhole=float(int(GPS.latitude/100)); //gives me the whole degree part of latitude
  degDec = (GPS.latitude - degWhole*100)/60; //give me fractional part of latitude
  deg = degWhole + degDec; //Gives complete correct decimal form of latitude degrees
  if (GPS.lat=='S') {  //If you are in Southern hemisphere latitude should be negative
    deg= (-1)*deg;
  }
  mySensorData.print(deg,4); //writing decimal degree longitude value to SD card
  mySensorData.print(","); //write comma to SD card
  mySensorData.print(GPS.altitude); //write altitude to file
  mySensorData.print(","); //write comma to SD card
  mySensorData.print(GPS.day);
  mySensorData.print("/");
  mySensorData.print(GPS.month);
  mySensorData.print("/");
  mySensorData.print(GPS.year);
  mySensorData.print(" ");
  mySensorData.print(GPS.hour);
  mySensorData.print(":");
  mySensorData.print(GPS.minute);
  mySensorData.print(":");
  mySensorData.print(GPS.seconds);
  mySensorData.print(",");
  mySensorData.print(GPS.speed,2);
  mySensorData.print(",");
  mySensorData.println(GPS.satellites);
  /*****************new print************************/
  mySensorData.print(mlx_1.readAmbientTempC());
  mySensorData.print(" , ");
  mySensorData.print(mlx_1.readObjectTempC());
  mySensorData.print(" , ");
  mySensorData.print(mlx_2.readAmbientTempC());
  mySensorData.print(" , ");
  mySensorData.print(mlx_2.readObjectTempC());
  mySensorData.print(" , ");
  mySensorData.print(mlx_3.readAmbientTempC());
  mySensorData.print(" , ");
  mySensorData.print(mlx_3.readObjectTempC());
 /***************************************************/  
 mySensorData.close();
  }
  
}

void readGPS() {
  
  clearGPS();
  while(!GPS.newNMEAreceived()) { //Loop until you have a good NMEA sentence
    c=GPS.read();
  }
  GPS.parse(GPS.lastNMEA()); //Parse that last good NMEA sentence
  NMEA1=GPS.lastNMEA();
  
   while(!GPS.newNMEAreceived()) { //Loop until you have a good NMEA sentence
    c=GPS.read();
  }
  GPS.parse(GPS.lastNMEA()); //Parse that last good NMEA sentence
  NMEA2=GPS.lastNMEA();
  
  Serial.println(NMEA1);
  Serial.println(NMEA2);
  Serial.println("");
  
}

void clearGPS() {  //Clear old and corrupt data from serial port 
  while(!GPS.newNMEAreceived()) { //Loop until you have a good NMEA sentence
    c=GPS.read();
  }
  GPS.parse(GPS.lastNMEA()); //Parse that last good NMEA sentence
  
  while(!GPS.newNMEAreceived()) { //Loop until you have a good NMEA sentence
    c=GPS.read();
  }
  GPS.parse(GPS.lastNMEA()); //Parse that last good NMEA sentence
   while(!GPS.newNMEAreceived()) { //Loop until you have a good NMEA sentence
    c=GPS.read();
  }
  GPS.parse(GPS.lastNMEA()); //Parse that last good NMEA sentence
  
}
[/img]

Could you please give me a hint what the problem might be?

Thanks
JaBo

User avatar
Franklin97355
 
Posts: 23912
Joined: Mon Apr 21, 2008 2:33 pm

Re: Adafruit GPS logger shield plus additional sensors

Post by Franklin97355 »

If you comment out the GPS code do you get the MLX written to the card?

User avatar
JaBo
 
Posts: 14
Joined: Wed Jul 02, 2014 12:59 am

Re: Adafruit GPS logger shield plus additional sensors

Post by JaBo »

Thanks for the swift reply!
Yes, all MLX data are written to the SD quite fast (500 lines in a few seconds).

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”