Display pressure altitude

I have these codes which displays the pressure. I am using altimu-10 v4 with arduino uno. I am thinking of displaying the altitude too. So is there anyone out there to help me display the altitude with the pressure that i have done already? Thanks.

#include <Wire.h>
#include <LSM303.h>
#include <LPS.h>
#include <L3G.h>
#include <math.h>

L3G gyro;
LPS ps;
LSM303 compass;
char report[80];
float pressure;
float altitude;
float temperature;
float heading;

void setup() 
{
Serial.begin(9600);
Wire.begin();

if (!gyro.init())
  {
    Serial.println("Failed to autodetect gyro type!");
    while (1);
  }

  gyro.enableDefault();

Serial.begin(9600);
Wire.begin();
if (!ps.init())
  {
    Serial.println("Failed to autodetect pressure sensor!");
    while (1);
  }

  ps.enableDefault();

Serial.begin(9600);
Wire.begin();
   compass.init();
  compass.enableDefault();
}

void loop()
{
  gyro.read();

  //Serial.print("G ");
 // Serial.print("X: ");
  //Serial.print((int)gyro.g.x);
  //Serial.print(" Y: ");
  //Serial.print((int)gyro.g.y);
  //Serial.print(" Z: ");
  //Serial.println((int)gyro.g.z); 

float pressure = ps.readPressureInchesHg();
  float altitude = ps.pressureToAltitudeFeet(pressure);
  float temperature = ps.readTemperatureF();

  //Serial.print("p: ");
  Serial.print(pressure);
//  Serial.print(" inHg ");
//  Serial.print("  ");
//  Serial.print(altitude);
  //Serial.print(" ft ");
  //Serial.print(temperature);
  //Serial.println(" deg C");

   //compass.read();

  //snprintf(report, sizeof(report), "A: %6d %6d %6d    M: %6d %6d %6d",
    //compass.a.x, compass.a.y, compass.a.z,
//compass.m.x, compass.m.y, compass.m.z);
  Serial.println(report);

delay(1000);
}

Why does
your code wander
all over the

page like it
was typed by
a drunken
monkey?

Use Tools + Auto Format to sober up the monkey.

Where do you want to display the altitude? Can't you figure out how you display the pressure? Can't you display the altitude the same way?

Get rid of the commented out code. Use your delete key, instead, when the code is useless.

To display alttitude as well as pressure, change this part:

float pressure = ps.readPressureInchesHg();
  float altitude = ps.pressureToAltitudeFeet(pressure);
  float temperature = ps.readTemperatureF();

  //Serial.print("p: ");
  Serial.print(pressure);
//  Serial.print(" inHg ");
//  Serial.print("  ");
//  Serial.print(altitude);

to look like this:

float pressure = ps.readPressureInchesHg();
  float altitude = ps.pressureToAltitudeFeet(pressure);
  float temperature = ps.readTemperatureF();

  //Serial.print("p: ");
  Serial.print(pressure);
//  Serial.print(" inHg ");
//  Serial.print("  ");
  Serial.print(altitude);

johnwasser:
to look like this:

float pressure = ps.readPressureInchesHg();

float altitude = ps.pressureToAltitudeFeet(pressure);
  float temperature = ps.readTemperatureF();

//Serial.print("p: ");
  Serial.print(pressure);
//  Serial.print(" inHg ");
//  Serial.print("  ");
  Serial.print(altitude);

Might need a space in there.

PaulMurrayCbr:
Might need a space in there.

OK:

  Serial.print("  ");
  Serial.print(altitude);

:slight_smile: