Go Down

Topic: GPS Logger, reading and Writing to and from SD (Read 1 time) previous topic - next topic

-dev

Quote from: Tonyi
I'm guessing you mean, I should fix the formatting of the closing brackets
Yes, although ctrl-T will also fix 'em.  :)

Quote
show me a better, more efficient way, to create the spacing, after the header.txt was added.
Put the two blank lines at the end of header.kml and remove them from copyFile.  Super-efficient, because there is no code.  Put two blank lines at the beginning of trailer.kml if you want.

Quote
I ordered a pressure sensor (barometer) and would appreciate a bit more of you guidance implementing into the code.
The only thing you have to be careful about is the time it takes to get a reading.  Many libraries will wait for a reading to complete (i.e., it "blocks").  That can cause the GPS to overflow the Arduino's input buffer, and you'll lose a fix.

Tell me which barometer it is, and I can suggest a library that doesn't block, or the calls you should use to avoid blocking.

Tonyi

#16
Apr 11, 2017, 11:34 pm Last Edit: Apr 12, 2017, 12:16 am by Tonyi
Ok, somehow the spaces didn't work when I first did it.  Perhaps I was still using [] to select the text at the time, before I submitted my problem code here.
The pressure sensor I ordered is this one, the most inexpensive one I could find, to test with first: BMP:280

I thought this would be a good place to upload a few pics of the dirigible I'm working on as well as the header.txt, trailer.txt and an example log, of a walk around my neighborhood today *.kml, that can be uploaded into "google maps" or Google "my maps". I had to edit this post because this sight doesn't allow *.kml files to be uploaded.  Just change the extension from *.txt to *.kml in my next post. I guess dropbox files don't work either...I didn't start at my house, for privacy sake.  All those dangerous coders out there you know!


Tonyi

You are probably wondering why the top half of the zeppelin has plastic wrap on it...  I'm still experimenting with a wrapper for the shell; the actual flotation, will be large Mylar ballast inside each half of the zeppelin.  I will paint the plastic wrap on the inside to make it look right.  Anyhow here is the walk about the neighborhood txt file mentioned in the above post.

Tonyi

Hello again, /dev and anybody else that may be following this thread, I finally received my BMP280 Chinese sensor.  Had trouble getting it to work with all the Library files I found until changing a address from 77 to 76 in the Adafruit_BMP280 library's *.h file.   It works on its own, even after I stripped down the example *.ino file, into this:
Code: [Select]
/*
  BMP280 Presure & Temperature Sensor
  I2C Connection: Vin: 5V/3V, GND: GND, SCK: A5 (SCL), SDI: A4 (SDA)
*/

#include <Wire.h>
#include "SPI.h" //Why? Because library supports SPI and I2C connection
#include <Adafruit_Sensor.h>
#include "Adafruit_BMP280.h"

//Setup connection of the sensor
Adafruit_BMP280 bmp; // I2C

//Variables
//float pressure;   //To store the barometric pressure (Pa)
//float temperature;  //To store the temperature (oC)
float altimeter;    //To store the altimeter (m) (you can also use it as a float variable)


void setup() {
  bmp.begin();    //Begin the sensor
  Serial.begin(9600); //Begin serial communication at 9600bps
}

void loop() {
  altitude();
  Serial.print(", ");
  Serial.println(altimeter);

}

void altitude() {
  //Read values from the sensor:
  // pressure = bmp.readPressure();
  //temperature = bmp.readTemperature();
  // float fahrenheit = (temperature*1.8)+32; // calc. reminder in case I want to use it in the future
  altimeter = bmp.readAltitude (1050.35) * .1; //Change the "1050.35" to your city current barrometric pressure (https://www.wunderground.com)

  //   delay(500); //Update every 10th of sec
}


This is how I altered the file, /Dev has been helping me so much with, but the altimeter is totally wrong and always prints "96":

Code: [Select]
/*
  BMP280 Presure & Temperature Sensor
  I2C Connection: Vin: 5V/3V, GND: GND, SCK: A5 (SCL), SDI: A4 (SDA)
*/
/*
  SD card connections:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4
*/

float altimeter;    //To store the altimeter (m) (you can also use it as a float variable)
int chipSelect = 4;
const int buttonPin = 5;
int buttonState = 0;
const char *gpsFilename = "GPSData.txt";

#include <SdFat.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BMP280.h"

SdFat SD;
File  gpsDataFile; // Data object you will write your sensor data to


//---------------------
//  Pick a serial port for the GPS

// BEST choice is a HardwareSerial port:
//    Use Serial1 on a Mega, Leo or Due board
//    You could use Serial on any board (disconnect GPS
//       when uploading over USB).
//#define gpsPort Serial1

// 2nd best:
//#include <AltSoftSerial.h>
//AltSoftSerial gpsPort; // must be on specific pins (8 & 9 for an UNO)

// 3rd best: must be baud rate 9600, 19200 or 38400
#include <NeoSWSerial.h>
NeoSWSerial gpsPort(3, 2);

// Worst: SoftwareSerial NOT RECOMMENDED
//---------------------

#include <NMEAGPS.h>
NMEAGPS GPS;
gps_fix fix;

//Setup connection of the sensor
Adafruit_BMP280 bmp; // I2C

void setup()
{
  Serial.begin(115200);
  gpsPort.begin( 9600 );
  bmp.begin();    //Begin the pressure sensor
  // Configure the GPS device
  GPS.send_P( &gpsPort, F("PGCMD,33,0") );  //Turn off antenna update nuisance data
  GPS.send_P( &gpsPort, F("PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0") ); //Request RMC and GGA Sentences only
  GPS.send_P( &gpsPort, F("PMTK220,1000") ); //Set update rate to 1 hz
  pinMode(buttonPin, INPUT);
  pinMode(10, OUTPUT); // reserve it to keep SD card happy
  if (!SD.begin(chipSelect)) {
    Serial.println( F("No SD card/reader found!") );
    for (;;); // hang here!
  }

  if (SD.exists(gpsFilename)) { //Delete old data files to start fresh
    SD.remove(gpsFilename);
  }

  gpsDataFile = SD.open(gpsFilename, FILE_WRITE);

  copyFile( "header.txt" );

}


void loop()
{

  Serial.print(", ");
  Serial.println(altimeter);
  // Read characters and parse into a fix structure
  if (GPS.available( gpsPort )) {

    // Get the new fix data (GPS quiet time just started)
    fix = GPS.read();

    // Only save data if we have a fix
    if (fix.valid.status &&
        (fix.status >= gps_fix::STATUS_STD)) {
      altimeter = bmp.readAltitude (1050.35) * .1;

      gpsDataFile.print( fix.longitude(), 5);
      gpsDataFile.print( ',' );
      gpsDataFile.print( fix.latitude(), 5 );
      gpsDataFile.print( ',' );
      //gpsDataFile.println( fix.altitude() );
      gpsDataFile.println(altimeter);
      gpsDataFile.flush(); // this works, but it slows things down
    }
  }

  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    gpsDataFile.println(" ");
    copyFile( "trailer.txt" );  // copy the rest of the XML stuff
    gpsDataFile.close();
    while (true) { // forever
      digitalWrite(10, LOW);
    }
  }

} // loop


void copyFile( const char *filename )
{
  File file = SD.open( filename );
  if (file.isOpen()) {

    uint8_t buffer[ 256 ];
    for (;;) {
      int numRead = file.read( &buffer[0], sizeof(buffer) );
      if (numRead == 0)
        break;
      gpsDataFile.write( buffer, numRead );

    }
    gpsDataFile.println(" ");
    gpsDataFile.println(" ");
    file.close();
  }
}

void altitude() {
  //Read values from the sensor:
  // pressure = bmp.readPressure();
  //temperature = bmp.readTemperature();
  // float fahrenheit = (temperature*1.8)+32; // calc. reminder in case I want to use it in the future
  altimeter = bmp.readAltitude (1050.35) * .1; //Change the "1050.35" to your city current barrometric pressure (https://www.wunderground.com)

  //delay(100); //Update every 10th of sec
}


The calculations also give me the wrong Altitude, but first thing first.  Help me get it to print to the SD card correctly, please.

Tonyi

After I noticed the link to https://www.wunderground.com, I obtained the pressure at sea level and converted it from inches to Millibars and the measurements are now pretty accurate and consistent, while changing elevations or sitting still.  I have still not been able to incorporate the stand alone, pressure sketch, with the GPS/SD card sketch, and have the pressure sensor function properly.  It does not matter if I'm printing to the SD card or to the serial monitor; it now gives me a -1258.18

Code: [Select]
-82.41294,28.07180,-1258.18
-82.41299,28.07178,-1258.18
-82.41296,28.07178,-1258.18
-82.41294,28.07178,-1258.18
-82.41293,28.07178,-1258.18
-82.41293,28.07178,-1258.18


The number never deviates so I don't think its a calculation problem.   Notice the lat. and long. do deviate slightly and are working correctly.  I have used a higher amp. battery through the USB port, does anybody think it could be a power problem?   Any help would be appreciated, I'm out of ideas...

-dev

Quote from: Tonyi
It works on its own, even after I stripped down the example *.ino file, into this:
Ok, this stand-alone program gives you the correct altitude?

Quote from: Tonyi
This is how I altered the file... but the altimeter is totally wrong and always prints "96"
After merging the stand-along program with the GPS/SD program, the altimeter always prints "96"?

Quote from: Tonyi
After I noticed the link to https://www.wunderground.com, I obtained the pressure at sea level and converted it from inches to Millibars and the measurements are now pretty accurate and consistent, while changing elevations or sitting still.  I have still not been able to incorporate the stand alone, pressure sketch, with the GPS/SD card sketch, and have the pressure sensor function properly.  It does not matter if I'm printing to the SD card or to the serial monitor; it now gives me a -1258.18
?

I'm confused.  Is there a 3rd sketch you got from that website, and it also gives you the correct altitude?

Let's start over.  Please list the wiring, show us a sketch, the Serial Monitor output and/or the SD file contents it produces.

I can only make one comment about this code:

Code: [Select]
void loop()
{
  Serial.print(", ");
  Serial.println(altimeter);

  // Read characters and parse into a fix structure
  if (GPS.available( gpsPort )) {

    // Get the new fix data (GPS quiet time just started)
    fix = GPS.read();

    // Only save data if we have a fix
    if (fix.valid.status &&
        (fix.status >= gps_fix::STATUS_STD)) {
      altimeter = bmp.readAltitude (1050.35) * .1;

      gpsDataFile.print( fix.longitude(), 5);
      gpsDataFile.print( ',' );
      gpsDataFile.print( fix.latitude(), 5 );
      gpsDataFile.print( ',' );
      //gpsDataFile.println( fix.altitude() );
      gpsDataFile.println(altimeter);
      gpsDataFile.flush(); // this works, but it slows things down
    }
  }

This tries to print the altimeter value every time through loop, thousands of times per second.  But the altimeter value is only updated when a new GPS fix is received (once per second).  This will try to print too much and interferes with receiving GPS data.  Instead, try this:

Code: [Select]
void loop()
{
  // Read characters and parse into a fix structure
  if (GPS.available( gpsPort )) {

    // Get the new fix data (GPS quiet time just started)
    fix = GPS.read();

    // Only save data if we have a fix
    if (fix.valid.status &&
        (fix.status >= gps_fix::STATUS_STD)) {

      altimeter = bmp.readAltitude (1050.35) * .1;
      Serial.println(altimeter);             // <-- print only after the reading is taken

      gpsDataFile.print( fix.longitude(), 5);
      gpsDataFile.print( ',' );
      gpsDataFile.print( fix.latitude(), 5 );
      gpsDataFile.print( ',' );
      //gpsDataFile.println( fix.altitude() );
      gpsDataFile.println(altimeter);
      gpsDataFile.flush();
    }
  }

Cheers,
/dev

Tonyi

Before I reply to the other questions; I tried you alteration and got this error.   
Code: [Select]
Arduino: 1.6.8 (Windows 10), Board: "Arduino Nano, ATmega328"


exit status 1
exit status 1
'copyFile' was not declared in this scope

'copyFile' was not declared in this scope

I recall placing that piece of code there, for the same reason, and that's why I had to rearrange it so it; so it would compile even though the, Read timing is way off.  Is there another way of getting one read on the pressure sensor, when the gps does its read?

-dev

I only gave you a snippet of code, not an entire sketch.  That is an excerpt from your 2nd sketch in reply #18.  I only showed enough lines that you could see that I moved the Serial.print statement inside the if statement.

In general, small modifications are shown with a snippet.  If you get error messages after modifying your program, you must include the entire sketch in your question.

Tonyi

#23
May 08, 2017, 01:35 am Last Edit: May 08, 2017, 01:42 am by Tonyi
Code: [Select]
If you get error messages after modifying your program, you must include the entire sketch in your question.  Ok, that sounds sensible, thanks for advising me.  Here is the total code:
Code: [Select]
/*
  SD card connections:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4
*/

int chipSelect = 4;
const int buttonPin = 5;
int buttonState = 0;
#include <SdFat.h>
#include <SPI.h>

SdFat SD;
File  gpsDataFile; // Data object you will write your sensor data to
const char *gpsFilename = "GPSData.txt";

//---------------------
//  Pick a serial port for the GPS

// BEST choice is a HardwareSerial port:
//    Use Serial1 on a Mega, Leo or Due board
//    You could use Serial on any board (disconnect GPS
//       when uploading over USB).
//#define gpsPort Serial1

// 2nd best:
//#include <AltSoftSerial.h>
//AltSoftSerial gpsPort(9, 8); // must be on specific pins (8 & 9 for an UNO)

// 3rd best: must be baud rate 9600, 19200 or 38400
#include <NeoSWSerial.h>
NeoSWSerial gpsPort(3, 2);

// Worst: SoftwareSerial NOT RECOMMENDED
//---------------------

#include <NMEAGPS.h>
NMEAGPS GPS;
gps_fix fix;

//---------------------
#include <SoftWire.h>
#include <AsyncDelay.h>

SoftWire sw(SDA, SCL);
#include "Adafruit_BMP280.h"

//Setup connection of the sensor
Adafruit_BMP280 bmp; // I2C
float altimeter;    //To store the altimeter (m) (you can also use it as a float variable)

void setup(void)
{
    gpsPort.begin( 9600 );

  // Configure the GPS device
  GPS.send_P( &gpsPort, F("PGCMD,33,0") );  //Turn off antenna update nuisance data
  GPS.send_P( &gpsPort, F("PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0") ); //Request RMC and GGA Sentences only
  GPS.send_P( &gpsPort, F("PMTK220,1000") ); //Set update rate to 1 hz
  pinMode(buttonPin, INPUT);
  pinMode(10, OUTPUT); // reserve it to keep SD card happy
  if (!SD.begin(chipSelect)) {
    //Serial.println( F("No SD card/reader found!") );
    for (;;); // hang here!
  }

  if (SD.exists(gpsFilename)) { //Delete old data files to start fresh
    SD.remove(gpsFilename);
  }

  gpsDataFile = SD.open(gpsFilename, FILE_WRITE);

  copyFile( "header.txt" );
  //-------------------------------
 
  //Serial.begin(9600);
  sw.setTimeout_ms(40);
  sw.begin();
  bmp.begin();    //Begin the sensor
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);

  // Set how long we are willing to wait for a device to respond
  sw.setTimeout_ms(200);

  const uint8_t firstAddr = 1;
  const uint8_t lastAddr = 0x7F;
 /*
  Serial.println();
  Serial.print("Interrogating all addresses in range 0x");
  Serial.print(firstAddr, HEX);
  Serial.print(" - 0x");
  Serial.print(lastAddr, HEX);
  Serial.println(" (inclusive) ...");
*/
  for (uint8_t addr = firstAddr; addr <= lastAddr; addr++) {
    digitalWrite(LED_BUILTIN, HIGH);
    delayMicroseconds(10);

    uint8_t startResult = sw.llStart((addr << 1) + 1); // Signal a read
    sw.stop();

    if (startResult == 0) {
/*      Serial.print("\rDevice found at 0x");
      Serial.println(addr, HEX);
      Serial.flush();
      */
    }
    digitalWrite(LED_BUILTIN, LOW);

    delay(50);
  }
 // Serial.println("Finished");

}


void loop()
{
  // Read characters and parse into a fix structure
  if (GPS.available( gpsPort )) {

    // Get the new fix data (GPS quiet time just started)
    fix = GPS.read();

    // Only save data if we have a fix
    if (fix.valid.status &&
        (fix.status >= gps_fix::STATUS_STD)) {

      altimeter = bmp.readAltitude (1050.35) * .1;
      Serial.println(altimeter);             // <-- print only after the reading is taken

      gpsDataFile.print( fix.longitude(), 5);
      gpsDataFile.print( ',' );
      gpsDataFile.print( fix.latitude(), 5 );
      gpsDataFile.print( ',' );
      //gpsDataFile.println( fix.altitude() );
      gpsDataFile.println(altimeter);
      gpsDataFile.flush();
    }
  }

void altitude() {
  //Read values from the sensor:
  // pressure = bmp.readPressure();
  //temperature = bmp.readTemperature();
  // float fahrenheit = (temperature*1.8)+32; // calc. reminder in case I want to use it in the future
  altimeter = bmp.readAltitude (1017.948); //Change the "1050.35" to your city current barrometric pressure (https://www.wunderground.com)

  //   delay(500); //Update every 10th of sec
}

void copyFile( const char *filename )
{
  File file = SD.open( filename );
  if (file.isOpen()) {

    uint8_t buffer[ 256 ];
    for (;;) {
      int numRead = file.read( &buffer[0], sizeof(buffer) );
      if (numRead == 0)
        break;
      gpsDataFile.write( buffer, numRead );

    }
    gpsDataFile.println(" ");
    gpsDataFile.println(" ");
    file.close();
  }
}


Now to answer some of your prior question (sorry its taken so long, I was out of town).
Code: [Select]
Ok, this stand-alone program gives you the correct altitude?  There was originally a lot more to the code in the example I found, which had code for other sensors and modules.   I stripped that out of it and saved the code exclusively meant for making the pressure sensor function.   And the code, by it self, which is an the beginning of post 18 works just fine.  When I combined it, it no longer gives me a pressure amount.  At first it was giving me a "96" then after a restart it started giving me the number 1258.18 both in serial reads and on the SD card as seen above, in the third row.
Code: [Select]
I'm confused.  Is there a 3rd sketch you got from that website, and it also gives you the correct altitude? No, no third sketch.  I was just mentioning that after I calibrated, the math, by adjusting the sea level, for the Tampa area, from that website, my pressure sensor readings where spot on, and that confirmed that the altitude given by the GPS sensor was 15 meters or more, off from the actual altitude.  But that isn't a problem, I just got off track by mentioning it.

-dev

Quote
I tried you alteration and got this error.  


Arduino: 1.6.8 (Windows 10), Board: "Arduino Nano, ATmega328"

exit status 1
'copyFile' was not declared in this scope
You're missing the closing brace for loop:

Code: [Select]
void loop()
{
   ...

    }
  }
}     <-- missing!

void altitude() {

A missing brace can cause weirderror messages.

BTW, this is a [quote] block:

Quote
... something you said ...
... and this is a [code] block:

Code: [Select]
... some code goes here...
Cheers,
/dev

Tonyi

I seem to have a chronic recurring bracket omission problem.   The code runs fine now, but the problem remains the same, with one difference, that must point to something pertinent, but I can't fathom what it is...  the number spit out has changed to 4433.00 instead of -1258.18 .
Code: [Select]
-82.41262,28.07186,4433.00
-82.42262,28.07186,4433.00
-82.42263,28.07186,4433.00
-82.42264,28.07186,4433.00
-82.42265,28.07187,4433.00

I should have noticed the quote tags, thanks for the heads up.

-dev

Don't use SoftWire.  Ii didn't notice that you added that.  You've got the sensor connected to the hardware I2C pins, so you don't need a software I2C library.  If you want to scan the I2C bus to confirm the address, use a separate "I2C scanner" sketch.

Here is a conflict:

Code: [Select]
  sw.begin();
  bmp.begin();    //Begin the sensor

This tells two libraries to listen to the same two pins.  Eliminate all the sw stuff, and the Adafruit_BMP library will probably work, just like the Adafruit example did.

Tonyi

#27
May 09, 2017, 02:40 am Last Edit: May 09, 2017, 03:56 am by Tonyi
I went back to prior code, without the softwire library in it, and now the pressure sensor is back to spitting out -96.13:
Code: [Select]
-82.42265,28.07184,-96.13
-82.42265,28.07184,-96.13
-82.42265,28.07184,-96.13
-82.42265,28.07184,-96.13
-82.42265,28.07184,-96.13
-82.42265,28.07184,-96.13


Here  Is the code as used to get the above results, or lack of, may be a better way of putting it.  Something I just noticed, probably not important.  The reason I had different result from the pressure sensor readings, was due to the sea level multiplier I was using at the time.  If I do a reading without anything in the parenthesis "altimeter = bmp.readAltitude();"...... I get -1272.30, over and over, which is still the same problem I've been having all along. 

Code: [Select]

/*
  SD card connections:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4
*/

int chipSelect = 4;
const int buttonPin = 5;
int buttonState = 0;
#include <SdFat.h>
#include <SPI.h>

SdFat SD;
File  gpsDataFile; // Data object you will write your sensor data to
const char *gpsFilename = "GPSData.txt";
float altimeter;    //To store the altimeter (m) (you can also use it as a float variable)
#include "Adafruit_BMP280.h"
Adafruit_BMP280 bmp; // I2C
//---------------------
//  Pick a serial port for the GPS

// BEST choice is a HardwareSerial port:
//    Use Serial1 on a Mega, Leo or Due board
//    You could use Serial on any board (disconnect GPS
//       when uploading over USB).
//#define gpsPort Serial1

// 2nd best:
//#include <AltSoftSerial.h>
//AltSoftSerial gpsPort; // must be on specific pins (8 & 9 for an UNO)

// 3rd best: must be baud rate 9600, 19200 or 38400
#include <NeoSWSerial.h>
NeoSWSerial gpsPort(3, 2);

// Worst: SoftwareSerial NOT RECOMMENDED
//---------------------

#include <NMEAGPS.h>
NMEAGPS GPS;
gps_fix fix;


void setup()
{
  Serial.begin(115200);
  gpsPort.begin( 9600 );
  bmp.begin();    //Begin the sensor
  // Configure the GPS device
  GPS.send_P( &gpsPort, F("PGCMD,33,0") );  //Turn off antenna update nuisance data
  GPS.send_P( &gpsPort, F("PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0") ); //Request RMC and GGA Sentences only
  GPS.send_P( &gpsPort, F("PMTK220,1000") ); //Set update rate to 1 hz
  pinMode(buttonPin, INPUT);
  pinMode(10, OUTPUT); // reserve it to keep SD card happy
  if (!SD.begin(chipSelect)) {
    Serial.println( F("No SD card/reader found!") );
    for (;;); // hang here!
  }

  if (SD.exists(gpsFilename)) { //Delete old data files to start fresh
    SD.remove(gpsFilename);
  }

  gpsDataFile = SD.open(gpsFilename, FILE_WRITE);

  copyFile( "header.txt" );

}


void loop()
{
  //altitude();
  // Read characters and parse into a fix structure
  if (GPS.available( gpsPort )) {

    // Get the new fix data (GPS quiet time just started)
    fix = GPS.read();

    // Only save data if we have a fix
    if (fix.valid.status &&
        (fix.status >= gps_fix::STATUS_STD)) {
      altimeter = bmp.readAltitude (1050.35) * .1;
      Serial.println(altimeter);             // <-- print only after the reading is taken

      gpsDataFile.print( fix.longitude(), 5);
      gpsDataFile.print( ',' );
      gpsDataFile.print( fix.latitude(), 5 );
      gpsDataFile.print( ',' );
      // gpsDataFile.println( fix.altitude() );
      gpsDataFile.println(altimeter);
      gpsDataFile.flush(); // this works, but it slows things down
    }
  }

  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    gpsDataFile.println(" ");
    copyFile( "trailer.txt" );  // copy the rest of the XML stuff
    gpsDataFile.close();
    while (true) { // forever
      digitalWrite(10, LOW);
    }
  }
} // loop


void copyFile( const char *filename )
{
  File file = SD.open( filename );
  if (file.isOpen()) {

    uint8_t buffer[ 256 ];
    for (;;) {
      int numRead = file.read( &buffer[0], sizeof(buffer) );
      if (numRead == 0)
        break;
      gpsDataFile.write( buffer, numRead );

    }
    gpsDataFile.println(" ");
    gpsDataFile.println(" ");
    file.close();
  }
}
/*
  void altitude() {
  //Read values from the sensor:
  // pressure = bmp.readPressure();
  //temperature = bmp.readTemperature();
  // float fahrenheit = (temperature*1.8)+32; // calc. reminder in case I want to use it in the future
  altimeter = bmp.readAltitude (1014.900); //Change the "1050.35" to your city current barrometric pressure (https://www.wunderground.com)

  //   delay(500); //Update every 10th of sec
  }
*/



-dev

A quick google for "bmp280 giving negative altitude" found this thread.  You must be using a sea level pressure that is less than your current barometric pressure.  The calculations will yield a negative altitude.

You need the current weather conditions to set the sea level presssure in hectoPascals.  That's inches of Hg times 33.8639.

The number you pass to readAltitude should be based on the current pressure:

    30.01 inches Hg * 33.8639 = 1016.26

Since you're in Tampa, you're basically at sea level.  :)  You should always pass in the current weather pressure, adjusted for your elevation (48 feet ?) with a calculation.  As you mentioned, wunderground.com has a calculator that uses the formula:

     sea level pressure = P * ( 1 - 0.0065h / (T + 0.0065h + 273.15) ) ^ -5.257

where "P" is the local barometric pressure in hPa, "h" is altitude in meters, and "T" is temperature in Celsius.  After converting 30.01" Hg, 48 feet and 59°F to the units it wants, it calculates a sea level pressure of 1018.02.

Your sketch uses 1050.35hPa, which is 31.01 inches Hg.  According to this, the pressure hasn't been that high in the past week.

Be sure to get the BMP280 stand-alone sketch working first, then use the same sea level parameter in the SD+GPS+BMP280 sketch.

Tonyi

You explained that well, but I knew all that.   I was merely pointing out the discrepancy between the readings from one test code to the next.  They where due to being done on different days, with different sea levels entered by me, therefore the sea level for Tampa I used to calculate the Altitude was different on each different code I used to try to get the pressure sensor working with.  
Quote
Be sure to get the BMP280 stand-alone sketch working first, then use the same sea level parameter in the SD+GPS+BMP280 sketch.
I just ran the BMP280 code that I posted at the beginning of post #18 that has....
Quote
I2C Connection: Vin: 5V/3V, GND: GND, SCK: A5 (SCL), SDI: A4 (SDA)
......written in the first line and get.  
Code: [Select]
, 0.ÿ, 0.50
, 0.50
, 0.50
, 0.50
, 0.50
, 0.50
, 0.50
, 0.50
, 0.50
, 0.50
, 0.50
, 0.52
, 0.52
, 0.52
, 0.52
, 0.52
, 0.49
, 0.49
, 0.49
, 0.49
, 0.50
, 0.50
, 0.50
, 0.50
, 0.50
, 0.51
, 0.51
, 0.51
, 0.51
, 0.53
, 0.53
, 0.53
, 0.53
, 0.51
, 0.51
, 0.51

Which is a little lower than I am.  And yes I converted the 30.05ins to 1017.27mbar before uploading the code to my Arduino.   Remember most of Tampa is slightly above sea level and I am in the AC and its actually kind of hot outside.  Notice the code deviates slightly, that's because the stand alone BMP280 code is working just fine.  I am still in the same place;.... baffled why it doesn't work when combined with the gps code.  I know you must be getting frustrated with this, as I am, but hope you can press on.

Go Up