Hi Guys I need Help for my Project. Having some trouble here.

Status
Not open for further replies.
Hi.
We are working for our Air Quality monitoring using ARDUINO BOARD.
We are using GPS(SkyNav EG25A1), SD CARD and Temperature Sensor.
We still dont have the important gasses but we are having trouble with our GPS and SD CARD.

PROBLEM in GPS:
1) The time we are getting is alternating with the GMT+8 that we put in the code and the UTC.
Because we need the constant GMT+8(PHILIPPINES TIME) not the UTC.
Example:
Time: 12:04:36
Time: 12:04:37
Time: 4:04:38
Time: 12:04:39
Time: 4:04:40
Time: 4:04:41

2) The Date is too long to updated sometimes it doesnt update.

PROBLEM in SD CARD:
1) I think his process in saving is so delayed.

2) And the FILE_WRITE is not exactly like in the SERIAL MONITOR. The data being saved is being duplicated
Example:

[OUTPUT IN SERIAL MONITOR]
Time: 12:04:36
Time: 12:04:37
Time: 4:04:38
Time: 12:04:39
Time: 4:04:40
Time: 4:04:41

[OUTPUT IN SD CARD]
Time: 12:04:36
Time: 12:04:36
Time: 12:04:36
Time: 12:04:36
Time: 12:04:36
Time: 12:04:36
Time: 12:04:37
Time: 12:04:37
Time: 12:04:37
Time: 12:04:37
Time: 12:04:37
Time: 4:04:38
Time: 4:04:38
Time: 4:04:38
Time: 4:04:38
Time: 4:04:38
Time: 4:04:38
Time: 12:04:39

This is the code that we use:
Code:
#include <SD.h>
#include <SPI.h>
#include <TinyGPS++.h>            //GPS library
#include <SoftwareSerial.h>       //GPS
#include <Time.h>                 //GPS

/*Choose two Arduino pins to use for software serial
 The GPS Shield uses D2 and D3 by default when in DLINE mode*/
int chipSelect = 4; //Set chipSelect=4
File AQ_GPSTemp_Data; //variable for working with our file object
 
//initialization for GPS
static const int RXPin = 2; 
static const int TXPin = 3; 

//initialization for TempSensor
int val;                    
int temPin = 1;              
float mv;
float cel;

// The Skytaq EM-506 GPS module included in the GPS Shield Kit
static const uint32_t GPSBaud = 9600;    //Set GPS Baud Rate
const int UTC_offset = 8;                // to correct the GPS UCT time to the Phil. Local Time           
  int Year;
  byte Month;
  byte Day;
  byte Hour;
  byte Minute;
  byte Second;

// Create a TinyGPS++ object called "gps"
TinyGPSPlus gps;

// Create a software serial port called "gpsSerial"
SoftwareSerial gpsSerial(RXPin, TXPin);

//initialization for SD


void setup()
{
  Serial.begin(9600);
  gpsSerial.begin(GPSBaud);     //GPS Serial.begin
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  Serial.print("Initializing SD card...");

  // see if the card is present and can be initialized
  if (!SD.begin(chipSelect)){
    Serial.println("Card failed, or not present");
    //dont do anything
    return;
  }
 
  Serial.println("card initialized."); 

  pinMode(10, OUTPUT); //Reserve pin 10 as an output
  SD.begin(4); //initialize the SD card with chipSelectect connected in pin 4
}

//MAIN LOOP
void loop()
{
  // This sketch displays information every time a new sentence is correctly encoded.
  while (gpsSerial.available() > 0)        //enabling the GPS Module
    if (gps.encode(gpsSerial.read()))
      displayInfo();                       //Provide the corresponding readings from the different sensors
      
    AQ_GPSTemp_Data= SD.open("GPSData.txt", FILE_WRITE);  //Open AirQuality_GPSandTEMP_Data.text on the SD card 
                                                                          //as a file to write the readings
    if (AQ_GPSTemp_Data){  
      AQ_GPSTemp_Data.print(F("Location: "));
      AQ_GPSTemp_Data.print(gps.location.lat(), 6);            //latitude
      AQ_GPSTemp_Data.print(F(",")); 
      AQ_GPSTemp_Data.print(gps.location.lng(), 6);            //longitude
      AQ_GPSTemp_Data.print(F("  Date/Time: "));
      AQ_GPSTemp_Data.print(gps.date.month());                 //month
      AQ_GPSTemp_Data.print(F("/"));
      AQ_GPSTemp_Data.print(gps.date.day());                   //day
      AQ_GPSTemp_Data.print(F("/"));
      AQ_GPSTemp_Data.print(gps.date.year());                  //year
      AQ_GPSTemp_Data.print(F(" "));
      AQ_GPSTemp_Data.print(Hour);                             //hour
      AQ_GPSTemp_Data.print(F(":"));
      AQ_GPSTemp_Data.print(Minute);                           //minute
      AQ_GPSTemp_Data.print(F(":"));
      AQ_GPSTemp_Data.print(Second);                           //second
      AQ_GPSTemp_Data.print(" TEMPERATURE=");
      AQ_GPSTemp_Data.print(cel);                              //temp in degree celsius
      AQ_GPSTemp_Data.println("*C");
      AQ_GPSTemp_Data.close(); //close the file
    }
  /* If 5000 milliseconds pass and there are no characters coming in
 over the software serial port, show a "No GPS detected" error*/
  if (millis() > 5000 && gps.charsProcessed() <10)
  {
    Serial.println(F("No GPS detected"));
    while(true);
  }
}

void displayInfo()    //Display Readings from sensors
{
  GPSLocation();      //GPS latitude and Longitude
  GPSDate();          //GPS Date in MM/DD/YY format
  GPSTime();          //GPS Phil. time in HH:MM:SS format
  TempSensor();       //Read Temperature Sensor
  Serial.println();
  delay(500);
}

//Functions in the [displayInfo()].
void GPSLocation()                          //Location of the GPS
{
   Serial.print(F("Location: "));
  if (gps.location.isValid())              //checks if there is any valid information for the location 
  {
    Serial.print(gps.location.lat(), 6);    // Latitude
    Serial.print(F(","));
    Serial.print(gps.location.lng(), 6);    // Longitude
  }
  else
  {
    Serial.print(F("INVALID"));             // no valid info
  }
}

void GPSDate()                             //Current Date
{
  Serial.print(F("  Date/Time: "));
  if (gps.date.isValid())                  //checks if there is any valid information for the date
  {
    Serial.print(gps.date.month());        //month
    Serial.print(F("/"));
    Serial.print(gps.date.day());          //day
    Serial.print(F("/"));
    Serial.print(gps.date.year());         //year
  }
  else
  {
    Serial.print(F("INVALID"));            //no valid info
  }
}

void GPSTime()                             //Current Time
{
  Serial.print(F(" "));
  if (gps.time.isValid()&& gps.date.isValid())                  //checks if there is any valid information for the time
  {
    Year = gps.date.year();
    Month = gps.date.month();
    Day = gps.date.day();
    Hour = gps.time.hour();
    Minute = gps.time.minute();
    Second = gps.time.second();
    
    setTime(Hour,Minute,Second,Day,Month,Year);      // Set Time from GPS data string
    adjustTime(UTC_offset * SECS_PER_HOUR);         //Calculate current Time Zone time by offset value
   
    
    Year = year();
    Month = month();
    Day = day();
    Hour = hour();
    Minute = minute();
    Second = second();
    
    if (Hour < 10) Serial.print(F("0"));
    Serial.print(Hour);                            //hour
    Serial.print(F(":"));
    if (Minute < 10) Serial.print(F("0"));
    Serial.print(Minute);                          //minute
    Serial.print(F(":"));
    if (Second < 10) Serial.print(F("0"));
    Serial.print(Second);                          //second 
  }
  else
  {
    Serial.print(F("INVALID"));                    //no valid info
  }
}

void TempSensor()                                  //ambient temperature
{   
    val = analogRead(temPin);
    mv = (val/1024.0)*5000;
    cel = mv/10;
    Serial.print(F(" TEMPERATURE = "));            
    Serial.print(cel);                             //temperature value in degree Celcius                         
    Serial.print(F("*C"));
}

Please help me, thank you in advance.
I think that my library is not that updated or I don't know maybe the problem is still in the code.
Maybe not proper grouping of codes, the process that I want is not doing it.
 
Last edited:
Your code needs some brackets....
The delay in displayInfo(); should better placed in loop().


Code:
//MAIN LOOP
void loop()
{
  // This sketch displays information every time a new sentence is correctly encoded.
  while (gpsSerial.available() > 0)        //enabling the GPS Module
    if (gps.encode(gpsSerial.read()))
     {  //<<<<<<<<<<<<<<<<<<<<<<<<<<<
      displayInfo();                       //Provide the corresponding readings from the different sensors
      delay(500);
        ...
        ...
      AQ_GPSTemp_Data.close(); //close the file
    }
   }    //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  /* If 5000 milliseconds pass and there are no characters coming in
 over the software serial port, show a "No GPS detected" error*/
  if (millis() > 5000 && gps.charsProcessed() <10)
  {
    Serial.println(F("No GPS detected"));
    while(true);
  }
}
 
Your code needs some brackets....
The delay in displayInfo(); should better placed in loop().


Code:
//MAIN LOOP
void loop()
{
  // This sketch displays information every time a new sentence is correctly encoded.
  while (gpsSerial.available() > 0)        //enabling the GPS Module
    if (gps.encode(gpsSerial.read()))
     {  //<<<<<<<<<<<<<<<<<<<<<<<<<<<
      displayInfo();                       //Provide the corresponding readings from the different sensors
      delay(500);
        ...
        ...
      AQ_GPSTemp_Data.close(); //close the file
    }
   }    //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  /* If 5000 milliseconds pass and there are no characters coming in
 over the software serial port, show a "No GPS detected" error*/
  if (millis() > 5000 && gps.charsProcessed() <10)
  {
    Serial.println(F("No GPS detected"));
    while(true);
  }
}

Hi sir, good evening.
That will solve what problem?
I don't have my gadget now cause I'm in a bus going home. hihi
Happy New Year!
 
The code writes every loop current data to SD.
displayInfo() starts only when new data arrived. With Brackets SD and displayInfo() are in the same block.
 
Status
Not open for further replies.
Back
Top