/***********************
* Barometer
* you can see the value of temperature and air pressure displayed on Serial Monitor
************************/
#include <Wire.h>
#include <SFE_BMP180.h>
SFE_BMP180 pressure;
void setup() {
Serial.begin(9600);
Serial.println("REBOOT");
if (pressure.begin()) {
Serial.println("BMP180 init success");
} else {
Serial.println("BMP180 init failure...\n\n");
while (1)
; // pause forever
}
}
void loop() {
char status;
double T, P, p0, a;
/****************
* Loop here getting pressue readings every 10 seconds
* If you want sea-level-compensated pressue, as used in weather reports,
* you will need to know the altitude at which your measurements are taken.
* We're using a constant called ALTITUDE in this sketch:
* If you want to measure altitude, and not pressue, you will instead need
* to provide a known baseline pressue. This is shown at the end of the sketch.
* You must first get a temperature measurement to perform a pressure reading.
* Start a temperature measurement:
* If request is successful, the number of ms to wait is returned.
* If request is unsuccessful, 0 is returned
******************/
status = pressure.startTemperature();
if (status != 0) {
delay(status); // Wait for the measurement to complete
status = pressure.getTemperature(T); // retrive the completed temperature measurement and stored in variable T
if (status != 0) { // measurement success
Serial.print("temperature: ");
Serial.print(T, 2);
Serial.print(" deg C ");
float tempF = 1.8 * T + 32.0;
Serial.print(" ");
Serial.print(tempF, 2);
Serial.println(" deg F ");
/**************
* start a pressure measurement
* the parameter is the oversampling setting, from 0 to 3 (highest res, longest wait).
* If request is successful, the number of ms to wait is returned.
* If request is unsuccessful, 0 is returned
****************/
status = pressure.startPressure(3);
if (status != 0) {
delay(status);
// store the measurement in variable P
// if temperature is stable, you can do one temperature measurement for a number of pressure measurements.
status = pressure.getPressure(P, T);
if (status != 0) {
Serial.print("pressure: ");
Serial.print(P, 2);
Serial.print(" mb ");
Serial.print(" ");
Serial.print(P * 0.0295301, 2); // convert millibars to inches of mecury
Serial.print(" inches ");
Serial.println(" ");
Serial.println(" ");
/***************
* The pressure sensor returns absolute pressure, which varies wiht altitude.
* To remove the effects of altitude, use the sea-level function and your current altitude.
* This number is commonly used in weather reports.
* Parameters: P = absolute pressure in mb, ALTITUDE = current altitude in m.
* Result: p0 = sea-level compensated pressure in mb
****************/
} else {
Serial.println("error retrieving pressure measurement\n");
}
} else {
Serial.println("error starting pressure measurement\n");
}
} else {
Serial.println("error retrieving temperature measurement\n");
}
} else {
Serial.println("error starting temperature measurement\n");
}
delay(5000); // Pause for 5 seconds
}