Hi,
I am at a totall los... The code below works fine when connected to the pc/IDE but when I power it with a USB cable outside (because of the GPS) it doesnt.
I have LED on pin7 that indicates whether the file has been created or not.
Inside it turns on, outside, no way.
I also tried powering the SD and GPS with an additional powersource. No luck
What can it be? It is a Nano
//#include <TinyGPS.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <SD.h> //load SD lib
#include <SPI.h> // load SPI comm
#include <Wire.h> // load Wire
int chipSelect=5; //Set ChipSelect
File myGpsData; //Variable for File
/*
This sample sketch demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object.
It requires the use of SoftwareSerial, and assumes that you have a
4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
*/
//static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;
// The TinyGPS++ object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(3, 4);
void setup()
{
//Serial.begin(115200);
ss.begin(GPSBaud);
SD.begin(chipSelect); //initialize SD Card
delay(1000);
pinMode(10, OUTPUT);
pinMode(7, OUTPUT);
//Serial.println(F("DeviceExample.ino"));
//Serial.println(F("A simple demonstration of TinyGPS++ with an attached GPS module"));
// Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
//Serial.println(F("by Mikal Hart"));
//Serial.println();
}
void loop()
{
// This sketch displays information every time a new sentence is correctly encoded.
while (ss.available() > 0)
if (gps.encode(ss.read()))
displayInfo();
if (millis() > 5000 && gps.charsProcessed() < 10)
{
myGpsData.println(F("No GPS detected: check wiring."));
while(true);
}
//}//file open
}//loop
void displayInfo()
{
myGpsData= SD.open("Gps.txt", FILE_WRITE);
if (myGpsData){digitalWrite(7,HIGH);}
myGpsData.print(F("Location: "));
if (gps.location.isValid())
{
myGpsData.print(gps.location.lat(), 6);
myGpsData.print(F(","));
myGpsData.print(gps.location.lng(), 6);
}
else
{
myGpsData.print(F("INVALID"));
}
myGpsData.print(F(" Date/Time: "));
if (gps.date.isValid())
{
myGpsData.print(gps.date.month());
myGpsData.print(F("/"));
myGpsData.print(gps.date.day());
myGpsData.print(F("/"));
myGpsData.print(gps.date.year());
}
else
{
myGpsData.print(F("INVALID"));
}
myGpsData.print(F(" "));
if (gps.time.isValid())
{
if (gps.time.hour() < 10) Serial.print(F("0"));
myGpsData.print(gps.time.hour());
myGpsData.print(F(":"));
if (gps.time.minute() < 10) Serial.print(F("0"));
myGpsData.print(gps.time.minute());
myGpsData.print(F(":"));
if (gps.time.second() < 10) Serial.print(F("0"));
myGpsData.print(gps.time.second());
myGpsData.print(F("."));
if (gps.time.centisecond() < 10) Serial.print(F("0"));
myGpsData.print(gps.time.centisecond());
}
else
{
myGpsData.print(F("INVALID"));
}
myGpsData.println();
myGpsData.close();//close the file}
}