Arduino library for the BMP180 temperature/pressure sensor. Currently supported products:
BMP180 GY-68 Digital Baromic Pressure Sensor Module (HCMODU0101) available from hobbycomponents.com
This library can be used to obtain calibrated temperature and pressure reading from a BMP180 sensor or module. The example has been written particularly for the BMP180 GY-68 Digital Baromic Pressure Sensor Module (HCMODU0101) available from hobbycomponents.com but should work with any compatible BMP180 sensor/module.
You will need to download (please log in to download the library) and unzip this library to the Arduino development environments library area.
On Windows:
My Documents\Arduino\libraries\
On Mac:
Documents/Arduino/libraries/
Linux:
Usually found within the users home area under /Arduino/libraries/
Using the HCBMP180 library
To use the library just include the HCBMP180.h header file and then create an instance of the library. E.g:
Code: Select all
#include "HCBMP180.h"
HCBMP180 HCBMP180(I2CBMP180ADD);
To initialise the library add the following line to the setup() section of your sketch:
Code: Select all
HCBMP180.Init();
The following functions are available with this library:
Code: Select all
HCBMP180.Mode(Oss);
ULTRA_LOW_POWER
STANDARD
HIGH_RESOLUTION
ULTRA_HIGH_RESOLUTION
If this function is omitted then the library defaults to ULTRA_HIGH_RESOLUTION
Code: Select all
Temp = HCBMP180.GetTemp();
Returns an integer value containing the temperature value in 0.1oC increments. To convert to oC simply multiply the result by 10
Code: Select all
Pressure = HCBMP180.GetPressure();
Returns a long integer value containing the pressure in Pascals. To convert to Millibar (mb) simply divide the result by 100.
Code: Select all
Altitude = HCBMP180.Altitude(p, p0);
p is the current pressure in Pascals and can be obtained using the GetPressure() library function.
p0 is the current pressure at sea level in pascals. You can obtain an up to date value by visiting an on-line weather site for your location. To convert a value from Millibar (mb) to Pascals simply multiply the value by 100
Returns a value of type double containing the current altitude of the sensor in meters above sea level.
Code: Select all
Pressure = HCBMP180.SeaLevelPressure(p, a);
p is the current pressure in Pascals and can be obtained using the GetPressure() library function.
a is the sensors current altitude above sea level in meters. You can obtain this value by visiting an on-line map that provides altitude information for you location.
Returns a long integer value containing the current pressure in Pascals at sea level. To convert to Millibars simply divide the result by 100.
Code: Select all
/* FILE: HCBMP180_Example
DATE: 24/05/16
VERSION: 0.1
AUTHOR: Andrew Davies
Created by Hobby Components Ltd (HOBBYCOMPONENTS.COM)
24/05/16 version 0.1: Original version
This is an example of how to use the HCBMP180 Arduino library to obtain measurement
readings from a BMP180 sensor or module. The example has been written particularly
for the BMP180 GY-68 Digital Baromic Pressure Sensor Module (HCMODU0101) available
from hobbycomponents.com
The example demonstrates how to get the current calibrated temperature and
pressure reading from the sensor and also how to use the library to obtain current
Altitude above sea level, differential altitude, and baromic pressure at sea level
(useful for weather forecasting). To use the module connect it to your Arduino as
follows:
BMP180....Uno/Nano
VIN.......+5V (for HCMODU00101) for other BMP180 modules check for correct supply voltage.
GND.......GND
SCL.......A5
SDA.......A4
You may copy, alter and reuse this code in any way you like, but please leave
reference to HobbyComponents.com in your comments if you redistribute this code.
This software may not be used directly for the purpose of selling products that
directly compete with Hobby Components Ltd's own range of products.
THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER
EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES,
INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
REASON WHATSOEVER.
*/
/* Include the HCBMP180 library */
#include "HCBMP180.h"
/* Current air pressure at sea level in Pascals. Used for calculating the absolute
* altitude above sea level. You can obtain an up to date value by visiting an on-line
* weather site for your location that also provides current baromic air pressure.
* To convert a value from Millibar (mb) to Pascals simply multiply the value by 100 */
#define PRESSURE_AT_SEA_LEVEL 102100
/* Current sensor altitude above sea level in meters. Used for calculating the pressure
* at sea level (useful for weather forecasting). You can obtain this value by visiting
* an on-line map that provides altitude information for you location. */
#define LOCATION_ALTITUDE 60.29
/* Create an instance of the library */
HCBMP180 HCBMP180(I2CBMP180ADD);
/* Used for the differential altitude example */
double Reference_Altitude;
void setup()
{
/* Initialise the HCBMP180 library and the serial interface */
HCBMP180.Init();
Serial.begin(9600);
/* Make an initial altitude measurement which will then be used by the differential
* altitude example to calculate any changes in height since the sketch was started */
Reference_Altitude = HCBMP180.Altitude(HCBMP180.GetPressure(), PRESSURE_AT_SEA_LEVEL);
}
void loop()
{
int Temp;
long Pressure, SeaLevel;
double Altitude;
/* Get the current temperature in 0.1oC units */
Temp = HCBMP180.GetTemp();
/* Output the temperature to the serial port. Temperature is in 0.1oC units so to
* convert to oC simply divide by 10 */
Serial.print("Temperature (oC): ");
Serial.println((float)Temp / 10);
/* Get the current pressure in Pascals */
Pressure = HCBMP180.GetPressure();
/* Output the pressure to the serial port in Millibars. To convert from Pascals to
* Millibars simply divide by 100 */
Serial.print("Pressure (mb): ");
Serial.println(Pressure / 100);
/* Calculate the absolute height above sea level using the current pressure at sea
* level */
Altitude = HCBMP180.Altitude(Pressure, PRESSURE_AT_SEA_LEVEL);
/* Output the calculated height to the serial port */
Serial.print("Sensor height above sea level (meters): ");
Serial.println(Altitude);
/* Calculate the pressure at sea level in Pascals */
SeaLevel = HCBMP180.SeaLevelPressure(Pressure, LOCATION_ALTITUDE);
/* Output the current pressure at sea level to the serial port. Pressure is in Pascals
* so to convert to Millibar simply divide by 100 */
Serial.print("Pressure at sea level (mb): ");
Serial.println(SeaLevel / 100);
/* Calculate any differences in altitude since the the sketch was started and output it
* to the serial port */
Serial.print("Differential altitude (meters): ");
Serial.println(Altitude - Reference_Altitude);
Serial.println();
delay(1000);
}
The HCBMP180 library can be downloaded here (please log in to download):