├── .github ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── githubci.yml ├── Adafruit_BMP085_U.cpp ├── Adafruit_BMP085_U.h ├── README.md ├── examples └── sensorapi │ └── sensorapi.pde └── library.properties /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for opening an issue on an Adafruit Arduino library repository. To 2 | improve the speed of resolution please review the following guidelines and 3 | common troubleshooting steps below before creating the issue: 4 | 5 | - **Do not use GitHub issues for troubleshooting projects and issues.** Instead use 6 | the forums at http://forums.adafruit.com to ask questions and troubleshoot why 7 | something isn't working as expected. In many cases the problem is a common issue 8 | that you will more quickly receive help from the forum community. GitHub issues 9 | are meant for known defects in the code. If you don't know if there is a defect 10 | in the code then start with troubleshooting on the forum first. 11 | 12 | - **If following a tutorial or guide be sure you didn't miss a step.** Carefully 13 | check all of the steps and commands to run have been followed. Consult the 14 | forum if you're unsure or have questions about steps in a guide/tutorial. 15 | 16 | - **For Arduino projects check these very common issues to ensure they don't apply**: 17 | 18 | - For uploading sketches or communicating with the board make sure you're using 19 | a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes 20 | very hard to tell the difference between a data and charge cable! Try using the 21 | cable with other devices or swapping to another cable to confirm it is not 22 | the problem. 23 | 24 | - **Be sure you are supplying adequate power to the board.** Check the specs of 25 | your board and plug in an external power supply. In many cases just 26 | plugging a board into your computer is not enough to power it and other 27 | peripherals. 28 | 29 | - **Double check all soldering joints and connections.** Flakey connections 30 | cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints. 31 | 32 | - **Ensure you are using an official Arduino or Adafruit board.** We can't 33 | guarantee a clone board will have the same functionality and work as expected 34 | with this code and don't support them. 35 | 36 | If you're sure this issue is a defect in the code and checked the steps above 37 | please fill in the following fields to provide enough troubleshooting information. 38 | You may delete the guideline and text above to just leave the following details: 39 | 40 | - Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE** 41 | 42 | - Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO 43 | VERSION HERE** 44 | 45 | - List the steps to reproduce the problem below (if possible attach a sketch or 46 | copy the sketch code in too): **LIST REPRO STEPS BELOW** 47 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for creating a pull request to contribute to Adafruit's GitHub code! 2 | Before you open the request please review the following guidelines and tips to 3 | help it be more easily integrated: 4 | 5 | - **Describe the scope of your change--i.e. what the change does and what parts 6 | of the code were modified.** This will help us understand any risks of integrating 7 | the code. 8 | 9 | - **Describe any known limitations with your change.** For example if the change 10 | doesn't apply to a supported platform of the library please mention it. 11 | 12 | - **Please run any tests or examples that can exercise your modified code.** We 13 | strive to not break users of the code and running tests/examples helps with this 14 | process. 15 | 16 | Thank you again for contributing! We will try to test and integrate the change 17 | as soon as we can, but be aware we have many GitHub repositories to manage and 18 | can't immediately respond to every request. There is no need to bump or check in 19 | on a pull request (it will clutter the discussion of the request). 20 | 21 | Also don't be worried if the request is closed or not integrated--sometimes the 22 | priorities of Adafruit's GitHub code (education, ease of use) might not match the 23 | priorities of the pull request. Don't fret, the open source community thrives on 24 | forks and GitHub makes it easy to keep your changes in a forked repo. 25 | 26 | After reviewing the guidelines above you can delete this text from the pull request. 27 | -------------------------------------------------------------------------------- /.github/workflows/githubci.yml: -------------------------------------------------------------------------------- 1 | name: Arduino Library CI 2 | 3 | on: [pull_request, push, repository_dispatch] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - uses: actions/setup-python@v4 11 | with: 12 | python-version: '3.x' 13 | - uses: actions/checkout@v3 14 | - uses: actions/checkout@v3 15 | with: 16 | repository: adafruit/ci-arduino 17 | path: ci 18 | 19 | - name: pre-install 20 | run: bash ci/actions_install.sh 21 | 22 | - name: test platforms 23 | run: python3 ci/build_platform.py main_platforms 24 | 25 | - name: clang 26 | run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r . 27 | 28 | - name: doxygen 29 | env: 30 | GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }} 31 | PRETTYNAME : "Adafruit BMP085 Unified" 32 | run: bash ci/doxy_gen_and_deploy.sh 33 | -------------------------------------------------------------------------------- /Adafruit_BMP085_U.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file Adafruit_BMP085_U.cpp 3 | * 4 | * @mainpage Adafruit BMP085 Pressure Sensor 5 | * 6 | * @section intro_sec Introduction 7 | * 8 | * This is a library for the BMP085 pressure sensor 9 | * 10 | * Designed specifically to work with the Adafruit BMP085 or BMP180 Breakout 11 | * ----> http://www.adafruit.com/products/391 12 | * ----> http://www.adafruit.com/products/1603 13 | * 14 | * These displays use I2C to communicate, 2 pins are required to interface. 15 | * 16 | * Adafruit invests time and resources providing this open source code, 17 | * please support Adafruit andopen-source hardware by purchasing products 18 | * from Adafruit! 19 | * 20 | * @section author Author 21 | * 22 | * Written by Kevin Townsend for Adafruit Industries. 23 | * 24 | * @section license License 25 | * BSD license, all text above must be included in any redistribution 26 | */ 27 | 28 | #if ARDUINO >= 100 29 | #include "Arduino.h" 30 | #else 31 | #include "WProgram.h" 32 | #endif 33 | 34 | #ifdef __AVR_ATtiny85__ 35 | #include "TinyWireM.h" 36 | #define Wire TinyWireM 37 | #else 38 | #include 39 | #endif 40 | 41 | #include 42 | #include 43 | 44 | #include "Adafruit_BMP085_U.h" 45 | 46 | static bmp085_calib_data 47 | _bmp085_coeffs; // Last read accelerometer data will be available here 48 | static uint8_t _bmp085Mode; 49 | 50 | #define BMP085_USE_DATASHEET_VALS \ 51 | (0) //!< Set to 1 for sanity check, when true, will use values from datasheet 52 | 53 | /*************************************************************************** 54 | PRIVATE FUNCTIONS 55 | ***************************************************************************/ 56 | 57 | /**************************************************************************/ 58 | /*! 59 | @brief Writes an 8 bit value over I2C 60 | */ 61 | /**************************************************************************/ 62 | static void writeCommand(byte reg, byte value) { 63 | Wire.beginTransmission((uint8_t)BMP085_ADDRESS); 64 | #if ARDUINO >= 100 65 | Wire.write((uint8_t)reg); 66 | Wire.write((uint8_t)value); 67 | #else 68 | Wire.send(reg); 69 | Wire.send(value); 70 | #endif 71 | Wire.endTransmission(); 72 | } 73 | 74 | /**************************************************************************/ 75 | /*! 76 | @brief Reads an 8 bit value over I2C 77 | */ 78 | /**************************************************************************/ 79 | static void read8(byte reg, uint8_t *value) { 80 | Wire.beginTransmission((uint8_t)BMP085_ADDRESS); 81 | #if ARDUINO >= 100 82 | Wire.write((uint8_t)reg); 83 | #else 84 | Wire.send(reg); 85 | #endif 86 | Wire.endTransmission(); 87 | Wire.requestFrom((uint8_t)BMP085_ADDRESS, (byte)1); 88 | #if ARDUINO >= 100 89 | *value = Wire.read(); 90 | #else 91 | *value = Wire.receive(); 92 | #endif 93 | Wire.endTransmission(); 94 | } 95 | 96 | /**************************************************************************/ 97 | /*! 98 | @brief Reads a 16 bit value over I2C 99 | */ 100 | /**************************************************************************/ 101 | static void read16(byte reg, uint16_t *value) { 102 | Wire.beginTransmission((uint8_t)BMP085_ADDRESS); 103 | #if ARDUINO >= 100 104 | Wire.write((uint8_t)reg); 105 | #else 106 | Wire.send(reg); 107 | #endif 108 | Wire.endTransmission(); 109 | Wire.requestFrom((uint8_t)BMP085_ADDRESS, (byte)2); 110 | #if ARDUINO >= 100 111 | *value = (Wire.read() << 8) | Wire.read(); 112 | #else 113 | *value = (Wire.receive() << 8) | Wire.receive(); 114 | #endif 115 | Wire.endTransmission(); 116 | } 117 | 118 | /**************************************************************************/ 119 | /*! 120 | @brief Reads a signed 16 bit value over I2C 121 | */ 122 | /**************************************************************************/ 123 | static void readS16(byte reg, int16_t *value) { 124 | uint16_t i; 125 | read16(reg, &i); 126 | *value = (int16_t)i; 127 | } 128 | 129 | /**************************************************************************/ 130 | /*! 131 | @brief Reads the factory-set coefficients 132 | */ 133 | /**************************************************************************/ 134 | static void readCoefficients(void) { 135 | #if BMP085_USE_DATASHEET_VALS 136 | _bmp085_coeffs.ac1 = 408; 137 | _bmp085_coeffs.ac2 = -72; 138 | _bmp085_coeffs.ac3 = -14383; 139 | _bmp085_coeffs.ac4 = 32741; 140 | _bmp085_coeffs.ac5 = 32757; 141 | _bmp085_coeffs.ac6 = 23153; 142 | _bmp085_coeffs.b1 = 6190; 143 | _bmp085_coeffs.b2 = 4; 144 | _bmp085_coeffs.mb = -32768; 145 | _bmp085_coeffs.mc = -8711; 146 | _bmp085_coeffs.md = 2868; 147 | _bmp085Mode = 0; 148 | #else 149 | readS16(BMP085_REGISTER_CAL_AC1, &_bmp085_coeffs.ac1); 150 | readS16(BMP085_REGISTER_CAL_AC2, &_bmp085_coeffs.ac2); 151 | readS16(BMP085_REGISTER_CAL_AC3, &_bmp085_coeffs.ac3); 152 | read16(BMP085_REGISTER_CAL_AC4, &_bmp085_coeffs.ac4); 153 | read16(BMP085_REGISTER_CAL_AC5, &_bmp085_coeffs.ac5); 154 | read16(BMP085_REGISTER_CAL_AC6, &_bmp085_coeffs.ac6); 155 | readS16(BMP085_REGISTER_CAL_B1, &_bmp085_coeffs.b1); 156 | readS16(BMP085_REGISTER_CAL_B2, &_bmp085_coeffs.b2); 157 | readS16(BMP085_REGISTER_CAL_MB, &_bmp085_coeffs.mb); 158 | readS16(BMP085_REGISTER_CAL_MC, &_bmp085_coeffs.mc); 159 | readS16(BMP085_REGISTER_CAL_MD, &_bmp085_coeffs.md); 160 | #endif 161 | } 162 | 163 | /**************************************************************************/ 164 | /*! 165 | 166 | */ 167 | /**************************************************************************/ 168 | static void readRawTemperature(int32_t *temperature) { 169 | #if BMP085_USE_DATASHEET_VALS 170 | *temperature = 27898; 171 | #else 172 | uint16_t t; 173 | writeCommand(BMP085_REGISTER_CONTROL, BMP085_REGISTER_READTEMPCMD); 174 | delay(5); 175 | read16(BMP085_REGISTER_TEMPDATA, &t); 176 | *temperature = t; 177 | #endif 178 | } 179 | 180 | /**************************************************************************/ 181 | /*! 182 | 183 | */ 184 | /**************************************************************************/ 185 | static void readRawPressure(int32_t *pressure) { 186 | #if BMP085_USE_DATASHEET_VALS 187 | *pressure = 23843; 188 | #else 189 | uint8_t p8; 190 | uint16_t p16; 191 | int32_t p32; 192 | 193 | writeCommand(BMP085_REGISTER_CONTROL, 194 | BMP085_REGISTER_READPRESSURECMD + (_bmp085Mode << 6)); 195 | switch (_bmp085Mode) { 196 | case BMP085_MODE_ULTRALOWPOWER: 197 | delay(5); 198 | break; 199 | case BMP085_MODE_STANDARD: 200 | delay(8); 201 | break; 202 | case BMP085_MODE_HIGHRES: 203 | delay(14); 204 | break; 205 | case BMP085_MODE_ULTRAHIGHRES: 206 | default: 207 | delay(26); 208 | break; 209 | } 210 | 211 | read16(BMP085_REGISTER_PRESSUREDATA, &p16); 212 | p32 = (uint32_t)p16 << 8; 213 | read8(BMP085_REGISTER_PRESSUREDATA + 2, &p8); 214 | p32 += p8; 215 | p32 >>= (8 - _bmp085Mode); 216 | 217 | *pressure = p32; 218 | #endif 219 | } 220 | 221 | /**************************************************************************/ 222 | /*! 223 | @brief Compute B5 coefficient used in temperature & pressure calcs. 224 | */ 225 | /**************************************************************************/ 226 | int32_t Adafruit_BMP085_Unified::computeB5(int32_t ut) { 227 | int32_t X1 = 228 | (ut - (int32_t)_bmp085_coeffs.ac6) * ((int32_t)_bmp085_coeffs.ac5) >> 15; 229 | int32_t X2 = 230 | ((int32_t)_bmp085_coeffs.mc << 11) / (X1 + (int32_t)_bmp085_coeffs.md); 231 | return X1 + X2; 232 | } 233 | 234 | /*************************************************************************** 235 | CONSTRUCTOR 236 | ***************************************************************************/ 237 | 238 | /**************************************************************************/ 239 | /*! 240 | @brief Instantiates a new Adafruit_BMP085_Unified class 241 | */ 242 | /**************************************************************************/ 243 | Adafruit_BMP085_Unified::Adafruit_BMP085_Unified(int32_t sensorID) { 244 | _sensorID = sensorID; 245 | } 246 | 247 | /*************************************************************************** 248 | PUBLIC FUNCTIONS 249 | ***************************************************************************/ 250 | 251 | /**************************************************************************/ 252 | /*! 253 | @brief Setups the HW 254 | */ 255 | /**************************************************************************/ 256 | bool Adafruit_BMP085_Unified::begin(bmp085_mode_t mode) { 257 | // Enable I2C 258 | Wire.begin(); 259 | 260 | /* Mode boundary check */ 261 | if ((mode > BMP085_MODE_ULTRAHIGHRES) || (mode < 0)) { 262 | mode = BMP085_MODE_ULTRAHIGHRES; 263 | } 264 | 265 | /* Make sure we have the right device */ 266 | uint8_t id; 267 | read8(BMP085_REGISTER_CHIPID, &id); 268 | if (id != 0x55) { 269 | return false; 270 | } 271 | 272 | /* Set the mode indicator */ 273 | _bmp085Mode = mode; 274 | 275 | /* Coefficients need to be read once */ 276 | readCoefficients(); 277 | 278 | return true; 279 | } 280 | 281 | /**************************************************************************/ 282 | /*! 283 | @brief Gets the compensated pressure level in kPa 284 | */ 285 | /**************************************************************************/ 286 | void Adafruit_BMP085_Unified::getPressure(float *pressure) { 287 | int32_t ut = 0, up = 0, compp = 0; 288 | int32_t x1, x2, b5, b6, x3, b3, p; 289 | uint32_t b4, b7; 290 | 291 | /* Get the raw pressure and temperature values */ 292 | readRawTemperature(&ut); 293 | readRawPressure(&up); 294 | 295 | /* Temperature compensation */ 296 | b5 = computeB5(ut); 297 | 298 | /* Pressure compensation */ 299 | b6 = b5 - 4000; 300 | x1 = (_bmp085_coeffs.b2 * ((b6 * b6) >> 12)) >> 11; 301 | x2 = (_bmp085_coeffs.ac2 * b6) >> 11; 302 | x3 = x1 + x2; 303 | b3 = (((((int32_t)_bmp085_coeffs.ac1) * 4 + x3) << _bmp085Mode) + 2) >> 2; 304 | x1 = (_bmp085_coeffs.ac3 * b6) >> 13; 305 | x2 = (_bmp085_coeffs.b1 * ((b6 * b6) >> 12)) >> 16; 306 | x3 = ((x1 + x2) + 2) >> 2; 307 | b4 = (_bmp085_coeffs.ac4 * (uint32_t)(x3 + 32768)) >> 15; 308 | b7 = ((uint32_t)(up - b3) * (50000 >> _bmp085Mode)); 309 | 310 | if (b7 < 0x80000000) { 311 | p = (b7 << 1) / b4; 312 | } else { 313 | p = (b7 / b4) << 1; 314 | } 315 | 316 | x1 = (p >> 8) * (p >> 8); 317 | x1 = (x1 * 3038) >> 16; 318 | x2 = (-7357 * p) >> 16; 319 | compp = p + ((x1 + x2 + 3791) >> 4); 320 | 321 | /* Assign compensated pressure value */ 322 | *pressure = compp; 323 | } 324 | 325 | /**************************************************************************/ 326 | /*! 327 | @brief Reads the temperatures in degrees Celsius 328 | */ 329 | /**************************************************************************/ 330 | void Adafruit_BMP085_Unified::getTemperature(float *temp) { 331 | int32_t UT, B5; // following ds convention 332 | float t; 333 | 334 | readRawTemperature(&UT); 335 | 336 | #if BMP085_USE_DATASHEET_VALS 337 | // use datasheet numbers! 338 | UT = 27898; 339 | _bmp085_coeffs.ac6 = 23153; 340 | _bmp085_coeffs.ac5 = 32757; 341 | _bmp085_coeffs.mc = -8711; 342 | _bmp085_coeffs.md = 2868; 343 | #endif 344 | 345 | B5 = computeB5(UT); 346 | t = (B5 + 8) >> 4; 347 | t /= 10; 348 | 349 | *temp = t; 350 | } 351 | 352 | /**************************************************************************/ 353 | /*! 354 | Calculates the altitude (in meters) from the specified atmospheric 355 | pressure (in hPa), and sea-level pressure (in hPa). 356 | 357 | @param seaLevel Sea-level pressure in hPa 358 | @param atmospheric Atmospheric pressure in hPa 359 | */ 360 | /**************************************************************************/ 361 | float Adafruit_BMP085_Unified::pressureToAltitude(float seaLevel, 362 | float atmospheric) { 363 | // Equation taken from BMP180 datasheet (page 16): 364 | // http://www.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf 365 | 366 | // Note that using the equation from wikipedia can give bad results 367 | // at high altitude. See this thread for more information: 368 | // http://forums.adafruit.com/viewtopic.php?f=22&t=58064 369 | 370 | return 44330.0 * (1.0 - pow(atmospheric / seaLevel, 0.1903)); 371 | } 372 | 373 | /**************************************************************************/ 374 | /*! 375 | Calculates the altitude (in meters) from the specified atmospheric 376 | pressure (in hPa), and sea-level pressure (in hPa). Note that this 377 | function just calls the overload of pressureToAltitude which takes 378 | seaLevel and atmospheric pressure--temperature is ignored. The original 379 | implementation of this function was based on calculations from Wikipedia 380 | which are not accurate at higher altitudes. To keep compatibility with 381 | old code this function remains with the same interface, but it calls the 382 | more accurate calculation. 383 | 384 | @param seaLevel Sea-level pressure in hPa 385 | @param atmospheric Atmospheric pressure in hPa 386 | @param temp Temperature in degrees Celsius 387 | */ 388 | /**************************************************************************/ 389 | float Adafruit_BMP085_Unified::pressureToAltitude(float seaLevel, 390 | float atmospheric, 391 | float temp) { 392 | return pressureToAltitude(seaLevel, atmospheric); 393 | } 394 | 395 | /**************************************************************************/ 396 | /*! 397 | Calculates the pressure at sea level (in hPa) from the specified altitude 398 | (in meters), and atmospheric pressure (in hPa). 399 | 400 | @param altitude Altitude in meters 401 | @param atmospheric Atmospheric pressure in hPa 402 | */ 403 | /**************************************************************************/ 404 | float Adafruit_BMP085_Unified::seaLevelForAltitude(float altitude, 405 | float atmospheric) { 406 | // Equation taken from BMP180 datasheet (page 17): 407 | // http://www.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf 408 | 409 | // Note that using the equation from wikipedia can give bad results 410 | // at high altitude. See this thread for more information: 411 | // http://forums.adafruit.com/viewtopic.php?f=22&t=58064 412 | 413 | return atmospheric / pow(1.0 - (altitude / 44330.0), 5.255); 414 | } 415 | 416 | /**************************************************************************/ 417 | /*! 418 | Calculates the pressure at sea level (in hPa) from the specified altitude 419 | (in meters), and atmospheric pressure (in hPa). Note that this 420 | function just calls the overload of seaLevelForAltitude which takes 421 | altitude and atmospheric pressure--temperature is ignored. The original 422 | implementation of this function was based on calculations from Wikipedia 423 | which are not accurate at higher altitudes. To keep compatibility with 424 | old code this function remains with the same interface, but it calls the 425 | more accurate calculation. 426 | 427 | @param altitude Altitude in meters 428 | @param atmospheric Atmospheric pressure in hPa 429 | @param temp Temperature in degrees Celsius 430 | */ 431 | /**************************************************************************/ 432 | float Adafruit_BMP085_Unified::seaLevelForAltitude(float altitude, 433 | float atmospheric, 434 | float temp) { 435 | return seaLevelForAltitude(altitude, atmospheric); 436 | } 437 | 438 | /**************************************************************************/ 439 | /*! 440 | @brief Provides the sensor_t data for this sensor 441 | */ 442 | /**************************************************************************/ 443 | void Adafruit_BMP085_Unified::getSensor(sensor_t *sensor) { 444 | /* Clear the sensor_t object */ 445 | memset(sensor, 0, sizeof(sensor_t)); 446 | 447 | /* Insert the sensor name in the fixed length char array */ 448 | strncpy(sensor->name, "BMP085", sizeof(sensor->name) - 1); 449 | sensor->name[sizeof(sensor->name) - 1] = 0; 450 | sensor->version = 1; 451 | sensor->sensor_id = _sensorID; 452 | sensor->type = SENSOR_TYPE_PRESSURE; 453 | sensor->min_delay = 0; 454 | sensor->max_value = 1100.0F; // 300..1100 hPa 455 | sensor->min_value = 300.0F; 456 | sensor->resolution = 0.01F; // Datasheet states 0.01 hPa resolution 457 | } 458 | 459 | /**************************************************************************/ 460 | /*! 461 | @brief Reads the sensor and returns the data as a sensors_event_t 462 | */ 463 | /**************************************************************************/ 464 | bool Adafruit_BMP085_Unified::getEvent(sensors_event_t *event) { 465 | float pressure_kPa; 466 | 467 | /* Clear the event */ 468 | memset(event, 0, sizeof(sensors_event_t)); 469 | 470 | event->version = sizeof(sensors_event_t); 471 | event->sensor_id = _sensorID; 472 | event->type = SENSOR_TYPE_PRESSURE; 473 | event->timestamp = 0; 474 | getPressure(&pressure_kPa); 475 | event->pressure = pressure_kPa / 100.0F; 476 | 477 | return true; 478 | } 479 | -------------------------------------------------------------------------------- /Adafruit_BMP085_U.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file Adafruit_BMP085_U.h 3 | */ 4 | 5 | #ifndef __BMP085_H__ 6 | #define __BMP085_H__ 7 | 8 | #if (ARDUINO >= 100) 9 | #include "Arduino.h" 10 | #else 11 | #include "WProgram.h" 12 | #endif 13 | 14 | #include 15 | 16 | #ifdef __AVR_ATtiny85__ 17 | #include "TinyWireM.h" 18 | #define Wire TinyWireM 19 | #else 20 | #include 21 | #endif 22 | 23 | /*! 24 | * @brief BMP085 I2C address/bits 25 | */ 26 | #define BMP085_ADDRESS (0x77) 27 | 28 | /*! 29 | * @brief BMP085 I2C registers 30 | */ 31 | enum { 32 | BMP085_REGISTER_CAL_AC1 = 0xAA, //!< R Calibration data (16 bits) 33 | BMP085_REGISTER_CAL_AC2 = 0xAC, //!< R Calibration data (16 bits) 34 | BMP085_REGISTER_CAL_AC3 = 0xAE, //!< R Calibration data (16 bits) 35 | BMP085_REGISTER_CAL_AC4 = 0xB0, //!< R Calibration data (16 bits) 36 | BMP085_REGISTER_CAL_AC5 = 0xB2, //!< R Calibration data (16 bits) 37 | BMP085_REGISTER_CAL_AC6 = 0xB4, //!< R Calibration data (16 bits) 38 | BMP085_REGISTER_CAL_B1 = 0xB6, //!< R Calibration data (16 bits) 39 | BMP085_REGISTER_CAL_B2 = 0xB8, //!< R Calibration data (16 bits) 40 | BMP085_REGISTER_CAL_MB = 0xBA, //!< R Calibration data (16 bits) 41 | BMP085_REGISTER_CAL_MC = 0xBC, //!< R Calibration data (16 bits) 42 | BMP085_REGISTER_CAL_MD = 0xBE, //!< R Calibration data (16 bits) 43 | BMP085_REGISTER_CHIPID = 0xD0, //!< Register that contains the chip ID 44 | BMP085_REGISTER_VERSION = 0xD1, //!< Register that contains the chip version 45 | BMP085_REGISTER_SOFTRESET = 0xE0, //!< Register for doing a soft reset 46 | BMP085_REGISTER_CONTROL = 0xF4, //!< Control register 47 | BMP085_REGISTER_TEMPDATA = 0xF6, //!< Temperature data register 48 | BMP085_REGISTER_PRESSUREDATA = 0xF6, //!< Pressure data register 49 | BMP085_REGISTER_READTEMPCMD = 50 | 0x2E, //!< Read temperature control register value 51 | BMP085_REGISTER_READPRESSURECMD = 52 | 0x34 //!< Read pressure control register value 53 | }; 54 | 55 | /*! 56 | * @brief BMP085 mode settings 57 | */ 58 | typedef enum { 59 | BMP085_MODE_ULTRALOWPOWER = 0, 60 | BMP085_MODE_STANDARD = 1, 61 | BMP085_MODE_HIGHRES = 2, 62 | BMP085_MODE_ULTRAHIGHRES = 3 63 | } bmp085_mode_t; 64 | /*=========================================================================*/ 65 | 66 | /*! 67 | * @brief Calibration data 68 | */ 69 | typedef struct { 70 | int16_t ac1; //!< R calibration coefficient (16-bits) 71 | int16_t ac2; //!< R calibration coefficient (16-bits) 72 | int16_t ac3; //!< R calibration coefficient (16-bits) 73 | uint16_t ac4; //!< R calibration coefficient (16-bits) 74 | uint16_t ac5; //!< R calibration coefficient (16-bits) 75 | uint16_t ac6; //!< R calibration coefficient (16-bits) 76 | int16_t b1; //!< R calibration coefficient (16-bits) 77 | int16_t b2; //!< R calibration coefficient (16-bits) 78 | int16_t mb; //!< R calibration coefficient (16-bits) 79 | int16_t mc; //!< R calibration coefficient (16-bits) 80 | int16_t md; //!< R calibration coefficient (16-bits) 81 | } bmp085_calib_data; 82 | 83 | /*! 84 | * @brief Class that stores state and functions for interacting with BMP183 85 | */ 86 | class Adafruit_BMP085_Unified : public Adafruit_Sensor { 87 | public: 88 | Adafruit_BMP085_Unified( 89 | int32_t sensorID = -1); //!< @param sensorID ID of the BMP085 sensor 90 | 91 | /*! 92 | * @brief Starts I2C connection 93 | * @param mode Mode to set, ultra high-res by default 94 | * @return Returns true if successful 95 | */ 96 | bool begin(bmp085_mode_t mode = BMP085_MODE_ULTRAHIGHRES); 97 | /*! 98 | * @brief Gets the temperature over I2C from the BMP085 99 | * @param temp Temperature 100 | * @return Returns the temperature 101 | */ 102 | void getTemperature(float *temp); 103 | /*! 104 | * @brief Gets the pressure over I2C from the BMP085 105 | * @param pressure Pressure 106 | * @return Returns the pressure 107 | */ 108 | void getPressure(float *pressure); 109 | /*! 110 | * @brief Calculates absolute pressure 111 | * @param seaLevel Pressure at sea level 112 | * @param atmospheric measured pressure 113 | * @return Absolute altitude 114 | */ 115 | float pressureToAltitude(float seaLevel, float atmospheric); 116 | /*! 117 | * @brief Calculates pressure at sea level 118 | * @param altitude Altitude 119 | * @param atmospheric measured pressure 120 | * @return Pressure at sea level 121 | */ 122 | float seaLevelForAltitude(float altitude, float atmospheric); 123 | // Note that the next two functions are just for compatibility with old 124 | // code that passed the temperature as a third parameter. A newer 125 | // calculation is used which does not need temperature. 126 | /*! 127 | * @brief Calculates absolute pressure 128 | * @param seaLevel Pressure at sea level 129 | * @param atmospheric Measured pressure 130 | * @param temp Temperature 131 | * @return Absolute altitude 132 | */ 133 | float pressureToAltitude(float seaLevel, float atmospheric, float temp); 134 | /*! 135 | * @brief Calculates pressure at sea level 136 | * @param altitude Altitude 137 | * @param atmospheric measured pressure 138 | * @param temp Temperature 139 | * @return Pressure at sea level 140 | */ 141 | float seaLevelForAltitude(float altitude, float atmospheric, float temp); 142 | /*! 143 | * @brief Used to read the sensor 144 | * @return Returns an event 145 | */ 146 | bool getEvent(sensors_event_t *); 147 | void getSensor(sensor_t *); 148 | 149 | private: 150 | int32_t computeB5(int32_t ut); 151 | int32_t _sensorID; 152 | }; 153 | 154 | #endif 155 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Adafruit Unified BMP085/BMP180 Driver (Barometric Pressure Sensor) [![Build Status](https://github.com/adafruit/Adafruit_BMP085_Unified/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit_BMP085_Unified/actions)[![Documentation](https://github.com/adafruit/ci-arduino/blob/master/assets/doxygen_badge.svg)](http://adafruit.github.io/Adafruit_BMP085_Unified/html/index.html) 2 | 3 | This driver is for the Adafruit BMP085 Breakout (http://www.adafruit.com/products/391) or BMP180 breakout (http://www.adafruit.com/products/1603), and is based on Adafruit's Unified Sensor Library (Adafruit_Sensor). 4 | 5 | ## About the BMP085 / BMP180 ## 6 | 7 | This precision sensor from Bosch is the best low-cost sensing solution for measuring barometric pressure and temperature. Because pressure changes with altitude you can also use it as an altimeter! 8 | 9 | ## What is the Adafruit Unified Sensor Library? ## 10 | 11 | The Adafruit Unified Sensor Library ([Adafruit_Sensor](https://github.com/adafruit/Adafruit_Sensor)) provides a common interface and data type for any supported sensor. It defines some basic information about the sensor (sensor limits, etc.), and returns standard SI units of a specific type and scale for each supported sensor type. 12 | 13 | It provides a simple abstraction layer between your application and the actual sensor HW, allowing you to drop in any comparable sensor with only one or two lines of code to change in your project (essentially the constructor since the functions to read sensor data and get information about the sensor are defined in the base Adafruit_Sensor class). 14 | 15 | This is imporant useful for two reasons: 16 | 17 | 1.) You can use the data right away because it's already converted to SI units that you understand and can compare, rather than meaningless values like 0..1023. 18 | 19 | 2.) Because SI units are standardised in the sensor library, you can also do quick sanity checks when working with new sensors, or drop in any comparable sensor if you need better sensitivity or if a lower cost unit becomes available, etc. 20 | 21 | Light sensors will always report units in lux, gyroscopes will always report units in rad/s, etc. ... freeing you up to focus on the data, rather than digging through the datasheet to understand what the sensor's raw numbers really mean. 22 | 23 | ## About this Driver ## 24 | 25 | Adafruit invests time and resources providing this open source code. Please support Adafruit and open-source hardware by purchasing products from Adafruit! 26 | 27 | Written by Kevin (KTOWN) Townsend for Adafruit Industries. 28 | -------------------------------------------------------------------------------- /examples/sensorapi/sensorapi.pde: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /* This driver uses the Adafruit unified sensor library (Adafruit_Sensor), 6 | which provides a common 'type' for sensor data and some helper functions. 7 | 8 | To use this driver you will also need to download the Adafruit_Sensor 9 | library and include it in your libraries folder. 10 | 11 | You should also assign a unique ID to this sensor for use with 12 | the Adafruit Sensor API so that you can identify this particular 13 | sensor in any data logs, etc. To assign a unique ID, simply 14 | provide an appropriate value in the constructor below (12345 15 | is used by default in this example). 16 | 17 | Connections 18 | =========== 19 | Connect SCL to analog 5 20 | Connect SDA to analog 4 21 | Connect VDD to 3.3V DC 22 | Connect GROUND to common ground 23 | 24 | History 25 | ======= 26 | 2013/JUN/17 - Updated altitude calculations (KTOWN) 27 | 2013/FEB/13 - First version (KTOWN) 28 | */ 29 | 30 | Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085); 31 | 32 | /**************************************************************************/ 33 | /* 34 | Displays some basic information on this sensor from the unified 35 | sensor API sensor_t type (see Adafruit_Sensor for more information) 36 | */ 37 | /**************************************************************************/ 38 | void displaySensorDetails(void) 39 | { 40 | sensor_t sensor; 41 | bmp.getSensor(&sensor); 42 | Serial.println("------------------------------------"); 43 | Serial.print ("Sensor: "); Serial.println(sensor.name); 44 | Serial.print ("Driver Ver: "); Serial.println(sensor.version); 45 | Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id); 46 | Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" hPa"); 47 | Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" hPa"); 48 | Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" hPa"); 49 | Serial.println("------------------------------------"); 50 | Serial.println(""); 51 | delay(500); 52 | } 53 | 54 | /**************************************************************************/ 55 | /* 56 | Arduino setup function (automatically called at startup) 57 | */ 58 | /**************************************************************************/ 59 | void setup(void) 60 | { 61 | Serial.begin(9600); 62 | Serial.println("Pressure Sensor Test"); Serial.println(""); 63 | 64 | /* Initialise the sensor */ 65 | if(!bmp.begin()) 66 | { 67 | /* There was a problem detecting the BMP085 ... check your connections */ 68 | Serial.print("Ooops, no BMP085 detected ... Check your wiring or I2C ADDR!"); 69 | while(1); 70 | } 71 | 72 | /* Display some basic information on this sensor */ 73 | displaySensorDetails(); 74 | } 75 | 76 | /**************************************************************************/ 77 | /* 78 | Arduino loop function, called once 'setup' is complete (your own code 79 | should go here) 80 | */ 81 | /**************************************************************************/ 82 | void loop(void) 83 | { 84 | /* Get a new sensor event */ 85 | sensors_event_t event; 86 | bmp.getEvent(&event); 87 | 88 | /* Display the results (barometric pressure is measure in hPa) */ 89 | if (event.pressure) 90 | { 91 | /* Display atmospheric pressue in hPa */ 92 | Serial.print("Pressure: "); 93 | Serial.print(event.pressure); 94 | Serial.println(" hPa"); 95 | 96 | /* Calculating altitude with reasonable accuracy requires pressure * 97 | * sea level pressure for your position at the moment the data is * 98 | * converted, as well as the ambient temperature in degress * 99 | * celcius. If you don't have these values, a 'generic' value of * 100 | * 1013.25 hPa can be used (defined as SENSORS_PRESSURE_SEALEVELHPA * 101 | * in sensors.h), but this isn't ideal and will give variable * 102 | * results from one day to the next. * 103 | * * 104 | * You can usually find the current SLP value by looking at weather * 105 | * websites or from environmental information centers near any major * 106 | * airport. * 107 | * * 108 | * For example, for Paris, France you can check the current mean * 109 | * pressure and sea level at: http://bit.ly/16Au8ol */ 110 | 111 | /* First we get the current temperature from the BMP085 */ 112 | float temperature; 113 | bmp.getTemperature(&temperature); 114 | Serial.print("Temperature: "); 115 | Serial.print(temperature); 116 | Serial.println(" C"); 117 | 118 | /* Then convert the atmospheric pressure, and SLP to altitude */ 119 | /* Update this next line with the current SLP for better results */ 120 | float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA; 121 | Serial.print("Altitude: "); 122 | Serial.print(bmp.pressureToAltitude(seaLevelPressure, 123 | event.pressure)); 124 | Serial.println(" m"); 125 | Serial.println(""); 126 | } 127 | else 128 | { 129 | Serial.println("Sensor error"); 130 | } 131 | delay(1000); 132 | } 133 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Adafruit BMP085 Unified 2 | version=1.1.3 3 | author=Adafruit 4 | maintainer=Adafruit 5 | sentence=Unified sensor driver for Adafruit's BMP085 & BMP180 breakouts 6 | paragraph=Unified sensor driver for Adafruit's BMP085 & BMP180 breakouts 7 | category=Sensors 8 | url=https://github.com/adafruit/Adafruit_BMP085_Unified 9 | architectures=* 10 | depends=Adafruit Unified Sensor 11 | --------------------------------------------------------------------------------