Created
April 24, 2019 06:41
-
-
Save Isaac-the-Man/0e0953c98a44db3fad623f2e6476141d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
#include <Adafruit_Sensor.h> | |
#include <Adafruit_BMP085_U.h> | |
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085); | |
void setup(void) | |
{ | |
Serial.begin(9600); | |
Serial.println("Pressure Sensor Test"); Serial.println(""); | |
/* Initialise the sensor */ | |
if(!bmp.begin()) | |
{ | |
/* There was a problem detecting the BMP085 ... check your connections */ | |
Serial.print("Ooops, no BMP085 detected ... Check your wiring or I2C ADDR!"); | |
while(1); | |
} | |
} | |
void loop(void) | |
{ | |
/* Get a new sensor event */ | |
sensors_event_t event; | |
bmp.getEvent(&event); | |
/* Display the results (barometric pressure is measure in hPa) */ | |
if (event.pressure) | |
{ | |
/* Display atmospheric pressue in hPa */ | |
Serial.print("Pressure: "); | |
Serial.print(event.pressure); | |
Serial.println(" hPa"); | |
float temperature; | |
bmp.getTemperature(&temperature); | |
Serial.print("Temperature: "); | |
Serial.print(temperature); | |
Serial.println(" C"); | |
/* Convert the atmospheric pressure, and SLP to altitude */ | |
/* Update this next line with the current SLP for better results */ | |
float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA; | |
Serial.print("Altitude: "); | |
Serial.print(bmp.pressureToAltitude(seaLevelPressure, | |
event.pressure)); | |
Serial.println(" m"); | |
Serial.println(""); | |
} | |
else | |
{ | |
Serial.println("Sensor error"); | |
} | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment