As advised, I have checked the wiring and tried the setup outside in the open. I have also stripped the programme of redundant code, or code that prettified the serial output. This helped me see relationships within the programme more clearly than before; however, I can't seem to get a GPS on the serial monitor [invalid,invalid,invalid,invalid] or the SD card [invalid,invalid,invalid,invalid].
Information on my hardware and pinning are set out below:
Hardware.
Arduina Mega 2560
5v ready Micro-SD \breakout Board
HAB Supplies UBlox 7 with Santana Ariel (gets signal on other programmes)
Pin arrangement
SD = CS-53; DI-51; DO-50; CLK-52; 5v-5v; GND-GND (this unit works)
GPS = TX-RX(serial1(pin19)); RX-TX(serial1(pin18)); GND-GND; 5v-5v; EN-5v.
My reduced programme follows - any help would be appreciated (I hope my use of the code button for the text below meets the Forum requirements ).
//TinyGPS Library and Helper Functions by Mikal Hart http://arduiniana.org/libraries/tinygps/
#include <TinyGPS.h>
#include <SD.h>
#include <stdlib.h>
#include <SPI.h>
/* Code demonstrates the normal use of a TinyGPS object.
It uses an Arduino Mega with a GPS attached to Serial1 at 4800 buad.
*/
TinyGPS gps;
static char dtostrfbuffer[20];
int CS = 53;
int LED = 13;
//Define String
String SD_date_time = "invalid";
String SD_lat = "invalid";
String SD_lon = "invalid";
String SD_alt = "invalid";
String dataString = ""; ////////////////////////////datastring
static void gpsdump(TinyGPS &gps);
static bool feedgps();
static void print_float(float val, float invalid, int len, int prec, int SD_val);/////////////////Float
static void print_int(unsigned long val, unsigned long invalid, int len);
static void print_date(TinyGPS &gps);
static void print_str(const char *str, int len);
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
void setup()
{
pinMode(CS, OUTPUT); //Chip Select for the SD Card
pinMode(LED, OUTPUT); //LED Indicator
//Serial interfaces
Serial1.begin(4800);
Serial.begin(115200);
//Connect to the SD Card
if (!SD.begin(CS))
{
Serial.println("Card Failure");
return;
}
}
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
void loop() {
bool newdata = false;
unsigned long start = millis();
// Every second print an update
while (millis() - start < 2000);
{
if (feedgps())
newdata = true;
}
//------------------------------------------------------------------------------------------------------
gpsdump(gps);
//Write the newest information to the SD Card
dataString = SD_date_time + "," + SD_lat + "," + SD_lon + "," + SD_alt;
if (SD_date_time != "invalid")
digitalWrite(LED, HIGH);
else
//-------------------------------------------------------------------------------------------------
digitalWrite(LED, LOW);
delay(5);
//Open the Data CSV File
File dataFile = SD.open("LOG.csv", FILE_WRITE);
if (dataFile)
{
dataFile.println(dataString);
Serial.println(dataString);
dataFile.close();
delay(10);
}
else
{
Serial1.println("\nCouldn't open the log file!");
}
}
//--------------------------------------------------------------------------------------------------
static void gpsdump(TinyGPS &gps)
{
float flat, flon;
unsigned long age, date, time, chars = 0;
unsigned short sentences = 0, failed = 0;
static const float LONDON_LAT = 51.508131, LONDON_LON = -0.128002;
print_int(gps.satellites(), TinyGPS::GPS_INVALID_SATELLITES, 5);
print_int(gps.hdop(), TinyGPS::GPS_INVALID_HDOP, 5);
gps.f_get_position(&flat, &flon, &age);
print_float(flat, TinyGPS::GPS_INVALID_F_ANGLE, 9, 5, 1); //LATITUDE
print_float(flon, TinyGPS::GPS_INVALID_F_ANGLE, 10, 5, 2); //LONGITUDE
print_int(age, TinyGPS::GPS_INVALID_AGE, 5);
print_date(gps); //DATE AND TIME
print_float(gps.f_altitude(), TinyGPS::GPS_INVALID_F_ALTITUDE, 8, 2, 3);//ALTITUDE
// print_float(gps.f_course(), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2, 0);
// print_float(gps.f_speed_kmph(), TinyGPS::GPS_INVALID_F_SPEED, 6, 2, 0);
// print_str(gps.f_course() == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(gps.f_course()), 6);
// print_int(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0UL : (unsigned long)TinyGPS::distance_between(flat, flon, LONDON_LAT, LONDON_LON) / 1000, 0xFFFFFFFF, 9);
// print_float(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : TinyGPS::course_to(flat, flon, 51.508131, -0.128002), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2, 0);
// print_str(flat == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(TinyGPS::course_to(flat, flon, LONDON_LAT, LONDON_LON)), 6);
// gps.stats(&chars, &sentences, &failed);
// print_int(chars, 0xFFFFFFFF, 6);
// print_int(sentences, 0xFFFFFFFF, 10);
// print_int(failed, 0xFFFFFFFF, 9);
Serial1.println();
delay(10);
}
//------------------------------------------------------------------------------------------------------
static void print_int(unsigned long val, unsigned long invalid, int len)
{
char sz[32];
Serial1.print(sz);//serial1 removes gbldgok
feedgps();
}
//------------------------------------------------------------------------------------------------------
static void print_float(float val, float invalid, int len, int prec, int SD_val)
{
char sz[32];
if (val == invalid)
{
strcpy(sz, "*******");
sz[len] = 0;
}
else
{
Serial1.print(val, prec);
delay(10);
}
feedgps();
}
//------------------------------------------------------------------------------------------------------
static void print_date(TinyGPS &gps)
{
}
static void print_str(const char *str, int len)
{
}
//------------------------------------------------------------------------------------------------------
static bool feedgps()
{
while (Serial1.available())
{
if (gps.encode(Serial1.read()))
return true;
}
return false;
}
Regards,
Colin.