This is a sensor for air pressure and temperature. Do not connect +5V to +/VDD of this sensor!
Sensor will be damaged!
Hardware connections
- Vin +3v3
- GND GND
- SCL SCL
- SDA SDA
Program on Codebender
Program
// 2016 JanJeronimus copy from
/* BMP180 Absolute Pressure
Mike Grusin, SparkFun Electronics
This sketch shows how to get an absolute pressure reading from the BMP180
barometric pressure sensor. https://www.sparkfun.com/products/11824
Hardware connections:
-/GND to GND
+/VDD to 3.3V
(WARNING: do not connect +/VDD to 5V or the sensor will be damaged!)
You will also need to connect the I2C pins (SCL and SDA) to your
Arduino. The pins are different on different Arduinos:
Any Arduino pins labeled: SDA SCL
Uno, Redboard, Pro: A4 A5
Mega2560, Due: 20 21
Leonardo: 2 3
Leave the IO (VDDIO) pin unconnected. This pin is for connecting
the BMP180 to systems with lower logic levels such as 1.8V
*/
// Include the needed libraries. The SFE_BMP180 library will need to be
// added to your arduino/libraries folder
#include <SFE_BMP180.h>
#include <Wire.h>
// You will need to create an SFE_BMP180 object, here called "pressure":
SFE_BMP180 pressure;
void setup()
{
Serial.begin(9600);
Serial.println("REBOOT");
// Initialize the sensor (it is important to get calibration values stored on the device).
if (pressure.begin())
Serial.println("BMP180 init success");
else
{
// Oops, something went wrong, this is usually a connection problem,
// see the comments at the top of this sketch for the proper connections.
Serial.println("BMP180 init fail\n\n");
while(1); // Pause forever.
}
Serial.println("deg C, deg F, abs press mbar, abs press inHg");
}
void loop()
{
char status;
double T,P;
// 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)
{
// Wait for the measurement to complete:
delay(status);
// Retrieve the completed temperature measurement:
// Note that the measurement is stored in the variable T.
// Function returns 1 if successful, 0 if failure.
status = pressure.getTemperature(T);
if (status != 0)
{
// Print out the measurement:
Serial.print(T,2);
Serial.print(", ");
Serial.print((9.0/5.0)*T+32.0,2);
Serial.print(", ");
// 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)
{
// Wait for the measurement to complete:
delay(status);
// Retrieve the completed pressure measurement:
// Note that the measurement is stored in the variable P.
// Note also that the function requires the previous temperature measurement (T).
// (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.)
// Function returns 1 if successful, 0 if failure.
status = pressure.getPressure(P,T);
if (status != 0)
{
// Print out the measurement:
Serial.print(P,2);
Serial.print(", ");
Serial.println(P*0.0295333727,2);
}
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(1000); // Pause for one second.
}
Output
REBOOTBMP180 init success
deg C, deg F, abs press mbar, abs press inHg
24.68, 76.42, 1018.39, 30.08
Remark
The barometric pressure sensor is an I2C device found at address 0x77(You can check this using an I2C scan program https://codebender.cc/sketch:358105
No comments:
Post a Comment