Repository: adafruit/Adafruit-BMP085-Library Branch: master Commit: 9d5057fb3e41 Files: 8 Total size: 19.4 KB Directory structure: gitextract_3hyzaojt/ ├── .github/ │ ├── ISSUE_TEMPLATE.md │ ├── PULL_REQUEST_TEMPLATE.md │ └── workflows/ │ └── githubci.yml ├── Adafruit_BMP085.cpp ├── Adafruit_BMP085.h ├── README.md ├── examples/ │ └── BMP085test/ │ └── BMP085test.ino └── library.properties ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/ISSUE_TEMPLATE.md ================================================ Thank you for opening an issue on an Adafruit Arduino library repository. To improve the speed of resolution please review the following guidelines and common troubleshooting steps below before creating the issue: - **Do not use GitHub issues for troubleshooting projects and issues.** Instead use the forums at http://forums.adafruit.com to ask questions and troubleshoot why something isn't working as expected. In many cases the problem is a common issue that you will more quickly receive help from the forum community. GitHub issues are meant for known defects in the code. If you don't know if there is a defect in the code then start with troubleshooting on the forum first. - **If following a tutorial or guide be sure you didn't miss a step.** Carefully check all of the steps and commands to run have been followed. Consult the forum if you're unsure or have questions about steps in a guide/tutorial. - **For Arduino projects check these very common issues to ensure they don't apply**: - For uploading sketches or communicating with the board make sure you're using a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes very hard to tell the difference between a data and charge cable! Try using the cable with other devices or swapping to another cable to confirm it is not the problem. - **Be sure you are supplying adequate power to the board.** Check the specs of your board and plug in an external power supply. In many cases just plugging a board into your computer is not enough to power it and other peripherals. - **Double check all soldering joints and connections.** Flakey connections 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. - **Ensure you are using an official Arduino or Adafruit board.** We can't guarantee a clone board will have the same functionality and work as expected with this code and don't support them. If you're sure this issue is a defect in the code and checked the steps above please fill in the following fields to provide enough troubleshooting information. You may delete the guideline and text above to just leave the following details: - Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE** - Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO VERSION HERE** - List the steps to reproduce the problem below (if possible attach a sketch or copy the sketch code in too): **LIST REPRO STEPS BELOW** ================================================ FILE: .github/PULL_REQUEST_TEMPLATE.md ================================================ Thank you for creating a pull request to contribute to Adafruit's GitHub code! Before you open the request please review the following guidelines and tips to help it be more easily integrated: - **Describe the scope of your change--i.e. what the change does and what parts of the code were modified.** This will help us understand any risks of integrating the code. - **Describe any known limitations with your change.** For example if the change doesn't apply to a supported platform of the library please mention it. - **Please run any tests or examples that can exercise your modified code.** We strive to not break users of the code and running tests/examples helps with this process. Thank you again for contributing! We will try to test and integrate the change as soon as we can, but be aware we have many GitHub repositories to manage and can't immediately respond to every request. There is no need to bump or check in on a pull request (it will clutter the discussion of the request). Also don't be worried if the request is closed or not integrated--sometimes the priorities of Adafruit's GitHub code (education, ease of use) might not match the priorities of the pull request. Don't fret, the open source community thrives on forks and GitHub makes it easy to keep your changes in a forked repo. After reviewing the guidelines above you can delete this text from the pull request. ================================================ FILE: .github/workflows/githubci.yml ================================================ name: Arduino Library CI on: [pull_request, push, repository_dispatch] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/setup-python@v4 with: python-version: '3.x' - uses: actions/checkout@v3 - uses: actions/checkout@v3 with: repository: adafruit/ci-arduino path: ci - name: pre-install run: bash ci/actions_install.sh - name: test platforms run: python3 ci/build_platform.py main_platforms - name: clang run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r . - name: doxygen env: GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }} PRETTYNAME : "Adafruit BMP085 Library" run: bash ci/doxy_gen_and_deploy.sh ================================================ FILE: Adafruit_BMP085.cpp ================================================ /*! * @file Adafruit_BMP085.cpp * * @mainpage Adafruit BMP085 Library * * @section intro_sec Introduction * * This is a library for the Adafruit BMP085/BMP180 Barometric Pressure + Temp * sensor * * Designed specifically to work with the Adafruit BMP085 or BMP180 Breakout * ----> http://www.adafruit.com/products/391 * ----> http://www.adafruit.com/products/1603 * * These displays use I2C to communicate, 2 pins are required to * interface * Adafruit invests time and resources providing this open source code, * please support Adafruit and open-source hardware by purchasing * products from Adafruit! * * @section author Author * * Written by Limor Fried/Ladyada for Adafruit Industries. * Updated by Samy Kamkar for cross-platform support. * * @section license License * * BSD license, all text above must be included in any redistribution */ #include "Adafruit_BMP085.h" #include Adafruit_BMP085::Adafruit_BMP085() { i2c_dev = nullptr; } bool Adafruit_BMP085::begin(uint8_t mode, TwoWire *wire) { if (mode > BMP085_ULTRAHIGHRES) mode = BMP085_ULTRAHIGHRES; oversampling = mode; if (i2c_dev) { delete i2c_dev; // remove old interface } i2c_dev = new Adafruit_I2CDevice(BMP085_I2CADDR, wire); if (!i2c_dev->begin()) { return false; } if (read8(0xD0) != 0x55) return false; /* read calibration data */ ac1 = read16(BMP085_CAL_AC1); ac2 = read16(BMP085_CAL_AC2); ac3 = read16(BMP085_CAL_AC3); ac4 = read16(BMP085_CAL_AC4); ac5 = read16(BMP085_CAL_AC5); ac6 = read16(BMP085_CAL_AC6); b1 = read16(BMP085_CAL_B1); b2 = read16(BMP085_CAL_B2); mb = read16(BMP085_CAL_MB); mc = read16(BMP085_CAL_MC); md = read16(BMP085_CAL_MD); #if (BMP085_DEBUG == 1) Serial.print("ac1 = "); Serial.println(ac1, DEC); Serial.print("ac2 = "); Serial.println(ac2, DEC); Serial.print("ac3 = "); Serial.println(ac3, DEC); Serial.print("ac4 = "); Serial.println(ac4, DEC); Serial.print("ac5 = "); Serial.println(ac5, DEC); Serial.print("ac6 = "); Serial.println(ac6, DEC); Serial.print("b1 = "); Serial.println(b1, DEC); Serial.print("b2 = "); Serial.println(b2, DEC); Serial.print("mb = "); Serial.println(mb, DEC); Serial.print("mc = "); Serial.println(mc, DEC); Serial.print("md = "); Serial.println(md, DEC); #endif return true; } int32_t Adafruit_BMP085::computeB5(int32_t UT) { int32_t X1 = (UT - (int32_t)ac6) * ((int32_t)ac5) >> 15; int32_t X2 = ((int32_t)mc << 11) / (X1 + (int32_t)md); return X1 + X2; } uint16_t Adafruit_BMP085::readRawTemperature(void) { write8(BMP085_CONTROL, BMP085_READTEMPCMD); delay(5); #if BMP085_DEBUG == 1 Serial.print("Raw temp: "); Serial.println(read16(BMP085_TEMPDATA)); #endif return read16(BMP085_TEMPDATA); } uint32_t Adafruit_BMP085::readRawPressure(void) { uint32_t raw; write8(BMP085_CONTROL, BMP085_READPRESSURECMD + (oversampling << 6)); if (oversampling == BMP085_ULTRALOWPOWER) delay(5); else if (oversampling == BMP085_STANDARD) delay(8); else if (oversampling == BMP085_HIGHRES) delay(14); else delay(26); raw = read16(BMP085_PRESSUREDATA); raw <<= 8; raw |= read8(BMP085_PRESSUREDATA + 2); raw >>= (8 - oversampling); /* this pull broke stuff, look at it later? if (oversampling==0) { raw <<= 8; raw |= read8(BMP085_PRESSUREDATA+2); raw >>= (8 - oversampling); } */ #if BMP085_DEBUG == 1 Serial.print("Raw pressure: "); Serial.println(raw); #endif return raw; } int32_t Adafruit_BMP085::readPressure(void) { int32_t UT, UP, B3, B5, B6, X1, X2, X3, p; uint32_t B4, B7; UT = readRawTemperature(); UP = readRawPressure(); #if BMP085_DEBUG == 1 // use datasheet numbers! UT = 27898; UP = 23843; ac6 = 23153; ac5 = 32757; mc = -8711; md = 2868; b1 = 6190; b2 = 4; ac3 = -14383; ac2 = -72; ac1 = 408; ac4 = 32741; oversampling = 0; #endif B5 = computeB5(UT); #if BMP085_DEBUG == 1 Serial.print("X1 = "); Serial.println(X1); Serial.print("X2 = "); Serial.println(X2); Serial.print("B5 = "); Serial.println(B5); #endif // do pressure calcs B6 = B5 - 4000; X1 = ((int32_t)b2 * ((B6 * B6) >> 12)) >> 11; X2 = ((int32_t)ac2 * B6) >> 11; X3 = X1 + X2; B3 = ((((int32_t)ac1 * 4 + X3) << oversampling) + 2) / 4; #if BMP085_DEBUG == 1 Serial.print("B6 = "); Serial.println(B6); Serial.print("X1 = "); Serial.println(X1); Serial.print("X2 = "); Serial.println(X2); Serial.print("B3 = "); Serial.println(B3); #endif X1 = ((int32_t)ac3 * B6) >> 13; X2 = ((int32_t)b1 * ((B6 * B6) >> 12)) >> 16; X3 = ((X1 + X2) + 2) >> 2; B4 = ((uint32_t)ac4 * (uint32_t)(X3 + 32768)) >> 15; B7 = ((uint32_t)UP - B3) * (uint32_t)(50000UL >> oversampling); #if BMP085_DEBUG == 1 Serial.print("X1 = "); Serial.println(X1); Serial.print("X2 = "); Serial.println(X2); Serial.print("B4 = "); Serial.println(B4); Serial.print("B7 = "); Serial.println(B7); #endif if (B7 < 0x80000000) { p = (B7 * 2) / B4; } else { p = (B7 / B4) * 2; } X1 = (p >> 8) * (p >> 8); X1 = (X1 * 3038) >> 16; X2 = (-7357 * p) >> 16; #if BMP085_DEBUG == 1 Serial.print("p = "); Serial.println(p); Serial.print("X1 = "); Serial.println(X1); Serial.print("X2 = "); Serial.println(X2); #endif p = p + ((X1 + X2 + (int32_t)3791) >> 4); #if BMP085_DEBUG == 1 Serial.print("p = "); Serial.println(p); #endif return p; } int32_t Adafruit_BMP085::readSealevelPressure(float altitude_meters) { float pressure = readPressure(); return (int32_t)(pressure / pow(1.0 - altitude_meters / 44330, 5.255)); } float Adafruit_BMP085::readTemperature(void) { int32_t UT, B5; // following ds convention float temp; UT = readRawTemperature(); #if BMP085_DEBUG == 1 // use datasheet numbers! UT = 27898; ac6 = 23153; ac5 = 32757; mc = -8711; md = 2868; #endif B5 = computeB5(UT); temp = (B5 + 8) >> 4; temp /= 10; return temp; } float Adafruit_BMP085::readAltitude(float sealevelPressure) { float altitude; float pressure = readPressure(); altitude = 44330 * (1.0 - pow(pressure / sealevelPressure, 0.1903)); return altitude; } /*********************************************************************/ uint8_t Adafruit_BMP085::read8(uint8_t a) { uint8_t ret; // send 1 byte, reset i2c, read 1 byte i2c_dev->write_then_read(&a, 1, &ret, 1, true); return ret; } uint16_t Adafruit_BMP085::read16(uint8_t a) { uint8_t retbuf[2]; uint16_t ret; // send 1 byte, reset i2c, read 2 bytes // we could typecast uint16_t as uint8_t array but would need to ensure proper // endianness i2c_dev->write_then_read(&a, 1, retbuf, 2, true); // write_then_read uses uint8_t array ret = retbuf[1] | (retbuf[0] << 8); return ret; } void Adafruit_BMP085::write8(uint8_t a, uint8_t d) { // send d prefixed with a (a d [stop]) i2c_dev->write(&d, 1, true, &a, 1); } ================================================ FILE: Adafruit_BMP085.h ================================================ /*! * @file Adafruit_BMP085.h * * This is a library for the Adafruit BMP085/BMP180 Barometric Pressure + Temp * sensor * * Designed specifically to work with the Adafruit BMP085 or BMP180 Breakout * ----> http://www.adafruit.com/products/391 * ----> http://www.adafruit.com/products/1603 * * These displays use I2C to communicate, 2 pins are required to * interface * Adafruit invests time and resources providing this open source code, * please support Adafruit and open-source hardware by purchasing * products from Adafruit! * * Written by Limor Fried/Ladyada for Adafruit Industries. * BSD license, all text above must be included in any redistribution */ #ifndef ADAFRUIT_BMP085_H #define ADAFRUIT_BMP085_H #include #include #define BMP085_DEBUG 0 //!< Debug mode #define BMP085_I2CADDR 0x77 //!< BMP085 I2C address #define BMP085_ULTRALOWPOWER 0 //!< Ultra low power mode #define BMP085_STANDARD 1 //!< Standard mode #define BMP085_HIGHRES 2 //!< High-res mode #define BMP085_ULTRAHIGHRES 3 //!< Ultra high-res mode #define BMP085_CAL_AC1 0xAA //!< R Calibration data (16 bits) #define BMP085_CAL_AC2 0xAC //!< R Calibration data (16 bits) #define BMP085_CAL_AC3 0xAE //!< R Calibration data (16 bits) #define BMP085_CAL_AC4 0xB0 //!< R Calibration data (16 bits) #define BMP085_CAL_AC5 0xB2 //!< R Calibration data (16 bits) #define BMP085_CAL_AC6 0xB4 //!< R Calibration data (16 bits) #define BMP085_CAL_B1 0xB6 //!< R Calibration data (16 bits) #define BMP085_CAL_B2 0xB8 //!< R Calibration data (16 bits) #define BMP085_CAL_MB 0xBA //!< R Calibration data (16 bits) #define BMP085_CAL_MC 0xBC //!< R Calibration data (16 bits) #define BMP085_CAL_MD 0xBE //!< R Calibration data (16 bits) #define BMP085_CONTROL 0xF4 //!< Control register #define BMP085_TEMPDATA 0xF6 //!< Temperature data register #define BMP085_PRESSUREDATA 0xF6 //!< Pressure data register #define BMP085_READTEMPCMD 0x2E //!< Read temperature control register value #define BMP085_READPRESSURECMD 0x34 //!< Read pressure control register value /*! * @brief Main BMP085 class */ class Adafruit_BMP085 { public: Adafruit_BMP085(); /*! * @brief Starts I2C connection * @param mode Mode to set, ultra high-res by default * @param wire The I2C interface to use, defaults to Wire * @return Returns true if successful */ bool begin(uint8_t mode = BMP085_ULTRAHIGHRES, TwoWire *wire = &Wire); /*! * @brief Gets the temperature over I2C from the BMP085 * @return Returns the temperature */ float readTemperature(void); /*! * @brief Gets the pressure over I2C from the BMP085 * @return Returns the pressure */ int32_t readPressure(void); /*! * @brief Calculates the pressure at sea level * @param altitude_meters Current altitude (in meters) * @return Returns the calculated pressure at sea level */ int32_t readSealevelPressure(float altitude_meters = 0); /*! * @brief Reads the altitude * @param sealevelPressure Pressure at sea level, measured in pascals * @return Returns the altitude */ float readAltitude(float sealevelPressure = 101325); // std atmosphere /*! * @brief Reads the raw temperature * @return Returns the raw temperature */ uint16_t readRawTemperature(void); /*! * @brief Reads the raw pressure * @return Returns the raw pressure */ uint32_t readRawPressure(void); private: int32_t computeB5(int32_t UT); uint8_t read8(uint8_t addr); uint16_t read16(uint8_t addr); void write8(uint8_t addr, uint8_t data); Adafruit_I2CDevice *i2c_dev; uint8_t oversampling; int16_t ac1, ac2, ac3, b1, b2, mb, mc, md; uint16_t ac4, ac5, ac6; }; #endif // ADAFRUIT_BMP085_H ================================================ FILE: README.md ================================================ # Adafruit BMP085 Library [![Build Status](https://github.com/adafruit/Adafruit-BMP085-Library/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit-BMP085-Library/actions)[![Documentation](https://github.com/adafruit/ci-arduino/blob/master/assets/doxygen_badge.svg)](http://adafruit.github.io/Adafruit-BMP085-Library/html/index.html) This is a library for the Adafruit BMP085/BMP180 Barometric Pressure + Temp sensor Designed specifically to work with the Adafruit BMP085 or BMP180 Breakout ----> http://www.adafruit.com/products/391 ----> http://www.adafruit.com/products/1603 These displays use I2C to communicate, 2 pins are required to interface Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! Check out the links above for our tutorials and wiring diagrams Requires the https://github.com/adafruit/Adafruit_BusIO library for I2C abstraction Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! Written by Limor Fried/Ladyada for Adafruit Industries. BSD license, all text above must be included in any redistribution To download. click the DOWNLOAD ZIP button, rename the uncompressed folder Adafruit_BMP085. Check that the Adafruit_BMP085 folder contains Adafruit_BMP085.cpp and Adafruit_BMP085.h Place the Adafruit_BMP085 library folder your arduinosketchfolder/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE. We also have a great tutorial on Arduino library installation at: http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use ================================================ FILE: examples/BMP085test/BMP085test.ino ================================================ #include /*************************************************** This is an example for the BMP085 Barometric Pressure & Temp Sensor Designed specifically to work with the Adafruit BMP085 Breakout ----> https://www.adafruit.com/products/391 These pressure and temperature sensors use I2C to communicate, 2 pins are required to interface Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! Written by Limor Fried/Ladyada for Adafruit Industries. BSD license, all text above must be included in any redistribution ****************************************************/ // Connect VCC of the BMP085 sensor to 3.3V (NOT 5.0V!) // Connect GND to Ground // Connect SCL to i2c clock - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 5 // Connect SDA to i2c data - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 4 // EOC is not used, it signifies an end of conversion // XCLR is a reset pin, also not used here Adafruit_BMP085 bmp; void setup() { Serial.begin(9600); if (!bmp.begin()) { Serial.println("Could not find a valid BMP085 sensor, check wiring!"); while (1) {} } } void loop() { Serial.print("Temperature = "); Serial.print(bmp.readTemperature()); Serial.println(" *C"); Serial.print("Pressure = "); Serial.print(bmp.readPressure()); Serial.println(" Pa"); // Calculate altitude assuming 'standard' barometric // pressure of 1013.25 millibar = 101325 Pascal Serial.print("Altitude = "); Serial.print(bmp.readAltitude()); Serial.println(" meters"); Serial.print("Pressure at sealevel (calculated) = "); Serial.print(bmp.readSealevelPressure()); Serial.println(" Pa"); // you can get a more precise measurement of altitude // if you know the current sea level pressure which will // vary with weather and such. If it is 1015 millibars // that is equal to 101500 Pascals. Serial.print("Real altitude = "); Serial.print(bmp.readAltitude(101500)); Serial.println(" meters"); Serial.println(); delay(500); } ================================================ FILE: library.properties ================================================ name=Adafruit BMP085 Library version=1.2.4 author=Adafruit maintainer=Adafruit sentence=A powerful but easy to use BMP085/BMP180 Library paragraph=A powerful but easy to use BMP085/BMP180 Library category=Sensors url=https://github.com/adafruit/Adafruit-BMP085-Library architectures=* depends=Adafruit Unified Sensor, Adafruit BusIO