BMP085 vs GPS code

Good Day all

Im trying to integrate some code to try and compare GPS Altitude to that of the BMP085

I found this online from, http://sites.google.com/site/wayneholder/gps-vs-barometric-altitude , but I get an error of “APM_BMP085 not declared in this scope” when calling " APM_BMP085.Init(2); // APM ADC initialization" and “APM_BMP085.Read();”, I havent changed anything other than the baud rate for the serial lines so Im not sure as to where the problem lies and I dont know how to contact the original author :S

#include <TinyGPS.h>
#include <NewSoftSerial.h>
#include <Wire.h>
#include <APM_BMP085.h> // ArduPilot Mega BMP085 Library

#define rxPin 2
#define txPin 3

TinyGPS       gps;
NewSoftSerial mySerial(rxPin, txPin);

void sendCmd (char *msg) {
  char cc;
  char chk = 0;
  mySerial.print('

, BYTE);
  while ((cc = msg++) != ‘\0’) {
    chk ^= cc;
    mySerial.print(cc, BYTE);
  }
  mySerial.print(’
’, BYTE);
  mySerial.println(chk, HEX);
}

void printFloat (double number, int digits) {
  // Handle negative numbers
  if (number < 0.0) {
    Serial.print(’-’);
    number = -number;
  }
  // Round correctly so that print(1.999, 2) prints as “2.00”
  double rounding = 0.5;
  for (uint8_t i = 0; i < digits; ++i)
    rounding /= 10.0;
  number += rounding;
  // Extract the integer part of the number and print it
  unsigned long int_part = (unsigned long) number;
  double remainder = number - (double) int_part;
  Serial.print(int_part);
  // Print the decimal point, but only if there are digits beyond
  if (digits > 0)
    Serial.print(".");
  // Extract digits from the remainder one at a time
  while (digits-- > 0) {
    remainder *= 10.0;
    int toPrint = int(remainder);
    Serial.print(toPrint);
    remainder -= toPrint;
  }
}

void setup()  {
  Serial.begin(57600);
  mySerial.begin(38400);
  //sendCmd(“PMTK314,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0”);
  //sendCmd(“PMTK220,200”);
  //sendCmd(“PMTK313,1”);
  //sendCmd(“PMTK301,2”);
  // Init BMP085
  APM_BMP085.Init(2);  // APM ADC initialization
  Serial.println(“Startup”);
}

byte slow;

void loop() {
  while (mySerial.available()) {
    if (gps.encode(mySerial.read()) && (slow++ & 0x0F) == 0) {
      float flat, flon;
      unsigned long age;
      gps.f_get_position(&flat, &flon, &age);
      Serial.print(“Lat: “);
      printFloat(flat, 5);
      Serial.print(”, Long: “);
      printFloat(flon, 5);
      Serial.print(”, Alt: “);
      printFloat(gps.altitude() / 100.0, 2);
      Serial.print(” Meters, Fix age: “);
      Serial.print(age);
      Serial.println(” ms.”);
      // Display Atmospheric Pressure
      float tmp_float;
      float altitude;
      APM_BMP085.Read();
      Serial.print(“Pressure: “);
      Serial.print(APM_BMP085.Press);              // Pa
      Serial.print(” Pa, Temperature: “);
      Serial.print(APM_BMP085.Temp / 10.0);        // degrees C
      Serial.print(” C, Altitude: “);
      tmp_float = (APM_BMP085.Press / 101325.0);
      tmp_float = pow(tmp_float, 0.190295);
      altitude = 44330 * (1.0 - tmp_float);
      Serial.print(altitude);                      // Meters
      Serial.println(” Meters\n”);
    }
  }
}

N.Turpion:

Go here for arduino code V22 compatible..

http://code.google.com/p/bmp085driver/

Ultra_high_res mode DOES NOT work on this lib. I have repaired it but not sent it to felipe.

I will contact him today I hope...

It works fine on my Mega2560 except for the one issue... Learn how to use the initialize code to set the altitude or pressure to "calibrate": the device.

Yeah Ive tried using it a few times before actually and noticed that if I leave the settings as is I dont get the numbers I expect. Not sure if its because Im inside a building or not. If I change the 250m setting to 0 it stays 0 or whatever number I set it at really. Same with the baro setting. Should I use this code at sea level or will it work at any height?

When I run the example of the BMP085 driver Output Im showing about 260 - 460 cm is this normal? the numbers do fluctuate a lot on the altitude and pressure. Also I know my altitude to be around 114m asl so Im wondering why it wont show this number?

Thanks

Hello N.Turpion,

As WillR said you must change initialization for your own known values. It can be current pressure from a weather station or known height from a GPS. Same as you would do when powering on a home weather station... If you run examples code with default settings, you will get wrong values if your current height is not 250m (that is my current location height and probably not yours). Based on your previous messages, your initialization height should be 114m. Try it. Its all about the starting point, it must be known.

Ultra_high_res is now working thanks to WillR, please check v0.3 branch at http://code.google.com/p/bmp085driver/source/browse/#svn%2Fbranches

Some info on fluctuating numbers:

  • make sure you are using Ultra_high_res;
  • disable autoupdate temperature and call calcTrueTemperature() less often (see BMP085_test2.pde);
  • you may also be interested in an experimental version that uses Exponential Moving Average to minimize this problem (see V0.3EMA branch);

Regards, Filipe