├── .github ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── githubci.yml ├── .gitignore ├── Adafruit_BMP280.cpp ├── Adafruit_BMP280.h ├── README.md ├── assets └── board.jpg ├── examples ├── bmp280_forced │ └── bmp280_forced.ino ├── bmp280_sensortest │ └── bmp280_sensortest.ino └── bmp280test │ └── bmp280test.ino ├── keywords.txt └── 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 BMP280 Library" 32 | run: bash ci/doxy_gen_and_deploy.sh 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # osx 2 | .DS_Store 3 | 4 | # doxygen 5 | Doxyfile* 6 | doxygen_sqlite3.db 7 | html 8 | *.tmp 9 | -------------------------------------------------------------------------------- /Adafruit_BMP280.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file Adafruit_BMP280.cpp 3 | * 4 | * This is a library for the BMP280 orientation sensor 5 | * 6 | * Designed specifically to work with the Adafruit BMP280 Sensor. 7 | * 8 | * Pick one up today in the adafruit shop! 9 | * ------> https://www.adafruit.com/product/2651 10 | * 11 | * These sensors use I2C to communicate, 2 pins are required to interface. 12 | * 13 | * Adafruit invests time and resources providing this open source code, 14 | * please support Adafruit andopen-source hardware by purchasing products 15 | * from Adafruit! 16 | * 17 | * K.Townsend (Adafruit Industries) 18 | * 19 | * BSD license, all text above must be included in any redistribution 20 | */ 21 | 22 | #include 23 | 24 | /*! 25 | * @brief BMP280 constructor using i2c 26 | * @param *theWire 27 | * optional wire 28 | */ 29 | Adafruit_BMP280::Adafruit_BMP280(TwoWire *theWire) { 30 | _wire = theWire; 31 | temp_sensor = new Adafruit_BMP280_Temp(this); 32 | pressure_sensor = new Adafruit_BMP280_Pressure(this); 33 | } 34 | 35 | /*! 36 | * @brief BMP280 constructor using hardware SPI 37 | * @param cspin 38 | * cs pin number 39 | * @param theSPI 40 | * optional SPI object 41 | */ 42 | Adafruit_BMP280::Adafruit_BMP280(int8_t cspin, SPIClass *theSPI) { 43 | spi_dev = new Adafruit_SPIDevice(cspin, 1000000, SPI_BITORDER_MSBFIRST, 44 | SPI_MODE0, theSPI); 45 | temp_sensor = new Adafruit_BMP280_Temp(this); 46 | pressure_sensor = new Adafruit_BMP280_Pressure(this); 47 | } 48 | 49 | /*! 50 | * @brief BMP280 constructor using bitbang SPI 51 | * @param cspin 52 | * The pin to use for CS/SSEL. 53 | * @param mosipin 54 | * The pin to use for MOSI. 55 | * @param misopin 56 | * The pin to use for MISO. 57 | * @param sckpin 58 | * The pin to use for SCK. 59 | */ 60 | Adafruit_BMP280::Adafruit_BMP280(int8_t cspin, int8_t mosipin, int8_t misopin, 61 | int8_t sckpin) { 62 | spi_dev = new Adafruit_SPIDevice(cspin, sckpin, misopin, mosipin); 63 | temp_sensor = new Adafruit_BMP280_Temp(this); 64 | pressure_sensor = new Adafruit_BMP280_Pressure(this); 65 | } 66 | 67 | Adafruit_BMP280::~Adafruit_BMP280(void) { 68 | if (spi_dev) 69 | delete spi_dev; 70 | if (i2c_dev) 71 | delete i2c_dev; 72 | if (temp_sensor) 73 | delete temp_sensor; 74 | if (pressure_sensor) 75 | delete pressure_sensor; 76 | } 77 | 78 | /*! 79 | * Initialises the sensor. 80 | * @param addr 81 | * The I2C address to use (default = 0x77) 82 | * @param chipid 83 | * The expected chip ID (used to validate connection). 84 | * @return True if the init was successful, otherwise false. 85 | */ 86 | bool Adafruit_BMP280::begin(uint8_t addr, uint8_t chipid) { 87 | if (spi_dev == NULL) { 88 | // I2C mode 89 | if (i2c_dev) 90 | delete i2c_dev; 91 | i2c_dev = new Adafruit_I2CDevice(addr, _wire); 92 | if (!i2c_dev->begin()) 93 | return false; 94 | } else { 95 | // SPI mode 96 | if (!spi_dev->begin()) 97 | return false; 98 | } 99 | 100 | // check if sensor, i.e. the chip ID is correct 101 | _sensorID = read8(BMP280_REGISTER_CHIPID); 102 | if (_sensorID != chipid) 103 | return false; 104 | 105 | readCoefficients(); 106 | // write8(BMP280_REGISTER_CONTROL, 0x3F); /* needed? */ 107 | setSampling(); 108 | delay(100); 109 | return true; 110 | } 111 | 112 | /*! 113 | * Sets the sampling config for the device. 114 | * @param mode 115 | * The operating mode of the sensor. 116 | * @param tempSampling 117 | * The sampling scheme for temp readings. 118 | * @param pressSampling 119 | * The sampling scheme for pressure readings. 120 | * @param filter 121 | * The filtering mode to apply (if any). 122 | * @param duration 123 | * The sampling duration. 124 | */ 125 | void Adafruit_BMP280::setSampling(sensor_mode mode, 126 | sensor_sampling tempSampling, 127 | sensor_sampling pressSampling, 128 | sensor_filter filter, 129 | standby_duration duration) { 130 | if (!_sensorID) 131 | return; // begin() not called yet 132 | _measReg.mode = mode; 133 | _measReg.osrs_t = tempSampling; 134 | _measReg.osrs_p = pressSampling; 135 | 136 | _configReg.filter = filter; 137 | _configReg.t_sb = duration; 138 | 139 | write8(BMP280_REGISTER_CONFIG, _configReg.get()); 140 | write8(BMP280_REGISTER_CONTROL, _measReg.get()); 141 | } 142 | 143 | /**************************************************************************/ 144 | /*! 145 | @brief Writes an 8 bit value over I2C/SPI 146 | */ 147 | /**************************************************************************/ 148 | void Adafruit_BMP280::write8(byte reg, byte value) { 149 | byte buffer[2]; 150 | buffer[1] = value; 151 | if (i2c_dev) { 152 | buffer[0] = reg; 153 | i2c_dev->write(buffer, 2); 154 | } else { 155 | buffer[0] = reg & ~0x80; 156 | spi_dev->write(buffer, 2); 157 | } 158 | } 159 | 160 | /*! 161 | * @brief Reads an 8 bit value over I2C/SPI 162 | * @param reg 163 | * selected register 164 | * @return value from selected register 165 | */ 166 | uint8_t Adafruit_BMP280::read8(byte reg) { 167 | uint8_t buffer[1]; 168 | if (i2c_dev) { 169 | buffer[0] = uint8_t(reg); 170 | i2c_dev->write_then_read(buffer, 1, buffer, 1); 171 | } else { 172 | buffer[0] = uint8_t(reg | 0x80); 173 | spi_dev->write_then_read(buffer, 1, buffer, 1); 174 | } 175 | return buffer[0]; 176 | } 177 | 178 | /*! 179 | * @brief Reads a 16 bit value over I2C/SPI 180 | */ 181 | uint16_t Adafruit_BMP280::read16(byte reg) { 182 | uint8_t buffer[2]; 183 | 184 | if (i2c_dev) { 185 | buffer[0] = uint8_t(reg); 186 | i2c_dev->write_then_read(buffer, 1, buffer, 2); 187 | } else { 188 | buffer[0] = uint8_t(reg | 0x80); 189 | spi_dev->write_then_read(buffer, 1, buffer, 2); 190 | } 191 | return uint16_t(buffer[0]) << 8 | uint16_t(buffer[1]); 192 | } 193 | 194 | uint16_t Adafruit_BMP280::read16_LE(byte reg) { 195 | uint16_t temp = read16(reg); 196 | return (temp >> 8) | (temp << 8); 197 | } 198 | 199 | /*! 200 | * @brief Reads a signed 16 bit value over I2C/SPI 201 | */ 202 | int16_t Adafruit_BMP280::readS16(byte reg) { return (int16_t)read16(reg); } 203 | 204 | int16_t Adafruit_BMP280::readS16_LE(byte reg) { 205 | return (int16_t)read16_LE(reg); 206 | } 207 | 208 | /*! 209 | * @brief Reads a 24 bit value over I2C/SPI 210 | */ 211 | uint32_t Adafruit_BMP280::read24(byte reg) { 212 | uint8_t buffer[3]; 213 | 214 | if (i2c_dev) { 215 | buffer[0] = uint8_t(reg); 216 | i2c_dev->write_then_read(buffer, 1, buffer, 3); 217 | } else { 218 | buffer[0] = uint8_t(reg | 0x80); 219 | spi_dev->write_then_read(buffer, 1, buffer, 3); 220 | } 221 | return uint32_t(buffer[0]) << 16 | uint32_t(buffer[1]) << 8 | 222 | uint32_t(buffer[2]); 223 | } 224 | 225 | /*! 226 | * @brief Reads the factory-set coefficients 227 | */ 228 | void Adafruit_BMP280::readCoefficients() { 229 | _bmp280_calib.dig_T1 = read16_LE(BMP280_REGISTER_DIG_T1); 230 | _bmp280_calib.dig_T2 = readS16_LE(BMP280_REGISTER_DIG_T2); 231 | _bmp280_calib.dig_T3 = readS16_LE(BMP280_REGISTER_DIG_T3); 232 | 233 | _bmp280_calib.dig_P1 = read16_LE(BMP280_REGISTER_DIG_P1); 234 | _bmp280_calib.dig_P2 = readS16_LE(BMP280_REGISTER_DIG_P2); 235 | _bmp280_calib.dig_P3 = readS16_LE(BMP280_REGISTER_DIG_P3); 236 | _bmp280_calib.dig_P4 = readS16_LE(BMP280_REGISTER_DIG_P4); 237 | _bmp280_calib.dig_P5 = readS16_LE(BMP280_REGISTER_DIG_P5); 238 | _bmp280_calib.dig_P6 = readS16_LE(BMP280_REGISTER_DIG_P6); 239 | _bmp280_calib.dig_P7 = readS16_LE(BMP280_REGISTER_DIG_P7); 240 | _bmp280_calib.dig_P8 = readS16_LE(BMP280_REGISTER_DIG_P8); 241 | _bmp280_calib.dig_P9 = readS16_LE(BMP280_REGISTER_DIG_P9); 242 | } 243 | 244 | /*! 245 | * Reads the temperature from the device. 246 | * @return The temperature in degrees celsius. 247 | */ 248 | float Adafruit_BMP280::readTemperature() { 249 | int32_t var1, var2; 250 | if (!_sensorID) 251 | return NAN; // begin() not called yet 252 | 253 | int32_t adc_T = read24(BMP280_REGISTER_TEMPDATA); 254 | adc_T >>= 4; 255 | 256 | var1 = ((((adc_T >> 3) - ((int32_t)_bmp280_calib.dig_T1 << 1))) * 257 | ((int32_t)_bmp280_calib.dig_T2)) >> 258 | 11; 259 | 260 | var2 = (((((adc_T >> 4) - ((int32_t)_bmp280_calib.dig_T1)) * 261 | ((adc_T >> 4) - ((int32_t)_bmp280_calib.dig_T1))) >> 262 | 12) * 263 | ((int32_t)_bmp280_calib.dig_T3)) >> 264 | 14; 265 | 266 | t_fine = var1 + var2; 267 | 268 | float T = (t_fine * 5 + 128) >> 8; 269 | return T / 100; 270 | } 271 | 272 | /*! 273 | * Reads the barometric pressure from the device. 274 | * @return Barometric pressure in Pa. 275 | */ 276 | float Adafruit_BMP280::readPressure() { 277 | int64_t var1, var2, p; 278 | if (!_sensorID) 279 | return NAN; // begin() not called yet 280 | 281 | // Must be done first to get the t_fine variable set up 282 | readTemperature(); 283 | 284 | int32_t adc_P = read24(BMP280_REGISTER_PRESSUREDATA); 285 | adc_P >>= 4; 286 | 287 | var1 = ((int64_t)t_fine) - 128000; 288 | var2 = var1 * var1 * (int64_t)_bmp280_calib.dig_P6; 289 | var2 = var2 + ((var1 * (int64_t)_bmp280_calib.dig_P5) << 17); 290 | var2 = var2 + (((int64_t)_bmp280_calib.dig_P4) << 35); 291 | var1 = ((var1 * var1 * (int64_t)_bmp280_calib.dig_P3) >> 8) + 292 | ((var1 * (int64_t)_bmp280_calib.dig_P2) << 12); 293 | var1 = 294 | (((((int64_t)1) << 47) + var1)) * ((int64_t)_bmp280_calib.dig_P1) >> 33; 295 | 296 | if (var1 == 0) { 297 | return 0; // avoid exception caused by division by zero 298 | } 299 | p = 1048576 - adc_P; 300 | p = (((p << 31) - var2) * 3125) / var1; 301 | var1 = (((int64_t)_bmp280_calib.dig_P9) * (p >> 13) * (p >> 13)) >> 25; 302 | var2 = (((int64_t)_bmp280_calib.dig_P8) * p) >> 19; 303 | 304 | p = ((p + var1 + var2) >> 8) + (((int64_t)_bmp280_calib.dig_P7) << 4); 305 | return (float)p / 256; 306 | } 307 | 308 | /*! 309 | * @brief Calculates the approximate altitude using barometric pressure and the 310 | * supplied sea level hPa as a reference. 311 | * @param seaLevelhPa 312 | * The current hPa at sea level. 313 | * @return The approximate altitude above sea level in meters. 314 | */ 315 | float Adafruit_BMP280::readAltitude(float seaLevelhPa) { 316 | float altitude; 317 | 318 | float pressure = readPressure(); // in Si units for Pascal 319 | pressure /= 100; 320 | 321 | altitude = 44330 * (1.0 - pow(pressure / seaLevelhPa, 0.1903)); 322 | 323 | return altitude; 324 | } 325 | 326 | /*! 327 | * Calculates the pressure at sea level (QNH) from the specified altitude, 328 | * and atmospheric pressure (QFE). 329 | * @param altitude Altitude in m 330 | * @param atmospheric Atmospheric pressure in hPa 331 | * @return The approximate pressure in hPa 332 | */ 333 | float Adafruit_BMP280::seaLevelForAltitude(float altitude, float atmospheric) { 334 | // Equation taken from BMP180 datasheet (page 17): 335 | // http://www.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf 336 | 337 | // Note that using the equation from wikipedia can give bad results 338 | // at high altitude. See this thread for more information: 339 | // http://forums.adafruit.com/viewtopic.php?f=22&t=58064 340 | return atmospheric / pow(1.0 - (altitude / 44330.0), 5.255); 341 | } 342 | 343 | /*! 344 | @brief calculates the boiling point of water by a given pressure 345 | @param pressure pressure in hPa 346 | @return temperature in °C 347 | */ 348 | 349 | float Adafruit_BMP280::waterBoilingPoint(float pressure) { 350 | // Magnusformular for calculation of the boiling point of water at a given 351 | // pressure 352 | return (234.175 * log(pressure / 6.1078)) / 353 | (17.08085 - log(pressure / 6.1078)); 354 | } 355 | 356 | /*! 357 | @brief Take a new measurement (only possible in forced mode) 358 | @return true if successful, otherwise false 359 | */ 360 | bool Adafruit_BMP280::takeForcedMeasurement() { 361 | // If we are in forced mode, the BME sensor goes back to sleep after each 362 | // measurement and we need to set it to forced mode once at this point, so 363 | // it will take the next measurement and then return to sleep again. 364 | // In normal mode simply does new measurements periodically. 365 | if (_measReg.mode == MODE_FORCED) { 366 | // set to forced mode, i.e. "take next measurement" 367 | write8(BMP280_REGISTER_CONTROL, _measReg.get()); 368 | // wait until measurement has been completed, otherwise we would read 369 | // the values from the last measurement 370 | while (read8(BMP280_REGISTER_STATUS) & 0x08) 371 | delay(1); 372 | return true; 373 | } 374 | return false; 375 | } 376 | 377 | /*! 378 | * @brief Resets the chip via soft reset 379 | */ 380 | void Adafruit_BMP280::reset(void) { 381 | write8(BMP280_REGISTER_SOFTRESET, MODE_SOFT_RESET_CODE); 382 | } 383 | 384 | /*! 385 | * Returns Sensor ID for diagnostics 386 | * @returns 0x61 for BME680, 0x60 for BME280, 0x56, 0x57, 0x58 for BMP280 387 | */ 388 | uint8_t Adafruit_BMP280::sensorID(void) { return _sensorID; }; 389 | 390 | /*! 391 | @brief Gets the most recent sensor event from the hardware status register. 392 | @return Sensor status as a byte. 393 | */ 394 | uint8_t Adafruit_BMP280::getStatus(void) { 395 | return read8(BMP280_REGISTER_STATUS); 396 | } 397 | 398 | /*! 399 | @brief Gets an Adafruit Unified Sensor object for the temp sensor component 400 | @return Adafruit_Sensor pointer to temperature sensor 401 | */ 402 | Adafruit_Sensor *Adafruit_BMP280::getTemperatureSensor(void) { 403 | return temp_sensor; 404 | } 405 | 406 | /*! 407 | @brief Gets an Adafruit Unified Sensor object for the pressure sensor 408 | component 409 | @return Adafruit_Sensor pointer to pressure sensor 410 | */ 411 | Adafruit_Sensor *Adafruit_BMP280::getPressureSensor(void) { 412 | return pressure_sensor; 413 | } 414 | 415 | /**************************************************************************/ 416 | /*! 417 | @brief Gets the sensor_t data for the BMP280's temperature sensor 418 | */ 419 | /**************************************************************************/ 420 | void Adafruit_BMP280_Temp::getSensor(sensor_t *sensor) { 421 | /* Clear the sensor_t object */ 422 | memset(sensor, 0, sizeof(sensor_t)); 423 | 424 | /* Insert the sensor name in the fixed length char array */ 425 | strncpy(sensor->name, "BMP280", sizeof(sensor->name) - 1); 426 | sensor->name[sizeof(sensor->name) - 1] = 0; 427 | sensor->version = 1; 428 | sensor->sensor_id = _sensorID; 429 | sensor->type = SENSOR_TYPE_AMBIENT_TEMPERATURE; 430 | sensor->min_delay = 0; 431 | sensor->min_value = -40.0; /* Temperature range -40 ~ +85 C */ 432 | sensor->max_value = +85.0; 433 | sensor->resolution = 0.01; /* 0.01 C */ 434 | } 435 | 436 | /**************************************************************************/ 437 | /*! 438 | @brief Gets the temperature as a standard sensor event 439 | @param event Sensor event object that will be populated 440 | @returns True 441 | */ 442 | /**************************************************************************/ 443 | bool Adafruit_BMP280_Temp::getEvent(sensors_event_t *event) { 444 | /* Clear the event */ 445 | memset(event, 0, sizeof(sensors_event_t)); 446 | 447 | event->version = sizeof(sensors_event_t); 448 | event->sensor_id = _sensorID; 449 | event->type = SENSOR_TYPE_AMBIENT_TEMPERATURE; 450 | event->timestamp = millis(); 451 | event->temperature = _theBMP280->readTemperature(); 452 | return true; 453 | } 454 | 455 | /**************************************************************************/ 456 | /*! 457 | @brief Gets the sensor_t data for the BMP280's pressure sensor 458 | */ 459 | /**************************************************************************/ 460 | void Adafruit_BMP280_Pressure::getSensor(sensor_t *sensor) { 461 | /* Clear the sensor_t object */ 462 | memset(sensor, 0, sizeof(sensor_t)); 463 | 464 | /* Insert the sensor name in the fixed length char array */ 465 | strncpy(sensor->name, "BMP280", sizeof(sensor->name) - 1); 466 | sensor->name[sizeof(sensor->name) - 1] = 0; 467 | sensor->version = 1; 468 | sensor->sensor_id = _sensorID; 469 | sensor->type = SENSOR_TYPE_PRESSURE; 470 | sensor->min_delay = 0; 471 | sensor->min_value = 300.0; /* 300 ~ 1100 hPa */ 472 | sensor->max_value = 1100.0; 473 | sensor->resolution = 0.012; /* 0.12 hPa relative */ 474 | } 475 | 476 | /**************************************************************************/ 477 | /*! 478 | @brief Gets the pressure as a standard sensor event 479 | @param event Sensor event object that will be populated 480 | @returns True 481 | */ 482 | /**************************************************************************/ 483 | bool Adafruit_BMP280_Pressure::getEvent(sensors_event_t *event) { 484 | /* Clear the event */ 485 | memset(event, 0, sizeof(sensors_event_t)); 486 | 487 | event->version = sizeof(sensors_event_t); 488 | event->sensor_id = _sensorID; 489 | event->type = SENSOR_TYPE_PRESSURE; 490 | event->timestamp = millis(); 491 | event->pressure = _theBMP280->readPressure() / 100; // convert Pa to hPa 492 | return true; 493 | } 494 | -------------------------------------------------------------------------------- /Adafruit_BMP280.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file Adafruit_BMP280.h 3 | * 4 | * This is a library for the Adafruit BMP280 Breakout. 5 | * 6 | * Designed specifically to work with the Adafruit BMP280 Breakout. 7 | * 8 | * Pick one up today in the adafruit shop! 9 | * ------> https://www.adafruit.com/product/2651 10 | * 11 | * These sensors use I2C to communicate, 2 pins are required to interface. 12 | * 13 | * Adafruit invests time and resources providing this open source code, 14 | * please support Adafruit andopen-source hardware by purchasing products 15 | * from Adafruit! 16 | * 17 | * K.Townsend (Adafruit Industries) 18 | * 19 | * BSD license, all text above must be included in any redistribution 20 | */ 21 | #ifndef __BMP280_H__ 22 | #define __BMP280_H__ 23 | 24 | // clang-format off 25 | #include 26 | #include 27 | #include 28 | #include 29 | // clang-format on 30 | 31 | /*! 32 | * I2C ADDRESS/BITS/SETTINGS 33 | */ 34 | #define BMP280_ADDRESS (0x77) /**< The default I2C address for the sensor. */ 35 | #define BMP280_ADDRESS_ALT \ 36 | (0x76) /**< Alternative I2C address for the sensor. */ 37 | #define BMP280_CHIPID (0x58) /**< Default chip ID. */ 38 | 39 | /*! 40 | * Registers available on the sensor. 41 | */ 42 | enum { 43 | BMP280_REGISTER_DIG_T1 = 0x88, 44 | BMP280_REGISTER_DIG_T2 = 0x8A, 45 | BMP280_REGISTER_DIG_T3 = 0x8C, 46 | BMP280_REGISTER_DIG_P1 = 0x8E, 47 | BMP280_REGISTER_DIG_P2 = 0x90, 48 | BMP280_REGISTER_DIG_P3 = 0x92, 49 | BMP280_REGISTER_DIG_P4 = 0x94, 50 | BMP280_REGISTER_DIG_P5 = 0x96, 51 | BMP280_REGISTER_DIG_P6 = 0x98, 52 | BMP280_REGISTER_DIG_P7 = 0x9A, 53 | BMP280_REGISTER_DIG_P8 = 0x9C, 54 | BMP280_REGISTER_DIG_P9 = 0x9E, 55 | BMP280_REGISTER_CHIPID = 0xD0, 56 | BMP280_REGISTER_VERSION = 0xD1, 57 | BMP280_REGISTER_SOFTRESET = 0xE0, 58 | BMP280_REGISTER_CAL26 = 0xE1, /**< R calibration = 0xE1-0xF0 */ 59 | BMP280_REGISTER_STATUS = 0xF3, 60 | BMP280_REGISTER_CONTROL = 0xF4, 61 | BMP280_REGISTER_CONFIG = 0xF5, 62 | BMP280_REGISTER_PRESSUREDATA = 0xF7, 63 | BMP280_REGISTER_TEMPDATA = 0xFA, 64 | }; 65 | 66 | /*! 67 | * Struct to hold calibration data. 68 | */ 69 | typedef struct { 70 | uint16_t dig_T1; /**< dig_T1 cal register. */ 71 | int16_t dig_T2; /**< dig_T2 cal register. */ 72 | int16_t dig_T3; /**< dig_T3 cal register. */ 73 | 74 | uint16_t dig_P1; /**< dig_P1 cal register. */ 75 | int16_t dig_P2; /**< dig_P2 cal register. */ 76 | int16_t dig_P3; /**< dig_P3 cal register. */ 77 | int16_t dig_P4; /**< dig_P4 cal register. */ 78 | int16_t dig_P5; /**< dig_P5 cal register. */ 79 | int16_t dig_P6; /**< dig_P6 cal register. */ 80 | int16_t dig_P7; /**< dig_P7 cal register. */ 81 | int16_t dig_P8; /**< dig_P8 cal register. */ 82 | int16_t dig_P9; /**< dig_P9 cal register. */ 83 | } bmp280_calib_data; 84 | 85 | class Adafruit_BMP280; 86 | 87 | /** Adafruit Unified Sensor interface for temperature component of BMP280 */ 88 | class Adafruit_BMP280_Temp : public Adafruit_Sensor { 89 | public: 90 | /** @brief Create an Adafruit_Sensor compatible object for the temp sensor 91 | @param parent A pointer to the BMP280 class */ 92 | Adafruit_BMP280_Temp(Adafruit_BMP280 *parent) { _theBMP280 = parent; } 93 | bool getEvent(sensors_event_t *); 94 | void getSensor(sensor_t *); 95 | 96 | private: 97 | int _sensorID = 280; 98 | Adafruit_BMP280 *_theBMP280 = NULL; 99 | }; 100 | 101 | /** Adafruit Unified Sensor interface for pressure component of BMP280 */ 102 | class Adafruit_BMP280_Pressure : public Adafruit_Sensor { 103 | public: 104 | /** @brief Create an Adafruit_Sensor compatible object for the pressure sensor 105 | @param parent A pointer to the BMP280 class */ 106 | Adafruit_BMP280_Pressure(Adafruit_BMP280 *parent) { _theBMP280 = parent; } 107 | bool getEvent(sensors_event_t *); 108 | void getSensor(sensor_t *); 109 | 110 | private: 111 | int _sensorID = 0; 112 | Adafruit_BMP280 *_theBMP280 = NULL; 113 | }; 114 | 115 | /** 116 | * Driver for the Adafruit BMP280 barometric pressure sensor. 117 | */ 118 | class Adafruit_BMP280 { 119 | public: 120 | /** Oversampling rate for the sensor. */ 121 | enum sensor_sampling { 122 | /** No over-sampling. */ 123 | SAMPLING_NONE = 0x00, 124 | /** 1x over-sampling. */ 125 | SAMPLING_X1 = 0x01, 126 | /** 2x over-sampling. */ 127 | SAMPLING_X2 = 0x02, 128 | /** 4x over-sampling. */ 129 | SAMPLING_X4 = 0x03, 130 | /** 8x over-sampling. */ 131 | SAMPLING_X8 = 0x04, 132 | /** 16x over-sampling. */ 133 | SAMPLING_X16 = 0x05 134 | }; 135 | 136 | /** Operating mode for the sensor. */ 137 | enum sensor_mode { 138 | /** Sleep mode. */ 139 | MODE_SLEEP = 0x00, 140 | /** Forced mode. */ 141 | MODE_FORCED = 0x01, 142 | /** Normal mode. */ 143 | MODE_NORMAL = 0x03, 144 | /** Software reset. */ 145 | MODE_SOFT_RESET_CODE = 0xB6 146 | }; 147 | 148 | /** Filtering level for sensor data. */ 149 | enum sensor_filter { 150 | /** No filtering. */ 151 | FILTER_OFF = 0x00, 152 | /** 2x filtering. */ 153 | FILTER_X2 = 0x01, 154 | /** 4x filtering. */ 155 | FILTER_X4 = 0x02, 156 | /** 8x filtering. */ 157 | FILTER_X8 = 0x03, 158 | /** 16x filtering. */ 159 | FILTER_X16 = 0x04 160 | }; 161 | 162 | /** Standby duration in ms */ 163 | enum standby_duration { 164 | /** 1 ms standby. */ 165 | STANDBY_MS_1 = 0x00, 166 | /** 62.5 ms standby. */ 167 | STANDBY_MS_63 = 0x01, 168 | /** 125 ms standby. */ 169 | STANDBY_MS_125 = 0x02, 170 | /** 250 ms standby. */ 171 | STANDBY_MS_250 = 0x03, 172 | /** 500 ms standby. */ 173 | STANDBY_MS_500 = 0x04, 174 | /** 1000 ms standby. */ 175 | STANDBY_MS_1000 = 0x05, 176 | /** 2000 ms standby. */ 177 | STANDBY_MS_2000 = 0x06, 178 | /** 4000 ms standby. */ 179 | STANDBY_MS_4000 = 0x07 180 | }; 181 | 182 | Adafruit_BMP280(TwoWire *theWire = &Wire); 183 | Adafruit_BMP280(int8_t cspin, SPIClass *theSPI = &SPI); 184 | Adafruit_BMP280(int8_t cspin, int8_t mosipin, int8_t misopin, int8_t sckpin); 185 | ~Adafruit_BMP280(void); 186 | 187 | bool begin(uint8_t addr = BMP280_ADDRESS, uint8_t chipid = BMP280_CHIPID); 188 | void reset(void); 189 | uint8_t getStatus(void); 190 | uint8_t sensorID(void); 191 | 192 | float readTemperature(); 193 | float readPressure(void); 194 | float readAltitude(float seaLevelhPa = 1013.25); 195 | float seaLevelForAltitude(float altitude, float atmospheric); 196 | float waterBoilingPoint(float pressure); 197 | bool takeForcedMeasurement(); 198 | 199 | Adafruit_Sensor *getTemperatureSensor(void); 200 | Adafruit_Sensor *getPressureSensor(void); 201 | 202 | void setSampling(sensor_mode mode = MODE_NORMAL, 203 | sensor_sampling tempSampling = SAMPLING_X16, 204 | sensor_sampling pressSampling = SAMPLING_X16, 205 | sensor_filter filter = FILTER_OFF, 206 | standby_duration duration = STANDBY_MS_1); 207 | 208 | private: 209 | TwoWire *_wire; /**< Wire object */ 210 | Adafruit_I2CDevice *i2c_dev = NULL; ///< Pointer to I2C bus interface 211 | Adafruit_SPIDevice *spi_dev = NULL; ///< Pointer to SPI bus interface 212 | 213 | Adafruit_BMP280_Temp *temp_sensor = NULL; 214 | Adafruit_BMP280_Pressure *pressure_sensor = NULL; 215 | 216 | /** Encapsulates the config register */ 217 | struct config { 218 | /** Initialize to power-on-reset state */ 219 | config() : t_sb(STANDBY_MS_1), filter(FILTER_OFF), none(0), spi3w_en(0) {} 220 | /** Inactive duration (standby time) in normal mode */ 221 | unsigned int t_sb : 3; 222 | /** Filter settings */ 223 | unsigned int filter : 3; 224 | /** Unused - don't set */ 225 | unsigned int none : 1; 226 | /** Enables 3-wire SPI */ 227 | unsigned int spi3w_en : 1; 228 | /** Used to retrieve the assembled config register's byte value. */ 229 | unsigned int get() { return (t_sb << 5) | (filter << 2) | spi3w_en; } 230 | }; 231 | 232 | /** Encapsulates trhe ctrl_meas register */ 233 | struct ctrl_meas { 234 | /** Initialize to power-on-reset state */ 235 | ctrl_meas() 236 | : osrs_t(SAMPLING_NONE), osrs_p(SAMPLING_NONE), mode(MODE_SLEEP) {} 237 | /** Temperature oversampling. */ 238 | unsigned int osrs_t : 3; 239 | /** Pressure oversampling. */ 240 | unsigned int osrs_p : 3; 241 | /** Device mode */ 242 | unsigned int mode : 2; 243 | /** Used to retrieve the assembled ctrl_meas register's byte value. */ 244 | unsigned int get() { return (osrs_t << 5) | (osrs_p << 2) | mode; } 245 | }; 246 | 247 | void readCoefficients(void); 248 | uint8_t spixfer(uint8_t x); 249 | void write8(byte reg, byte value); 250 | uint8_t read8(byte reg); 251 | uint16_t read16(byte reg); 252 | uint32_t read24(byte reg); 253 | int16_t readS16(byte reg); 254 | uint16_t read16_LE(byte reg); 255 | int16_t readS16_LE(byte reg); 256 | 257 | uint8_t _i2caddr; 258 | 259 | int32_t _sensorID = 0; 260 | int32_t t_fine; 261 | // int8_t _cs, _mosi, _miso, _sck; 262 | bmp280_calib_data _bmp280_calib; 263 | config _configReg; 264 | ctrl_meas _measReg; 265 | }; 266 | 267 | #endif 268 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Adafruit BMP280 Driver (Barometric Pressure Sensor) [![Build Status](https://travis-ci.com/adafruit/Adafruit_BMP280_Library.svg?branch=master)](https://travis-ci.com/adafruit/Adafruit_BMP280_Library) 2 | 3 | This driver is for the [Adafruit BMP280 Breakout](http://www.adafruit.com/products/2651) 4 | 5 | 6 | 7 | ## About the BMP280 ## 8 | 9 | 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! 10 | 11 | ## About this Driver ## 12 | 13 | Adafruit invests time and resources providing this open source code. Please support Adafruit and open-source hardware by purchasing products from Adafruit! 14 | 15 | Written by Kevin (KTOWN) Townsend for Adafruit Industries. 16 | 17 | 18 | 19 | ## Compatibility 20 | 21 | MCU | Tested Works | Doesn't Work | Not Tested | Notes 22 | ------------------ | :----------: | :----------: | :---------: | ----- 23 | Atmega328 @ 16MHz | X | | | 24 | Atmega328 @ 12MHz | X | | | 25 | Atmega32u4 @ 16MHz | X | | | Use SDA/SCL on pins D2 & D3 26 | Atmega32u4 @ 8MHz | X | | | Use SDA/SCL on pins D2 & D3 27 | ESP8266 | X | | | SDA/SCL default to pins 4 & 5 but any two pins can be assigned as SDA/SCL using Wire.begin(SDA,SCL) 28 | Atmega2560 @ 16MHz | X | | | Use SDA/SCL on pins 20 & 21 29 | ATSAM3X8E | X | | | Use SDA/SCL on pins 20 & 21 30 | ATSAM21D | X | | | 31 | ATtiny85 @ 16MHz | | X | | 32 | ATtiny85 @ 8MHz | | X | | 33 | Intel Curie @ 32MHz | | | X | 34 | STM32F2 | | | X | 35 | 36 | * ATmega328 @ 16MHz : Arduino UNO, Adafruit Pro Trinket 5V, Adafruit Metro 328, Adafruit Metro Mini 37 | * ATmega328 @ 12MHz : Adafruit Pro Trinket 3V 38 | * ATmega32u4 @ 16MHz : Arduino Leonardo, Arduino Micro, Arduino Yun, Teensy 2.0 39 | * ATmega32u4 @ 8MHz : Adafruit Flora, Bluefruit Micro 40 | * ESP8266 : Adafruit Huzzah 41 | * ATmega2560 @ 16MHz : Arduino Mega 42 | * ATSAM3X8E : Arduino Due 43 | * ATSAM21D : Arduino Zero, M0 Pro 44 | * ATtiny85 @ 16MHz : Adafruit Trinket 5V 45 | * ATtiny85 @ 8MHz : Adafruit Gemma, Arduino Gemma, Adafruit Trinket 3V 46 | 47 | 48 | -------------------------------------------------------------------------------- /assets/board.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/Adafruit_BMP280_Library/ddcaf6d232e545179af9caf906fa7a56305fcf9d/assets/board.jpg -------------------------------------------------------------------------------- /examples/bmp280_forced/bmp280_forced.ino: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | This is a library for the BMP280 humidity, temperature & pressure sensor 3 | 4 | Designed specifically to work with the Adafruit BMP280 Breakout 5 | ----> http://www.adafruit.com/products/2651 6 | 7 | These sensors use I2C or SPI to communicate, 2 or 4 pins are required 8 | to interface. 9 | 10 | Adafruit invests time and resources providing this open source code, 11 | please support Adafruit andopen-source hardware by purchasing products 12 | from Adafruit! 13 | 14 | Written by Limor Fried & Kevin Townsend for Adafruit Industries. 15 | BSD license, all text above must be included in any redistribution 16 | ***************************************************************************/ 17 | 18 | #include 19 | 20 | #define BMP_SCK (13) 21 | #define BMP_MISO (12) 22 | #define BMP_MOSI (11) 23 | #define BMP_CS (10) 24 | 25 | Adafruit_BMP280 bmp; // I2C 26 | //Adafruit_BMP280 bmp(BMP_CS); // hardware SPI 27 | //Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK); 28 | 29 | void setup() { 30 | Serial.begin(9600); 31 | Serial.println(F("BMP280 Forced Mode Test.")); 32 | 33 | //if (!bmp.begin(BMP280_ADDRESS_ALT, BMP280_CHIPID)) { 34 | if (!bmp.begin()) { 35 | Serial.println(F("Could not find a valid BMP280 sensor, check wiring or " 36 | "try a different address!")); 37 | while (1) delay(10); 38 | } 39 | 40 | /* Default settings from datasheet. */ 41 | bmp.setSampling(Adafruit_BMP280::MODE_FORCED, /* Operating Mode. */ 42 | Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */ 43 | Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */ 44 | Adafruit_BMP280::FILTER_X16, /* Filtering. */ 45 | Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */ 46 | } 47 | 48 | void loop() { 49 | // must call this to wake sensor up and get new measurement data 50 | // it blocks until measurement is complete 51 | if (bmp.takeForcedMeasurement()) { 52 | // can now print out the new measurements 53 | Serial.print(F("Temperature = ")); 54 | Serial.print(bmp.readTemperature()); 55 | Serial.println(" *C"); 56 | 57 | Serial.print(F("Pressure = ")); 58 | Serial.print(bmp.readPressure()); 59 | Serial.println(" Pa"); 60 | 61 | Serial.print(F("Approx altitude = ")); 62 | Serial.print(bmp.readAltitude(1013.25)); /* Adjusted to local forecast! */ 63 | Serial.println(" m"); 64 | 65 | Serial.println(); 66 | delay(2000); 67 | } else { 68 | Serial.println("Forced measurement failed!"); 69 | } 70 | 71 | 72 | } 73 | -------------------------------------------------------------------------------- /examples/bmp280_sensortest/bmp280_sensortest.ino: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | This is a library for the BMP280 humidity, temperature & pressure sensor 3 | This example shows how to take Sensor Events instead of direct readings 4 | 5 | Designed specifically to work with the Adafruit BMP280 Breakout 6 | ----> http://www.adafruit.com/products/2651 7 | 8 | These sensors use I2C or SPI to communicate, 2 or 4 pins are required 9 | to interface. 10 | 11 | Adafruit invests time and resources providing this open source code, 12 | please support Adafruit and open-source hardware by purchasing products 13 | from Adafruit! 14 | 15 | Written by Limor Fried & Kevin Townsend for Adafruit Industries. 16 | BSD license, all text above must be included in any redistribution 17 | ***************************************************************************/ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | Adafruit_BMP280 bmp; // use I2C interface 24 | Adafruit_Sensor *bmp_temp = bmp.getTemperatureSensor(); 25 | Adafruit_Sensor *bmp_pressure = bmp.getPressureSensor(); 26 | 27 | void setup() { 28 | Serial.begin(9600); 29 | while ( !Serial ) delay(100); // wait for native usb 30 | Serial.println(F("BMP280 Sensor event test")); 31 | 32 | unsigned status; 33 | //status = bmp.begin(BMP280_ADDRESS_ALT, BMP280_CHIPID); 34 | status = bmp.begin(); 35 | if (!status) { 36 | Serial.println(F("Could not find a valid BMP280 sensor, check wiring or " 37 | "try a different address!")); 38 | Serial.print("SensorID was: 0x"); Serial.println(bmp.sensorID(),16); 39 | Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n"); 40 | Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n"); 41 | Serial.print(" ID of 0x60 represents a BME 280.\n"); 42 | Serial.print(" ID of 0x61 represents a BME 680.\n"); 43 | while (1) delay(10); 44 | } 45 | 46 | /* Default settings from datasheet. */ 47 | bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */ 48 | Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */ 49 | Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */ 50 | Adafruit_BMP280::FILTER_X16, /* Filtering. */ 51 | Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */ 52 | 53 | bmp_temp->printSensorDetails(); 54 | } 55 | 56 | void loop() { 57 | sensors_event_t temp_event, pressure_event; 58 | bmp_temp->getEvent(&temp_event); 59 | bmp_pressure->getEvent(&pressure_event); 60 | 61 | Serial.print(F("Temperature = ")); 62 | Serial.print(temp_event.temperature); 63 | Serial.println(" *C"); 64 | 65 | Serial.print(F("Pressure = ")); 66 | Serial.print(pressure_event.pressure); 67 | Serial.println(" hPa"); 68 | 69 | Serial.println(); 70 | delay(2000); 71 | } 72 | -------------------------------------------------------------------------------- /examples/bmp280test/bmp280test.ino: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | This is a library for the BMP280 humidity, temperature & pressure sensor 3 | 4 | Designed specifically to work with the Adafruit BMP280 Breakout 5 | ----> http://www.adafruit.com/products/2651 6 | 7 | These sensors use I2C or SPI to communicate, 2 or 4 pins are required 8 | to interface. 9 | 10 | Adafruit invests time and resources providing this open source code, 11 | please support Adafruit andopen-source hardware by purchasing products 12 | from Adafruit! 13 | 14 | Written by Limor Fried & Kevin Townsend for Adafruit Industries. 15 | BSD license, all text above must be included in any redistribution 16 | ***************************************************************************/ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #define BMP_SCK (13) 23 | #define BMP_MISO (12) 24 | #define BMP_MOSI (11) 25 | #define BMP_CS (10) 26 | 27 | Adafruit_BMP280 bmp; // I2C 28 | //Adafruit_BMP280 bmp(BMP_CS); // hardware SPI 29 | //Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK); 30 | 31 | void setup() { 32 | Serial.begin(9600); 33 | while ( !Serial ) delay(100); // wait for native usb 34 | Serial.println(F("BMP280 test")); 35 | unsigned status; 36 | //status = bmp.begin(BMP280_ADDRESS_ALT, BMP280_CHIPID); 37 | status = bmp.begin(); 38 | if (!status) { 39 | Serial.println(F("Could not find a valid BMP280 sensor, check wiring or " 40 | "try a different address!")); 41 | Serial.print("SensorID was: 0x"); Serial.println(bmp.sensorID(),16); 42 | Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n"); 43 | Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n"); 44 | Serial.print(" ID of 0x60 represents a BME 280.\n"); 45 | Serial.print(" ID of 0x61 represents a BME 680.\n"); 46 | while (1) delay(10); 47 | } 48 | 49 | /* Default settings from datasheet. */ 50 | bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */ 51 | Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */ 52 | Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */ 53 | Adafruit_BMP280::FILTER_X16, /* Filtering. */ 54 | Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */ 55 | } 56 | 57 | void loop() { 58 | Serial.print(F("Temperature = ")); 59 | Serial.print(bmp.readTemperature()); 60 | Serial.println(" *C"); 61 | 62 | Serial.print(F("Pressure = ")); 63 | Serial.print(bmp.readPressure()); 64 | Serial.println(" Pa"); 65 | 66 | Serial.print(F("Approx altitude = ")); 67 | Serial.print(bmp.readAltitude(1013.25)); /* Adjusted to local forecast! */ 68 | Serial.println(" m"); 69 | 70 | Serial.println(); 71 | delay(2000); 72 | } 73 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map for BMP280 library 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | Adafruit_BMP280 KEYWORD1 9 | Adafruit_BMP280_Temp KEYWORD1 10 | Adafruit_BMP280_Pressure KEYWORD1 11 | bmp280_calib_data KEYWORD1 12 | 13 | ####################################### 14 | # Methods and Functions (KEYWORD2) 15 | ####################################### 16 | begin KEYWORD2 17 | reset KEYWORD2 18 | getStatus KEYWORD2 19 | sensorID KEYWORD2 20 | getEvent KEYWORD2 21 | getSensor KEYWORD2 22 | readTemperature KEYWORD2 23 | readPressure KEYWORD2 24 | readAltitude KEYWORD2 25 | seaLevelForAltitude KEYWORD2 26 | waterBoilingPoint KEYWORD2 27 | takeForcedMeasurement KEYWORD2 28 | getTemperatureSensor KEYWORD2 29 | getPressureSensor KEYWORD2 30 | setSampling KEYWORD2 31 | 32 | ####################################### 33 | # Constants (LITERAL1) 34 | ####################################### 35 | SAMPLING_NONE LITERAL1 36 | SAMPLING_X1 LITERAL1 37 | SAMPLING_X2 LITERAL1 38 | SAMPLING_X4 LITERAL1 39 | SAMPLING_X8 LITERAL1 40 | SAMPLING_X16 LITERAL1 41 | MODE_SLEEP LITERAL1 42 | MODE_FORCED LITERAL1 43 | MODE_NORMAL LITERAL1 44 | MODE_SOFT_RESET_CODE LITERAL1 45 | FILTER_OFF LITERAL1 46 | FILTER_X2 LITERAL1 47 | FILTER_X4 LITERAL1 48 | FILTER_X8 LITERAL1 49 | FILTER_X16 LITERAL1 50 | STANDBY_MS_1 LITERAL1 51 | STANDBY_MS_63 LITERAL1 52 | STANDBY_MS_125 LITERAL1 53 | STANDBY_MS_250 LITERAL1 54 | STANDBY_MS_500 LITERAL1 55 | STANDBY_MS_1000 LITERAL1 56 | STANDBY_MS_2000 LITERAL1 57 | STANDBY_MS_4000 LITERAL1 58 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Adafruit BMP280 Library 2 | version=2.6.8 3 | author=Adafruit 4 | maintainer=Adafruit 5 | sentence=Arduino library for BMP280 sensors. 6 | paragraph=Arduino library for BMP280 pressure and altitude sensors. 7 | category=Sensors 8 | url=https://github.com/adafruit/Adafruit_BMP280_Library 9 | architectures=* 10 | depends=Adafruit Unified Sensor, Adafruit BusIO 11 | --------------------------------------------------------------------------------