I am using an arduino mega as my microcontroller, hence the SD card needing to be set to pin 53. This code will run perfectly fine with the included libraries. It correctly displays the gps coordinates, speed in mph, and the temp in F and C. The last part of the project is to try and write the serial monitor data to the SD card. The module being used is Micro SD Card Micro SDHC Mini TF Card Adapter Reader SPI interface driver Module. I have tried basing my code off of the basic SD card info code on the arduino ide, but to no avail. I apologize if i am overlooking this, coding is just not my thing. I also have tried looking the answer up on google, as well as searching other forums.
#include <SD.h> //this is a preinstalled library, but you still need to call it
#include <SPI.h> //this is a preinstalled library, but you still need to call it
#include <TinyGPS.h> //this library must be downloaded and the file must be placed in the arduino libraries folder in order to properly use it
#include <OneWire.h> //this library must be downloaded and the file must be placed in the arduino libraries folder in order to properly use it
#include <DallasTemperature.h> //this library must be downloaded and the file must be placed in the arduino libraries folder in order to properly use it
//long lat,lon; // create variable for latitude and longitude object
float lat,lon; //allows for multiple digits after the decimal place for more accuracy
TinyGPS gps; // create gps object
#define ONE_WIRE_BUS 2 // Data wire is plugged into digital pin 2 on the Arduino
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire device
DallasTemperature sensors(&oneWire); // Pass oneWire reference to DallasTemperature library
void setup(){
pinMode(53, OUTPUT);//set our chip select to pin 53
Serial.begin(9600); // connect serial
Serial1.begin(9600); // connect gps sensor, gps is plugged into pins 18 and 19 so serial1
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire device
DallasTemperature sensors(&oneWire); // Pass oneWire reference to DallasTemperature library
Serial.print("Latitude"); Serial.print("\t"); Serial.print("Longitude"); Serial.print("\t"); Serial.print("Speed mph"); Serial.print("\t"); Serial.print("Temp C"); Serial.print("\t"); Serial.println("Temp F"); //creating a header for the info we are displaying
}
void loop(){{
while(Serial1.available()){ // check for gps data
if(gps.encode(Serial1.read()))// encode gps data
{
gps.f_get_position(&lat,&lon); // get latitude and longitude
//Latitude
Serial.print(lat,6); //prints the latitude with 6 digits after the decimal this provides accuracy to 43.496 mm
Serial.print("\t");
//Longitude
Serial.print(lon,6); //prints the longitude with 6 digits after the decimal this provides accuracy to 43.496 mm
Serial.print("\t");
//speed
float fmph = gps.f_speed_mph();
Serial.print(fmph);//prints speed in mph, floated to two decimnal points
Serial.print("\t");
Serial.print("\t");
//altitude //commented out becuase not giving proper readings
//float Alt = gps.f_altitude();
//Serial.print(Alt);
//Serial.print("\t");
//Temp
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.print(sensors.getTempCByIndex(0)); //print the temperature in Celsius
Serial.print("\t");
Serial.println((sensors.getTempCByIndex(0) * 9.0) / 5.0 + 32.0);//celcius to fahrenheit conversion
delay(5000);
}
}
}
}