GPS and sensor data logger only works when connected to serial connection

Below and attached are the code, libraries, and image I am using on the project.
It is suppose to be a simple datalogger to an SD card.
The data logger works, but only when connected via usb serial connection. and not when it is connected to and external power source.

I am using an Arduino UNO, PMB-648 SIRF III GPS(pin6), BMP085(analog 4 and 5), and an SD card shield(see attached image), in addition there are other sensors.

Any help would be greatly appreciated. Also, I am new to programming so the code might be inefficient and crappy.
Thanks,
Joey

logger_new.ino (7.3 KB)

Adafruit_BMP085.h (2.52 KB)

Adafruit_BMP085.cpp (7.63 KB)

jmagnus:
The data logger works, but only when connected via usb serial connection. and not when it is connected to and external power source.

What are the symptoms of it 'not working' and how do these differ from when it is working correctly?

PeterH:

jmagnus:
The data logger works, but only when connected via usb serial connection. and not when it is connected to and external power source.

What are the symptoms of it 'not working' and how do these differ from when it is working correctly?

When it is working correctly it logs all of the data collected from the sensors to a .csv file on the sd card.

When I take it off serial monitor(pc connection) and power it externally it does not save any data to the sd card.(there is no data when I open the .csv file)

I have had a similar problem before as well.

what is the voltage and current you measure coming from your power supply?

btricha2:
I have had a similar problem before as well.

what is the voltage and current you measure coming from your power supply?

Thanks for the suggestion.

I havn't measured it. I will do that tonight. I have tried 6 lithium AA's and 8 Lithium AA's (both energizer brand) connected to the 2.5mm connector. I'm not sure what the mAh for those but they are 1.5v each. I think the current might be the issue. The unit powers on and seems to be working. Sometimes the GPS won't get a satalite fix though. I have heard that can be caused by a power issue.

Also, I am not sure how good my code is, I want to fix this section of code but I don't know how

First, you define what is wrong with it.
Then, you define what you want to do, instead.
Finally, you follow Captain Jean Luc Picard's direction, and "Make it so!".

jmagnus:
When I take it off serial monitor(pc connection) and power it externally it does not save any data to the sd card.(there is no data when I open the .csv file)

Is that output on the SD card the only evidence that it's working? If so, I suggest you think about adding some diagnostics. Flash an LED a couple of times in setup or do something else recognisable so that you can see whether the Arduino is being reset. Make sure that your code checks for and handles all the error conditions that could occur initialising the SD card and writing to it, and find a way to make it apparent when something fails (e.g. turn an LED on solid, blink an error code, change the state of a spare output pin - do something tangible you can look for to see whether the sketch has detected any errors and if so you can then go see what type of error has occurred.

PeterH:

jmagnus:
When I take it off serial monitor(pc connection) and power it externally it does not save any data to the sd card.(there is no data when I open the .csv file)

Is that output on the SD card the only evidence that it's working? If so, I suggest you think about adding some diagnostics. Flash an LED a couple of times in setup or do something else recognisable so that you can see whether the Arduino is being reset. Make sure that your code checks for and handles all the error conditions that could occur initialising the SD card and writing to it, and find a way to make it apparent when something fails (e.g. turn an LED on solid, blink an error code, change the state of a spare output pin - do something tangible you can look for to see whether the sketch has detected any errors and if so you can then go see what type of error has occurred.

Yes, if there is no data on the SD card then that is the only way I know it failed. I have no clue how far it gets in the sketch.
The LED error code sounds like a good idea. Problem is I am a complete noob and I dont know how to do that or to check for other errors.

Problem is I am a complete noob and I dont know how to do that or to check for other errors.

There is an on-board LED, usually on pin 13. Set the pin HIGH at places in the code, and LOW at other places. Or, create a function to blink the LED a number of times. Call that function with different numbers of times to blink at different points in the code - say 3 in setup() and 5 when you open the file, and 4 when the end of the GPS sentence arrives.

Soon, you'll know where you are getting to, and where you are not getting to.

jmagnus:
Yes, if there is no data on the SD card then that is the only way I know it failed. I have no clue how far it gets in the sketch.
The LED error code sounds like a good idea. Problem is I am a complete noob and I dont know how to do that or to check for other errors.

Do you have an LED on your Arduino? Or any unused output pins that you could use to connect an external LED? The 'blink' example is pretty much the first step in any Arduino learning curve and I find it hard to believe you're intending to debug an SD data logger if you don't know how to turn on an LED.

How does it look?

Awful.

  digitalWrite(led, LOW);                              
  delay(300);
  digitalWrite(led, HIGH);
  delay(300);
  digitalWrite(led, LOW);
  delay(300);
  digitalWrite(led, HIGH);
  delay(300);
  digitalWrite(led, LOW);
  delay(300);
  digitalWrite(led, HIGH);
  delay(300);
  digitalWrite(led, LOW);
  delay(300);
  digitalWrite(led, HIGH);

Haven't you heard of for loops?

Random indenting sucks. Tools + Auto Format will fix that in no time flat.

  gps.f_get_position(&flat, &flon, &age);           //Assign value to flat, flon, and age by calling TinyGPS function
  gps.get_datetime(&date, &time);                   //Assign value to date and time by calling TinyGPS function
  speedmps = gps.f_speed_mps();                     //Assign value to speedmps by calling TinyGPS function
  satellites = gps.satellites();                    //Assign value to satellites by calling TinyGPS function
  altitude = gps.f_altitude();                      //Assign value to altitude by calling TinyGPS function
  course = gps.course();                            //Assign value to course by calling TinyGPS function

Do these comments REALLY add any value? Anyone who has ever written a line of code will recognize what the code is doing. The signal to noise ratio is far to low.

Thank you for the advice above. I took out a bunch of comments. I will clean up the code and add loops and other led indicators once I have the code working.

Speaking of working. I found out I had fried my arduino uno. I didnt realize I needed a voltage regulator if I wanted to power it via the usb port.

I tested the device with a new arduino board and it saves the data to the SD card when on external power, but I still dont get readings from the GPS module. All other sensors work.

jmagnus:
Speaking of working. I found out I had fried my arduino uno. I didnt realize I needed a voltage regulator if I wanted to power it via the usb port.

Do you mean you were supplying more than 5V through the USB port? Yes, that wouldn't do it any good.

PeterH:

jmagnus:
Speaking of working. I found out I had fried my arduino uno. I didnt realize I needed a voltage regulator if I wanted to power it via the usb port.

Do you mean you were supplying more than 5V through the USB port? Yes, that wouldn't do it any good.

That is exactly what I was doing. I figured the Arduino had a built in regulator for usb power(that would be redundant)... ID10T error!

In other news I got the device to work using the following code.

Thanks for everyones input and help!

/* 
 This Sketch uses the TinyGPS library and SD card library to log GPS data and save it on a SD card.
 
 Important: This version is intended for Arduino 1.0.1 IDE. It will
 not compile in earlier versions. Be sure the following files are
 present in the libraries folder:
 
 TinyGPS.h
 Adafruit_BMP085.h

 Written By: Joseph Magnus
 Date: 10/18/2012
 */

#include <SoftwareSerial.h>                          //Standard Software Serial Library
#include <TinyGPS.h>                                 // Version for 1.0.1
#include <SD.h>                                      // Standard Arduino SD card Library
#include <Wire.h>
#include <Adafruit_BMP085.h>

File myFile;                                         
Adafruit_BMP085 bmp;                                 
TinyGPS gps;                                         
SoftwareSerial nss(6, 255);                          //Yellow wire to pin 6. (Based on using Parallax 28500-RT PMB-648 GPS SiRF III Internal Antenna)
int led = 13;                                        //Pin 13 is declared as led

//declare variables for GPS
float flat, flon;                                 
unsigned long age, time, date, speed, course, satellites, altitude, speedmps;      
//end variable declaration for GPS

//Declare variable declaration for Humidity Sensor
int humPin = 0; //// Humidity sensor on Analog pin 0
//end variable declaration for Humidity Sensor


//declare variables for temp sensor
int tempPin = 2; // TMP-36 on Analog pin 2
int tempReading = 0;
float temperatureC = 0;
float temperatureF = 0;
const int interval = 10*100; // the interval between sensor reads, in ms
long lastReadTime = 0;        // the last time you read the sensor, in ms
//end variable declaration for temp sensor

//Setup                                     
void setup() {

  Serial.begin(9600);
  nss.begin(4800);
  bmp.begin();
  pinMode(led, OUTPUT);                              

  digitalWrite(led, HIGH);                           

  Serial.println("Flight_DATA_LOGGER");
  Serial.println("WRITTEN BY: Joseph Magnus");
  delay(1000);
  Serial.println("....................");
  delay(1000);
  Serial.println("***");

  //Initialize Barometer
  Serial.println("Initializing Barometer...");
  delay(1000);

  Serial.println("Initialization Completed Successfully!");
  // End initialize Barometer

  // Initialize SD card
  Serial.println("Initializing SD card...");
  delay(2000);
  pinMode(10, OUTPUT);                               //Set SD Card Pin to digital pin 10
  if (!SD.begin(10))                                 //If no SD card available then fail
  {
    Serial.println("Initialization Failed!");
    return;
  }
  Serial.println("Initialization Completed Successfully!");
  // End initialize SD Card

  digitalWrite(led, LOW);                              
}
//End Setup

//Begin Loop
void loop() {
  bool newdata = true;
  unsigned long start = millis();
  while (millis() - start < 5000) {                 // Update every 5 seconds
    if (feedgps())
      newdata = true;
  }
  if (newdata) {
    gpsdump(gps);

  }
}
void gpsdump(TinyGPS &gps) {
  //Start GPS read
  gps.f_get_position(&flat, &flon, &age);           
  gps.get_datetime(&date, &time);                   
  speedmps = gps.f_speed_mps();                     
  satellites = gps.satellites();                   
  altitude = gps.f_altitude();                      
  course = gps.course();     
  //End GPS read
  delay(1000);
  //Start TMP36 temp sensor read
  tempReading = analogRead(tempPin);                      // READ TEMPERATURE
  float tempVoltage = tempReading * 5;                    // convert readings to voltage, using 5V power supply
  tempVoltage /= 1024.0;
  temperatureC = (tempVoltage - 0.5) * 100 ;              // now print out the temperature degrees C
  temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;       // now convert to Fahrenheight
  //End TMP36 temp sensor read

  //Start Humidity sensor read
  int humReading = analogRead(humPin);                      // read the value from the pin  
  double volt = humReading / 1023.0 * 5;                    // convert it into voltage (Vcc = 5V)  
  double sensorRH = 161.*volt/5 - 25.8;                     // calculate the sensor humitidy  
  double trueRH = sensorRH / (1.0546 - 0.0026*temperatureC);// adapt this for the given temperature  
  //end humidity sensor reading

  //Print data to Serial Debug
  Serial.println("Data Prints Correctly");
  Serial.print(flat, 4);
  Serial.print(", ");
  Serial.print(flon, 4);
  Serial.print(", ");
  Serial.print(date);
  Serial.print(", ");
  Serial.println(time);
  //End Serial print  

  digitalWrite(led, HIGH);                           //LED on before opening file 
  // Open Tracking.csv from SD Card
  myFile = SD.open("tracking.csv", FILE_WRITE);

  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to Tracking.csv...");
    myFile.print(flat, 4);                          
    myFile.print(", ");
    myFile.print(flon, 4);                      
    myFile.print(", ");
    myFile.print(altitude);                      
    myFile.print(", ");
    myFile.print(date);                      
    myFile.print(", ");
    myFile.print(time);                          
    myFile.print(", ");
    myFile.print(satellites);                      
    myFile.print(", ");   
    myFile.print(course);                          
    myFile.print(", ");
    myFile.print(speedmps);                         
    myFile.print(", ");
    myFile.print(bmp.readTemperature());
    myFile.print(", ");
    myFile.print(bmp.readPressure());
    myFile.print(", ");
    myFile.print(bmp.readAltitude());
    myFile.print(", ");
    myFile.print(temperatureC);
    myFile.print(", ");
    myFile.print(temperatureF);
    myFile.print(", ");
    myFile.print(sensorRH);
    myFile.print(", ");
    myFile.println(trueRH);

    delay(200);

    // close the file:
    myFile.close();
    digitalWrite(led, LOW);                            
    Serial.println("done."); 
  } 
  else {                                            // if the file didn't open, print an error:

    Serial.println("error opening tracking.csv");
  }
}
// Feed data as it becomes available 
bool feedgps() {
  while (nss.available()) {
    if (gps.encode(nss.read()))
      return true;

  }
  return true;
}

are you positive you fried the arduino? it should be able to take as much as 17 volts, no usb operates at that many volts

btricha2:
are you positive you fried the arduino? it should be able to take as much as 17 volts, no usb operates at that many volts

If the supply came via the voltage regulator, certainly. Does the USB supply come via the voltage regulator?

Well... The Bright side is that an FTDI device and a new 328... ?$10.00?) leaves about 90% of the board OK... and Very usable albeit with some encumbreance.

Bob

Hi,
Some years ago I used that GPS as it works on 5Volts (and 3.something). But when you use it with a 5Volt power supply the output signals are always 3. something Volts and not 5 Volt!!
To solve this I placed a signal amplifier between the GPS unit and the PIC (sorry, that's what I used then) to lift the signal to 5Volt. Then it works.
Hopefully this will help.

Attached the schema I used.
I am not responsible for wanted or unwanted results by using the schema in any form.

TweeTrapVersterker.jpg

If you suspect your GPS isn't working, it is quite easy to connect directly to the
PC through the USB/serial adaptor and see what it is outputing. You can use
the serial monitor for this or a program such as MiniGPS or several similar ones.

You are right, I forgot to write that the problem relates to the TTL output pin. In this case TTL is not 5Volt but 3.something volt. And that does not work with a microcontroller running with 5Volt power supply.
Just measure it with a oscilloscope.
Unless the manufacturer has changed this.....
The PIC microcontroller I used does not have USB I/O.
The pin I wanted to use was a TTL input.