From 63e56ed366386c7a29d7bb941ac38279aa072589 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Thu, 8 Aug 2024 14:18:10 -0400 Subject: [PATCH] Remove lost BMP388_DEV as submodule and add as folder Signed-off-by: Sara Damiano --- .gitmodules | 197 +++-- BMP388_DEV | 1 - BMP388_DEV/.editorconfig | 5 + BMP388_DEV/.gitignore | 32 + BMP388_DEV/.piopm | 1 + BMP388_DEV/BMP388_DEV.cpp | 521 +++++++++++++ BMP388_DEV/BMP388_DEV.h | 461 +++++++++++ BMP388_DEV/Device.cpp | 195 +++++ BMP388_DEV/Device.h | 94 +++ BMP388_DEV/LICENSE | 21 + BMP388_DEV/README.md | 737 ++++++++++++++++++ .../bmp388_ESP32_HSPI_Normal.ino | 43 + .../BMP388_ESP32_I2C_Normal_DefinedPins.ino | 29 + .../BMP388_ESP8266_I2C_Normal_DefinedPins.ino | 29 + .../BMP388_I2C_Forced/BMP388_I2C_Forced.ino | 28 + .../BMP388_I2C_Forced_Interrupt.ino | 39 + .../BMP388_I2C_Normal/BMP388_I2C_Normal.ino | 29 + .../BMP388_I2C_Normal_FIFO.ino | 46 ++ .../BMP388_I2C_Normal_Interrupt.ino | 40 + .../BMP388_I2C_Normal_Interrupt_FIFO.ino | 1 + .../BMP388_SPI_Forced/BMP388_SPI_Forced.ino | 28 + .../BMP_SPI_Forced_Interrupt.ino | 40 + .../BMP388_SPI_Normal/BMP388_SPI_Normal.ino | 29 + .../BMP388_SPI_Normal_FIFO.ino | 46 ++ .../BMP_SPI_Normal_Interrupt.ino | 41 + .../BMP388_SPI_Normal_Interrupt_FIFO.ino | 57 ++ .../BMP388_SPI_Normal_Multiple.ino | 44 ++ BMP388_DEV/keywords.txt | 135 ++++ BMP388_DEV/library.properties | 9 + 29 files changed, 2877 insertions(+), 101 deletions(-) delete mode 160000 BMP388_DEV create mode 100644 BMP388_DEV/.editorconfig create mode 100644 BMP388_DEV/.gitignore create mode 100644 BMP388_DEV/.piopm create mode 100644 BMP388_DEV/BMP388_DEV.cpp create mode 100644 BMP388_DEV/BMP388_DEV.h create mode 100644 BMP388_DEV/Device.cpp create mode 100644 BMP388_DEV/Device.h create mode 100644 BMP388_DEV/LICENSE create mode 100644 BMP388_DEV/README.md create mode 100644 BMP388_DEV/examples/BMP388_ESP32_HSPI_Normal/bmp388_ESP32_HSPI_Normal.ino create mode 100644 BMP388_DEV/examples/BMP388_ESP32_I2C_Normal_DefinedPins/BMP388_ESP32_I2C_Normal_DefinedPins.ino create mode 100644 BMP388_DEV/examples/BMP388_ESP8266_I2C_Normal_DefinedPins/BMP388_ESP8266_I2C_Normal_DefinedPins.ino create mode 100644 BMP388_DEV/examples/BMP388_I2C_Forced/BMP388_I2C_Forced.ino create mode 100644 BMP388_DEV/examples/BMP388_I2C_Forced_Interrupt/BMP388_I2C_Forced_Interrupt.ino create mode 100644 BMP388_DEV/examples/BMP388_I2C_Normal/BMP388_I2C_Normal.ino create mode 100644 BMP388_DEV/examples/BMP388_I2C_Normal_FIFO/BMP388_I2C_Normal_FIFO.ino create mode 100644 BMP388_DEV/examples/BMP388_I2C_Normal_Interrupt/BMP388_I2C_Normal_Interrupt.ino create mode 100644 BMP388_DEV/examples/BMP388_I2C_Normal_Interrupt_FIFO/BMP388_I2C_Normal_Interrupt_FIFO.ino create mode 100644 BMP388_DEV/examples/BMP388_SPI_Forced/BMP388_SPI_Forced.ino create mode 100644 BMP388_DEV/examples/BMP388_SPI_Forced_Interrupt/BMP_SPI_Forced_Interrupt.ino create mode 100644 BMP388_DEV/examples/BMP388_SPI_Normal/BMP388_SPI_Normal.ino create mode 100644 BMP388_DEV/examples/BMP388_SPI_Normal_FIFO/BMP388_SPI_Normal_FIFO.ino create mode 100644 BMP388_DEV/examples/BMP388_SPI_Normal_Interrupt/BMP_SPI_Normal_Interrupt.ino create mode 100644 BMP388_DEV/examples/BMP388_SPI_Normal_Interrupt_FIFO/BMP388_SPI_Normal_Interrupt_FIFO.ino create mode 100644 BMP388_DEV/examples/BMP388_SPI_Normal_Multiple/BMP388_SPI_Normal_Multiple.ino create mode 100644 BMP388_DEV/keywords.txt create mode 100644 BMP388_DEV/library.properties diff --git a/.gitmodules b/.gitmodules index 1d81fa8..d3d1c4f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,146 +1,143 @@ [submodule "DHT sensor library"] - path = Adafruit_DHT - url = http://github.com/adafruit/DHT-sensor-library +path = Adafruit_DHT +url = http://github.com/adafruit/DHT-sensor-library [submodule "Adafruit Unified Sensor"] - path = Adafruit_Sensor - url = https://github.com/adafruit/Adafruit_Sensor +path = Adafruit_Sensor +url = https://github.com/adafruit/Adafruit_Sensor [submodule "Adafruit TSL2561"] - path = Adafruit_TSL2561 - url = https://github.com/adafruit/Adafruit_TSL2561 +path = Adafruit_TSL2561 +url = https://github.com/adafruit/Adafruit_TSL2561 [submodule "EnviroDIY DS3231"] - path = EnviroDIY_DS3231 - url = https://github.com/EnviroDIY/Sodaq_DS3231 +path = EnviroDIY_DS3231 +url = https://github.com/EnviroDIY/Sodaq_DS3231 [submodule "EnviroDIY GPRSBee"] - path = EnviroDIY_GPRSBee - url = http://github.com/EnviroDIY/GPRSBee - branch = v1.2_hacked +path = EnviroDIY_GPRSBee +url = http://github.com/EnviroDIY/GPRSBee +branch = v1.2_hacked [submodule "ModularSensors"] - path = EnviroDIY_ModularSensors - url = https://github.com/EnviroDIY/ModularSensors +path = EnviroDIY_ModularSensors +url = https://github.com/EnviroDIY/ModularSensors [submodule "EnviroDIY PcIntMod"] - path = EnviroDIY_PCInt_PCINT0 - url = http://github.com/EnviroDIY/PcInt_PCINT0 +path = EnviroDIY_PCInt_PCINT0 +url = http://github.com/EnviroDIY/PcInt_PCINT0 [submodule "EnviroDIY SDI12"] - path = EnviroDIY_SDI12 - url = http://github.com/EnviroDIY/Arduino-SDI-12 - branch = master +path = EnviroDIY_SDI12 +url = http://github.com/EnviroDIY/Arduino-SDI-12 +branch = master [submodule "EnviroDIY SDI12Mod"] - path = EnviroDIY_SDI12_PCINT3 - url = https://github.com/EnviroDIY/Arduino-SDI-12 - branch = mayfly +path = EnviroDIY_SDI12_PCINT3 +url = https://github.com/EnviroDIY/Arduino-SDI-12 +branch = mayfly [submodule "EnviroDIY SoftwareSerialMod"] - path = EnviroDIY_SoftwareSerial_PCINT12 - url = http://github.com/EnviroDIY/SoftwareSerial_PCINT12 +path = EnviroDIY_SoftwareSerial_PCINT12 +url = http://github.com/EnviroDIY/SoftwareSerial_PCINT12 [submodule "Sodaq PcInt"] - path = Sodaq_PcInt - url = http://github.com/SodaqMoja/Sodaq_PcInt +path = Sodaq_PcInt +url = http://github.com/SodaqMoja/Sodaq_PcInt [submodule "Sodaq RTCTimer"] - path = Sodaq_RTCTimer - url = http://github.com/SodaqMoja/RTCTimer +path = Sodaq_RTCTimer +url = http://github.com/SodaqMoja/RTCTimer [submodule "Adafruit AM2315"] - path = Adafruit_AM2315 - url = https://github.com/adafruit/Adafruit_AM2315 +path = Adafruit_AM2315 +url = https://github.com/adafruit/Adafruit_AM2315 [submodule "Adafruit BME280 Library"] - path = Adafruit_BME280 - url = https://github.com/adafruit/Adafruit_BME280_Library +path = Adafruit_BME280 +url = https://github.com/adafruit/Adafruit_BME280_Library [submodule "Adafruit ADS1X15"] - path = Adafruit_ADS1X15 - url = https://github.com/soligen2010/Adafruit_ADS1X15 +path = Adafruit_ADS1X15 +url = https://github.com/soligen2010/Adafruit_ADS1X15 [submodule "Adafruit MPL115A2"] - path = Adafruit_MPL115A2 - url = https://github.com/adafruit/Adafruit_MPL115A2 +path = Adafruit_MPL115A2 +url = https://github.com/adafruit/Adafruit_MPL115A2 [submodule "Adafruit INA219"] - path = Adafruit_INA219 - url = https://github.com/adafruit/Adafruit_INA219 +path = Adafruit_INA219 +url = https://github.com/adafruit/Adafruit_INA219 [submodule "Adafruit BusIO"] - path = Adafruit_BusIO - url = https://github.com/adafruit/Adafruit_BusIO.git +path = Adafruit_BusIO +url = https://github.com/adafruit/Adafruit_BusIO.git [submodule "SDL_SSD1306"] - path = SDL_SSD1306 - url = http://github.com/switchdoclabs/SDL_Arduino_SSD1306 +path = SDL_SSD1306 +url = http://github.com/switchdoclabs/SDL_Arduino_SSD1306 [submodule "SdFat"] - path = SdFat - url = https://github.com/greiman/SdFat +path = SdFat +url = https://github.com/greiman/SdFat [submodule "DallasTemperature"] - path = DallasTemperature - url = https://github.com/milesburton/Arduino-Temperature-Control-Library +path = DallasTemperature +url = https://github.com/milesburton/Arduino-Temperature-Control-Library [submodule "OneWire"] - path = OneWire - url = https://github.com/PaulStoffregen/OneWire +path = OneWire +url = https://github.com/PaulStoffregen/OneWire [submodule "EnviroDIY_SoftwareSerial_ExtInts"] - path = EnviroDIY_SoftwareSerial_ExtInts - url = https://github.com/EnviroDIY/SoftwareSerial_ExternalInts +path = EnviroDIY_SoftwareSerial_ExtInts +url = https://github.com/EnviroDIY/SoftwareSerial_ExternalInts [submodule "EnviroDIY_SDI12_ExtInts"] - path = EnviroDIY_SDI12_ExtInts - url = https://github.com/EnviroDIY/Arduino-SDI-12 - branch = ExtInts +path = EnviroDIY_SDI12_ExtInts +url = https://github.com/EnviroDIY/Arduino-SDI-12 +branch = ExtInts [submodule "RTCZero"] - path = RTCZero - url = https://github.com/arduino-libraries/RTCZero +path = RTCZero +url = https://github.com/arduino-libraries/RTCZero [submodule "SensorModbusMaster"] - path = SensorModbusMaster - url = https://github.com/EnviroDIY/SensorModbusMaster +path = SensorModbusMaster +url = https://github.com/EnviroDIY/SensorModbusMaster [submodule "YosemitechModbus"] - path = YosemitechModbus - url = https://github.com/EnviroDIY/YosemitechModbus +path = YosemitechModbus +url = https://github.com/EnviroDIY/YosemitechModbus [submodule "KellerModbus"] - path = KellerModbus - url = https://github.com/EnviroDIY/KellerModbus +path = KellerModbus +url = https://github.com/EnviroDIY/KellerModbus [submodule "GroPointModbus"] - path = GroPointModbus - url = https://github.com/EnviroDIY/GroPointModbus.git +path = GroPointModbus +url = https://github.com/EnviroDIY/GroPointModbus.git [submodule "EnableInterrupt"] - path = EnableInterrupt - url = https://github.com/GreyGnome/EnableInterrupt +path = EnableInterrupt +url = https://github.com/GreyGnome/EnableInterrupt [submodule "AltSoftSerial"] - path = AltSoftSerial - url = https://github.com/PaulStoffregen/AltSoftSerial +path = AltSoftSerial +url = https://github.com/PaulStoffregen/AltSoftSerial [submodule "MS5803"] - path = MS5803 - url = https://github.com/NorthernWidget/MS5803 +path = MS5803 +url = https://github.com/NorthernWidget/MS5803 [submodule "PubSubClient"] - path = PubSubClient - url = https://github.com/knolleary/pubsubclient.git +path = PubSubClient +url = https://github.com/knolleary/pubsubclient.git [submodule "NeoSWSerial"] - path = NeoSWSerial - url = https://github.com/SRGDamia1/NeoSWSerial.git +path = NeoSWSerial +url = https://github.com/SRGDamia1/NeoSWSerial.git [submodule "StreamDebugger"] - path = StreamDebugger - url = https://github.com/vshymanskyy/StreamDebugger +path = StreamDebugger +url = https://github.com/vshymanskyy/StreamDebugger [submodule "SoftwareWire"] - path = SoftwareWire - url = https://github.com/Testato/SoftwareWire.git +path = SoftwareWire +url = https://github.com/Testato/SoftwareWire.git [submodule "Tally I2C"] - path = Tally_Library - url = https://github.com/EnviroDIY/Tally_Library - branch = Dev_I2C +path = Tally_Library +url = https://github.com/EnviroDIY/Tally_Library +branch = Dev_I2C [submodule "TinyGSM"] - path = TinyGSM - url = https://github.com/vshymanskyy/TinyGSM +path = TinyGSM +url = https://github.com/vshymanskyy/TinyGSM [submodule "Adafruit SHT4x Library"] - path = Adafruit_SHT4x - url = https://github.com/adafruit/Adafruit_SHT4x +path = Adafruit_SHT4x +url = https://github.com/adafruit/Adafruit_SHT4x [submodule "SparkFun_PCA9536_Arduino_Library"] - path = SparkFun_PCA9536_Arduino_Library - url = https://github.com/sparkfun/SparkFun_PCA9536_Arduino_Library -[submodule "BMP388_DEV"] - path = BMP388_DEV - url = https://github.com/MartinL1/BMP388_DEV.git +path = SparkFun_PCA9536_Arduino_Library +url = https://github.com/sparkfun/SparkFun_PCA9536_Arduino_Library [submodule "Adafruit_SSD1306"] - path = Adafruit_SSD1306 - url = https://github.com/adafruit/Adafruit_SSD1306 +path = Adafruit_SSD1306 +url = https://github.com/adafruit/Adafruit_SSD1306 [submodule "Adafruit-GFX-Library"] - path = Adafruit-GFX-Library - url = https://github.com/adafruit/Adafruit-GFX-Library +path = Adafruit-GFX-Library +url = https://github.com/adafruit/Adafruit-GFX-Library [submodule "Adafruit_MAX1704X"] - path = Adafruit_MAX1704X - url = https://github.com/adafruit/Adafruit_MAX1704X.git +path = Adafruit_MAX1704X +url = https://github.com/adafruit/Adafruit_MAX1704X.git [submodule "SparkFun_RV-8803_Arduino_Library"] - path = SparkFun_RV-8803_Arduino_Library - url = https://github.com/sparkfun/SparkFun_RV-8803_Arduino_Library +path = SparkFun_RV-8803_Arduino_Library +url = https://github.com/sparkfun/SparkFun_RV-8803_Arduino_Library [submodule "Adafruit_SPIFlash"] - path = Adafruit_SPIFlash - url = https://github.com/adafruit/Adafruit_SPIFlash +path = Adafruit_SPIFlash +url = https://github.com/adafruit/Adafruit_SPIFlash [submodule "LoRa_AT"] - path = LoRa_AT - url = https://github.com/EnviroDIY/LoRa_AT.git +path = LoRa_AT +url = https://github.com/EnviroDIY/LoRa_AT.git diff --git a/BMP388_DEV b/BMP388_DEV deleted file mode 160000 index cb709e8..0000000 --- a/BMP388_DEV +++ /dev/null @@ -1 +0,0 @@ -Subproject commit cb709e8b34c9344968c2862f8d01a5f8a9aab0c9 diff --git a/BMP388_DEV/.editorconfig b/BMP388_DEV/.editorconfig new file mode 100644 index 0000000..538ba2b --- /dev/null +++ b/BMP388_DEV/.editorconfig @@ -0,0 +1,5 @@ +root = true + +[*] +indent_style = tab +indent_size = 2 diff --git a/BMP388_DEV/.gitignore b/BMP388_DEV/.gitignore new file mode 100644 index 0000000..259148f --- /dev/null +++ b/BMP388_DEV/.gitignore @@ -0,0 +1,32 @@ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app diff --git a/BMP388_DEV/.piopm b/BMP388_DEV/.piopm new file mode 100644 index 0000000..5ccf150 --- /dev/null +++ b/BMP388_DEV/.piopm @@ -0,0 +1 @@ +{"type": "library", "name": "BMP388_DEV", "version": "1.0.11", "spec": {"owner": "martinl1", "id": 7012, "name": "BMP388_DEV", "requirements": null, "uri": null}} \ No newline at end of file diff --git a/BMP388_DEV/BMP388_DEV.cpp b/BMP388_DEV/BMP388_DEV.cpp new file mode 100644 index 0000000..0678660 --- /dev/null +++ b/BMP388_DEV/BMP388_DEV.cpp @@ -0,0 +1,521 @@ +/* + BMP388_DEV is an I2C/SPI compatible library for the Bosch BMP388 barometer. + + Copyright (C) Martin Lindupp 2020 + + V1.0.0 -- Initial release + V1.0.1 -- Fix uninitialised structures, thanks to David Jade for investigating and flagging up this issue + V1.0.2 -- Modification to allow user-defined pins for I2C operation on the ESP32 + V1.0.3 -- Initialise "device" constructor member variables in the same order they are declared + V1.0.4 -- Fix incorrect oversampling definition for x1, thanks to myval for raising the issue + V1.0.5 -- Modification to allow ESP8266 SPI operation, thanks to Adam9850 for the generating the pull request + V1.0.6 -- Include getErrorReg() and getStatusReg() functions + V1.0.7 -- Fix compilation issue with Arduino Due + V1.0.8 -- Allow for additional TwoWire instances + V1.0.9 -- Fix compilation issue with STM32 Blue Pill + V1.0.10 -- Removed default parameter causing ESP32 compilation error with user defined I2C pins + V1.0.11 -- Fixed uninitialised "Wire" pointer for ESP8266/ESP32 with user defined I2C pins + + The MIT License (MIT) + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#include + +//////////////////////////////////////////////////////////////////////////////// +// BMP388_DEV Class Constructors +//////////////////////////////////////////////////////////////////////////////// + +BMP388_DEV::BMP388_DEV(TwoWire& twoWire) : Device(twoWire) { setI2CAddress(BMP388_I2C_ADDR); } // Constructor for I2C communications +#ifdef ARDUINO_ARCH_ESP8266 +BMP388_DEV::BMP388_DEV(uint8_t sda, uint8_t scl, TwoWire& twoWire) : // Constructor for I2C comms on ESP8266 + Device(sda, scl, twoWire) { setI2CAddress(BMP388_I2C_ADDR); } +#endif +BMP388_DEV::BMP388_DEV(uint8_t cs) : Device(cs) {} // Constructor for SPI communications +#ifdef ARDUINO_ARCH_ESP32 +BMP388_DEV::BMP388_DEV(uint8_t sda, uint8_t scl, TwoWire& twoWire) : // Constructor for I2C comms on ESP32 + Device(sda, scl, twoWire) { setI2CAddress(BMP388_I2C_ADDR); } +BMP388_DEV::BMP388_DEV(uint8_t cs, uint8_t spiPort, SPIClass& spiClass) : Device(cs, spiPort, spiClass) {} // Constructor for SPI communications on the ESP32 +#endif +//////////////////////////////////////////////////////////////////////////////// +// BMP388_DEV Public Member Functions +//////////////////////////////////////////////////////////////////////////////// + +uint8_t BMP388_DEV::begin(Mode mode, // Initialise BMP388 device settings + Oversampling presOversampling, + Oversampling tempOversampling, + IIRFilter iirFilter, + TimeStandby timeStandby) +{ + initialise(); // Call the Device base class "initialise" function + if (!reset()) // Reset the BMP388 barometer + { + return 0; // If unable to reset return 0 + } + + byte chipId = readByte(BMP388_CHIP_ID); // Read the device ID + if (chipId != BMP388_ID && chipId != BMP390_ID) // Check the device ID + { + return 0; // If the ID is incorrect return 0 + } + + readBytes(BMP388_TRIM_PARAMS, (uint8_t*)¶ms, sizeof(params)); // Read the trim parameters into the params structure + floatParams.param_T1 = (float)params.param_T1 / powf(2.0f, -8.0f); // Calculate the floating point trim parameters + floatParams.param_T2 = (float)params.param_T2 / powf(2.0f, 30.0f); + floatParams.param_T3 = (float)params.param_T3 / powf(2.0f, 48.0f); + floatParams.param_P1 = ((float)params.param_P1 - powf(2.0f, 14.0f)) / powf(2.0f, 20.0f); + floatParams.param_P2 = ((float)params.param_P2 - powf(2.0f, 14.0f)) / powf(2.0f, 29.0f); + floatParams.param_P3 = (float)params.param_P3 / powf(2.0f, 32.0f); + floatParams.param_P4 = (float)params.param_P4 / powf(2.0f, 37.0f); + floatParams.param_P5 = (float)params.param_P5 / powf(2.0f, -3.0f); + floatParams.param_P6 = (float)params.param_P6 / powf(2.0f, 6.0f); + floatParams.param_P7 = (float)params.param_P7 / powf(2.0f, 8.0f); + floatParams.param_P8 = (float)params.param_P8 / powf(2.0f, 15.0f); + floatParams.param_P9 = (float)params.param_P9 / powf(2.0f, 48.0f); + floatParams.param_P10 = (float)params.param_P10 / powf(2.0f, 48.0f); + floatParams.param_P11 = (float)params.param_P11 / powf(2.0f, 65.0f); + setIIRFilter(iirFilter); // Initialise the BMP388 IIR filter register + setTimeStandby(timeStandby); // Initialise the BMP388 standby time register + setOversamplingRegister(presOversampling, tempOversampling); // Initialise the BMP388 oversampling register + pwr_ctrl.bit.press_en = 1; // Set power control register to enable pressure sensor + pwr_ctrl.bit.temp_en = 1; // Set power control register to enable temperature sensor + setMode(mode); // Set the BMP388 mode + return 1; // Report successful initialisation +} + +uint8_t BMP388_DEV::begin(Mode mode, uint8_t addr) // Initialise BMP388 with default settings, but selected mode and +{ // I2C address + setI2CAddress(addr); + return begin(mode); +} + +uint8_t BMP388_DEV::begin(uint8_t addr) // Initialise BMP388 with default settings and selected I2C address +{ + setI2CAddress(addr); + return begin(); +} + +uint8_t BMP388_DEV::reset() // Reset the BMP388 barometer +{ + writeByte(BMP388_CMD, RESET_CODE); // Write the reset code to the command register + delay(10); // Wait for 10ms + event.reg = readByte(BMP388_EVENT); // Read the BMP388's event register + return event.bit.por_detected; // Return if device reset is complete +} + +void BMP388_DEV::startNormalConversion() { setMode(NORMAL_MODE); } // Start continuous measurement in NORMAL_MODE + +void BMP388_DEV::startForcedConversion() // Start a one shot measurement in FORCED_MODE +{ + if (pwr_ctrl.bit.mode == SLEEP_MODE) // Only set FORCED_MODE if we're already in SLEEP_MODE + { + setMode(FORCED_MODE); + } +} + +void BMP388_DEV::stopConversion() { setMode(SLEEP_MODE); } // Stop the conversion and return to SLEEP_MODE + +void BMP388_DEV::setPresOversampling(Oversampling presOversampling) // Set the pressure oversampling rate +{ + osr.bit.osr_p = presOversampling; + writeByte(BMP388_OSR, osr.reg); +} + +void BMP388_DEV::setTempOversampling(Oversampling tempOversampling) // Set the temperature oversampling rate +{ + osr.bit.osr_t = tempOversampling; + writeByte(BMP388_OSR, osr.reg); +} + +void BMP388_DEV::setIIRFilter(IIRFilter iirFilter) // Set the IIR filter setting +{ + config.bit.iir_filter = iirFilter; + writeByte(BMP388_CONFIG, config.reg); +} + +void BMP388_DEV::setTimeStandby(TimeStandby timeStandby) // Set the time standby measurement interval +{ + odr.bit.odr_sel = timeStandby; + writeByte(BMP388_ODR, odr.reg); +} + +void BMP388_DEV::setSeaLevelPressure(float pressure) // Set the sea level pressure value +{ + sea_level_pressure = pressure; +} + +uint8_t BMP388_DEV::getTemperature(volatile float &temperature) // Get the temperature +{ + if (!dataReady()) // Check if a measurement is ready + { + return 0; + } + uint8_t data[3]; // Create a data buffer + readBytes(BMP388_DATA_3, &data[0], 3); // Read the temperature + int32_t adcTemp = (int32_t)data[2] << 16 | (int32_t)data[1] << 8 | (int32_t)data[0]; // Copy the temperature data into the adc variables + temperature = bmp388_compensate_temp((float)adcTemp); // Temperature compensation (function from BMP388 datasheet) + return 1; +} + +uint8_t BMP388_DEV::getPressure(volatile float &pressure) // Get the pressure +{ + float temperature; + return getTempPres(temperature, pressure); +} + +uint8_t BMP388_DEV::getTempPres(volatile float &temperature, // Get the temperature and pressure + volatile float &pressure) +{ + if (!dataReady()) // Check if a measurement is ready + { + return 0; + } + uint8_t data[6]; // Create a data buffer + readBytes(BMP388_DATA_0, &data[0], 6); // Read the temperature and pressure data + int32_t adcTemp = (int32_t)data[5] << 16 | (int32_t)data[4] << 8 | (int32_t)data[3]; // Copy the temperature and pressure data into the adc variables + int32_t adcPres = (int32_t)data[2] << 16 | (int32_t)data[1] << 8 | (int32_t)data[0]; + temperature = bmp388_compensate_temp((float)adcTemp); // Temperature compensation (function from BMP388 datasheet) + pressure = bmp388_compensate_press((float)adcPres, temperature); // Pressure compensation (function from BMP388 datasheet) + pressure /= 100.0f; // Calculate the pressure in millibar/hPa + return 1; +} + +uint8_t BMP388_DEV::getAltitude(volatile float &altitude) // Get the altitude +{ + float temperature, pressure; + return getMeasurements(temperature, pressure, altitude); +} + +uint8_t BMP388_DEV::getMeasurements(volatile float &temperature, // Get all measurements temperature, pressure and altitude + volatile float &pressure, + volatile float &altitude) +{ + if (getTempPres(temperature, pressure)) + { + altitude = ((float)powf(sea_level_pressure / pressure, 0.190223f) - 1.0f) * (temperature + 273.15f) / 0.0065f; // Calculate the altitude in metres + return 1; + } + return 0; +} + +void BMP388_DEV::enableInterrupt(OutputDrive outputDrive, // Enable the BMP388's data ready interrupt on the INT pin + ActiveLevel activeLevel, + LatchConfig latchConfig) +{ + int_ctrl.reg = latchConfig << 2 | activeLevel << 1 | outputDrive; + int_ctrl.bit.drdy_en = 1; + writeByte(BMP388_INT_CTRL, int_ctrl.reg); +} + +void BMP388_DEV::disableInterrupt() // Disable the data ready interrupt on the INT pin +{ + int_ctrl.bit.drdy_en = 0; + writeByte(BMP388_INT_CTRL, int_ctrl.reg); +} + +void BMP388_DEV::setIntOutputDrive(OutputDrive outputDrive) // Set the interrupt output drive: PUSH_PULL or OPEN_COLLECTOR +{ + int_ctrl.bit.int_od = outputDrive; + writeByte(BMP388_INT_CTRL, int_ctrl.reg); +} + +void BMP388_DEV::setIntActiveLevel(ActiveLevel activeLevel) // Set the interrupt active level: LOW or HIGH +{ + int_ctrl.bit.int_level = activeLevel; + writeByte(BMP388_INT_CTRL, int_ctrl.reg); +} + +void BMP388_DEV::setIntLatchConfig(LatchConfig latchConfig) // Set the interrupt latch configuration +{ + int_ctrl.bit.int_latch = latchConfig; + writeByte(BMP388_INT_CTRL, int_ctrl.reg); +} + +void BMP388_DEV::enableFIFO(PressEnable pressEnable, // Enable the FIFO + AltEnable altEnable, + TimeEnable timeEnable, + Subsampling subsampling, + DataSelect dataSelect, + StopOnFull stopOnFull) +{ + alt_enable = altEnable; + fifo_config_1.reg = 1 << 4 | pressEnable << 3 | timeEnable << 2 | stopOnFull << 1; + fifo_config_1.bit.fifo_mode = 1; + writeByte(BMP388_FIFO_CONFIG_1, fifo_config_1.reg); + fifo_config_2.reg = dataSelect << 3 | subsampling; + writeByte(BMP388_FIFO_CONFIG_2, fifo_config_2.reg); +} + +void BMP388_DEV::disableFIFO() // Disable the FIFO +{ + fifo_config_1.bit.fifo_mode = 0; + writeByte(BMP388_FIFO_CONFIG_1, fifo_config_1.reg); +} + +uint8_t BMP388_DEV::setFIFONoOfMeasurements(uint16_t noOfMeasurements) // Set the FIFO watermark from the number of measurements +{ + // Calculate the FIFO watermark from the number of measurements + uint16_t fifoWatermark = noOfMeasurements * ((fifo_config_1.bit.fifo_press_en | fifo_config_1.bit.fifo_temp_en) + + 3 * fifo_config_1.bit.fifo_press_en + 3 * fifo_config_1.bit.fifo_temp_en); + return setFIFOWatermark(fifoWatermark); +} + +uint8_t BMP388_DEV::setFIFOWatermark(uint16_t fifoWatermark) // Set the FIFO watermark +{ + if (fifoWatermark + fifo_config_1.bit.fifo_time_en + // Check if the FIFO watermark + appended sensor time (4 bytes) + 3 * fifo_config_1.bit.fifo_time_en + 2 > FIFO_SIZE) // if enabled + 2 byte overhead is larger than the FIFO size of 512 bytes + { + return 0; // FIFO watermark larger than FIFO, return error + } + uint8_t fifoWatermarkLSB = (uint8_t)(fifoWatermark & 0xFF); + uint8_t fifoWatermarkMSB = (uint8_t)(fifoWatermark >> 8 & 0x01); + writeByte(BMP388_FIFO_WTM_0, fifoWatermarkLSB); + writeByte(BMP388_FIFO_WTM_1, fifoWatermarkMSB); + return 1; +} + +uint16_t BMP388_DEV::getFIFOWatermark() // Retrieve the FIFO watermark +{ + uint16_t fifoWatermark; + readBytes(BMP388_FIFO_WTM_0, (uint8_t*)&fifoWatermark, sizeof(fifoWatermark)); + return fifoWatermark; +} + +void BMP388_DEV::setFIFOPressEnable(PressEnable pressEnable) // Enable pressure measurements +{ + fifo_config_1.bit.fifo_press_en = pressEnable; + writeByte(BMP388_FIFO_CONFIG_1, fifo_config_1.reg); +} + +void BMP388_DEV::setFIFOTimeEnable(TimeEnable timeEnable) // Enable sensor time +{ + fifo_config_1.bit.fifo_time_en = timeEnable; + writeByte(BMP388_FIFO_CONFIG_1, fifo_config_1.reg); +} + +void BMP388_DEV::setFIFOSubsampling(Subsampling subsampling) // Set the FIFO sub-sampling rate +{ + fifo_config_2.bit.fifo_subsampling = subsampling; + writeByte(BMP388_FIFO_CONFIG_2, fifo_config_2.reg); +} + +void BMP388_DEV::setFIFODataSelect(DataSelect dataSelect) // Set if the FIFO data is unfiltered or filtered +{ + fifo_config_2.bit.data_select = dataSelect; + writeByte(BMP388_FIFO_CONFIG_2, fifo_config_2.reg); +} + +void BMP388_DEV::setFIFOStopOnFull(StopOnFull stopOnFull) // Set if to stop reading the FIFO when full or overwrite data +{ + fifo_config_1.bit.fifo_stop_on_full = stopOnFull; + writeByte(BMP388_FIFO_CONFIG_1, fifo_config_1.reg); +} + +uint16_t BMP388_DEV::getFIFOLength() // Get the FIFO length +{ + uint16_t fifoLength; + readBytes(BMP388_FIFO_LENGTH_0, (uint8_t*)&fifoLength, sizeof(fifoLength)); + return fifoLength; +} + +FIFOStatus BMP388_DEV::getFIFOData(volatile float *temperature, volatile float *pressure, // Get FIFO data + volatile float *altitude, volatile uint32_t &sensorTime) +{ + if (!fifoReady()) // Check if the FIFO data is ready + { + return DATA_PENDING; // Return if the measurements are pending + } + bool configError = false; // Set the configuration error flag + uint16_t fifoLength = getFIFOLength() + fifo_config_1.bit.fifo_time_en + // Get the FIFO length plus sensor time bits if required + 3 * fifo_config_1.bit.fifo_time_en; + uint16_t count = 0; // Initialise the byte count + uint16_t measCount = 0; // Initialise the measurement count + uint8_t packetSize = (fifo_config_1.bit.fifo_press_en | fifo_config_1.bit.fifo_temp_en) + // Determine the size of the data packets + 3 * fifo_config_1.bit.fifo_press_en + 3 * fifo_config_1.bit.fifo_temp_en; + uint8_t data[MAX_PACKET_SIZE]; // Declare data packet memory + while (count < fifoLength) // Parse the data until the FIFO is empty + { + readBytes(BMP388_FIFO_DATA, &data[0], packetSize); // Acquire the next data packet + uint8_t header = data[0]; // Acquire the data header + int32_t adcTemp, adcPres; // Declare the raw temperature and pressure variables + switch(header) + { + case FIFO_SENSOR_PRESS: // Header indicates that temperature and pressure data follows + adcTemp = (int32_t)data[3] << 16 | (int32_t)data[2] << 8 | (int32_t)data[1]; // Copy the temperature and pressure data into the adc variables + temperature[measCount] = bmp388_compensate_temp((float)adcTemp); // Temperature compensation (function from BMP388 datasheet) + adcPres = (int32_t)data[6] << 16 | (int32_t)data[5] << 8 | (int32_t)data[4]; + pressure[measCount] = bmp388_compensate_press((float)adcPres, temperature[measCount]); // Pressure compensation (function from BMP388 datasheet) + pressure[measCount] /= 100.0f; + if (alt_enable) // Check if altitude measurements have been enabled + { + altitude[measCount] = ((float)powf(sea_level_pressure / pressure[measCount], 0.190223f) - 1.0f) * // Calculate the altitude in metres + (temperature[measCount] + 273.15f) / 0.0065f; + } + count += 6; // Increment the byte count by the size of the data payload + measCount++; // Increment the measurement count + break; + case FIFO_SENSOR_TEMP: // Header indicates that temperature data follows + adcTemp = (int32_t)data[3] << 16 | (int32_t)data[2] << 8 | (int32_t)data[1]; // Copy the temperature and pressure data into the adc variables + temperature[measCount] = bmp388_compensate_temp((float)adcTemp); // Temperature compensation (function from BMP388 datasheet) + count += 3; // Increment the byte count by the size of the data payload + measCount++; // Increment the measurement count + break; + case FIFO_SENSOR_TIME: // Header indicates that sensor time follows + // Sensor time isn't actually stored in the FIFO, but is appended once the FIFO is read + sensorTime = (uint32_t)data[3] << 16 | (uint32_t)data[1] << 8 | (uint32_t)data[1]; // Read the sensor time + count += 3; // Increment the byte count by the size of the data payload + break; + case FIFO_CONFIG_CHANGE: // Header indicates that configuration change or FIFO empty data follows + case FIFO_EMPTY: + count++; // Increment the byte count + break; + case FIFO_CONFIG_ERROR: + configError = true; // Set the configuration error flag + count++; // Increment the byte count + break; + default: + break; + } + } + return configError ? CONFIG_ERROR : DATA_READY; // Indicate that the measurements are ready, (or if a config error occured) +} + +void BMP388_DEV::enableFIFOInterrupt(OutputDrive outputDrive, // Enable the BMP388's FIFO interrupts on the INT pin + ActiveLevel activeLevel, + LatchConfig latchConfig) +{ + int_ctrl.reg = latchConfig << 2 | activeLevel << 1 | outputDrive; + int_ctrl.bit.fwtm_en = 1; + int_ctrl.bit.ffull_en = 1; + writeByte(BMP388_INT_CTRL, int_ctrl.reg); +} + +void BMP388_DEV::disableFIFOInterrupt() // Disable the FIFO interrupts on the INT pin +{ + int_ctrl.bit.fwtm_en = 0; + int_ctrl.bit.ffull_en = 0; + writeByte(BMP388_INT_CTRL, int_ctrl.reg); +} + +void BMP388_DEV::flushFIFO() // Flush the FIFO +{ + writeByte(BMP388_CMD, FIFO_FLUSH); +} + +uint32_t BMP388_DEV::getSensorTime() // Get the sensor time +{ + uint32_t sensorTime; + readBytes(BMP388_SENSORTIME_0, (uint8_t*)&sensorTime, sizeof(sensorTime - 1)); + return sensorTime & 0x00FFFFFF; +} + +void BMP388_DEV::enableI2CWatchdog() // Enable the I2C watchdog +{ + if_conf.bit.i2c_wdt_en = 1; + writeByte(BMP388_IF_CONFIG, if_conf.reg); +} + +void BMP388_DEV::disableI2CWatchdog() // Disable the I2C watchdog +{ + if_conf.bit.i2c_wdt_en = 0; + writeByte(BMP388_IF_CONFIG, if_conf.reg); +} + +void BMP388_DEV::setI2CWatchdogTimout(WatchdogTimout watchdogTimeout) // Set the I2C watchdog time-out: 1.25ms or 40ms +{ + if_conf.bit.i2c_wdt_sel = watchdogTimeout; + writeByte(BMP388_IF_CONFIG, if_conf.reg); +} + +uint8_t BMP388_DEV::getErrorReg() // Read the error register +{ + return readByte(BMP388_ERR_REG); +} + +uint8_t BMP388_DEV::getStatusReg() // Read the status register +{ + return readByte(BMP388_STATUS); +} + +//////////////////////////////////////////////////////////////////////////////// +// BMP388_DEV Private Member Functions +//////////////////////////////////////////////////////////////////////////////// + +void BMP388_DEV::setMode(Mode mode) // Set the BMP388's mode in the power control register +{ + pwr_ctrl.bit.mode = mode; + writeByte(BMP388_PWR_CTRL, pwr_ctrl.reg); +} + +void BMP388_DEV::setOversamplingRegister(Oversampling presOversampling, // Set the BMP388 oversampling register + Oversampling tempOversampling) +{ + osr.reg = tempOversampling << 3 | presOversampling; + writeByte(BMP388_OSR, osr.reg); +} + +uint8_t BMP388_DEV::dataReady() // Check if measurement data is ready +{ + if (pwr_ctrl.bit.mode == SLEEP_MODE) // If we're in SLEEP_MODE return immediately + { + return 0; + } + int_status.reg = readByte(BMP388_INT_STATUS); // Read the interrupt status register + if (int_status.bit.drdy) // Check if the data ready flag has been cleared + { + if (pwr_ctrl.bit.mode == FORCED_MODE) // If we're in FORCED_MODE switch back to SLEEP_MODE + { + pwr_ctrl.bit.mode = SLEEP_MODE; + } + return 1; // The measurement is ready + } + return 0; // The measurement is still pending +} + +uint8_t BMP388_DEV::fifoReady() // Check if the FIFO data is ready +{ + return dataReady() && int_status.bit.fwm_int ? 1 : 0; // Return 1 if a FIFO measurement is ready, otherwise 0 +} + +//////////////////////////////////////////////////////////////////////////////// +// Bosch BMP388_DEV (Private) Member Functions +//////////////////////////////////////////////////////////////////////////////// + +float BMP388_DEV::bmp388_compensate_temp(float uncomp_temp) +{ + float partial_data1 = uncomp_temp - floatParams.param_T1; + float partial_data2 = partial_data1 * floatParams.param_T2; + return partial_data2 + partial_data1 * partial_data1 * floatParams.param_T3; +} + +float BMP388_DEV::bmp388_compensate_press(float uncomp_press, float t_lin) +{ + float partial_data1 = floatParams.param_P6 * t_lin; + float partial_data2 = floatParams.param_P7 * t_lin * t_lin; + float partial_data3 = floatParams.param_P8 * t_lin * t_lin * t_lin; + float partial_out1 = floatParams.param_P5 + partial_data1 + partial_data2 + partial_data3; + partial_data1 = floatParams.param_P2 * t_lin; + partial_data2 = floatParams.param_P3 * t_lin * t_lin; + partial_data3 = floatParams.param_P4 * t_lin * t_lin * t_lin; + float partial_out2 = uncomp_press * (floatParams.param_P1 + + partial_data1 + partial_data2 + partial_data3); + partial_data1 = uncomp_press * uncomp_press; + partial_data2 = floatParams.param_P9 + floatParams.param_P10 * t_lin; + partial_data3 = partial_data1 * partial_data2; + float partial_data4 = partial_data3 + uncomp_press * uncomp_press * uncomp_press * floatParams.param_P11; + return partial_out1 + partial_out2 + partial_data4; +} diff --git a/BMP388_DEV/BMP388_DEV.h b/BMP388_DEV/BMP388_DEV.h new file mode 100644 index 0000000..196b245 --- /dev/null +++ b/BMP388_DEV/BMP388_DEV.h @@ -0,0 +1,461 @@ +/* + BMP388_DEV is an I2C/SPI compatible library for the Bosch BMP388 barometer. + + Copyright (C) Martin Lindupp 2020 + + V1.0.0 -- Initial release + V1.0.1 -- Fix uninitialised structures, thanks to David Jade for investigating and flagging up this issue + V1.0.2 -- Modification to allow user-defined pins for I2C operation on the ESP32 + V1.0.3 -- Initialise "device" constructor member variables in the same order they are declared + V1.0.4 -- Fix incorrect oversampling definition for x1, thanks to myval for raising the issue + V1.0.5 -- Modification to allow ESP8266 SPI operation, thanks to Adam9850 for the generating the pull request + V1.0.6 -- Include getErrorReg() and getStatusReg() functions + V1.0.7 -- Fix compilation issue with Arduino Due + V1.0.8 -- Allow for additional TwoWire instances + V1.0.9 -- Fix compilation issue with STM32 Blue Pill + V1.0.10 -- Removed default parameter causing ESP32 compilation error with user defined I2C pins + V1.0.11 -- Fixed uninitialised "Wire" pointer for ESP8266/ESP32 with user defined I2C pins + + The MIT License (MIT) + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#ifndef BMP388_DEV_h +#define BMP388_DEV_h + +#include + +//////////////////////////////////////////////////////////////////////////////// +// BMP388_DEV Definitions +//////////////////////////////////////////////////////////////////////////////// + +#define BMP388_I2C_ADDR 0x77 // The BMP388 I2C address +#define BMP388_I2C_ALT_ADDR 0x76 // The BMP388 I2C alternate address +#define BMP388_ID 0x50 // The BMP388 device ID +#define BMP390_ID 0x60 // The BMP390 device ID +#define RESET_CODE 0xB6 // The BMP388 reset code +#define FIFO_FLUSH 0xB0 // The BMP388 flush FIFO code + +enum SPIPort { BMP388_SPI0, BMP388_SPI1 }; + +//////////////////////////////////////////////////////////////////////////////// +// BMP388_DEV Registers +//////////////////////////////////////////////////////////////////////////////// + +enum { + BMP388_CHIP_ID = 0x00, // Chip ID register sub-address + BMP388_ERR_REG = 0x02, // Error register sub-address + BMP388_STATUS = 0x03, // Status register sub-address + BMP388_DATA_0 = 0x04, // Pressure eXtended Least Significant Byte (XLSB) register sub-address + BMP388_DATA_1 = 0x05, // Pressure Least Significant Byte (LSB) register sub-address + BMP388_DATA_2 = 0x06, // Pressure Most Significant Byte (MSB) register sub-address + BMP388_DATA_3 = 0x07, // Temperature eXtended Least Significant Byte (XLSB) register sub-address + BMP388_DATA_4 = 0x08, // Temperature Least Significant Byte (LSB) register sub-address + BMP388_DATA_5 = 0x09, // Temperature Most Significant Byte (MSB) register sub-address + BMP388_SENSORTIME_0 = 0x0C, // Sensor time register 0 sub-address + BMP388_SENSORTIME_1 = 0x0D, // Sensor time register 1 sub-address + BMP388_SENSORTIME_2 = 0x0E, // Sensor time register 2 sub-address + BMP388_EVENT = 0x10, // Event register sub-address + BMP388_INT_STATUS = 0x11, // Interrupt Status register sub-address + BMP388_FIFO_LENGTH_0 = 0x12, // FIFO Length Least Significant Byte (LSB) register sub-address + BMP388_FIFO_LENGTH_1 = 0x13, // FIFO Length Most Significant Byte (MSB) register sub-address + BMP388_FIFO_DATA = 0x14, // FIFO Data register sub-address + BMP388_FIFO_WTM_0 = 0x15, // FIFO Water Mark Least Significant Byte (LSB) register sub-address + BMP388_FIFO_WTM_1 = 0x16, // FIFO Water Mark Most Significant Byte (MSB) register sub-address + BMP388_FIFO_CONFIG_1 = 0x17, // FIFO Configuration 1 register sub-address + BMP388_FIFO_CONFIG_2 = 0x18, // FIFO Configuration 2 register sub-address + BMP388_INT_CTRL = 0x19, // Interrupt Control register sub-address + BMP388_IF_CONFIG = 0x1A, // Interface Configuration register sub-address + BMP388_PWR_CTRL = 0x1B, // Power Control register sub-address + BMP388_OSR = 0x1C, // Oversampling register sub-address + BMP388_ODR = 0x1D, // Output Data Rate register sub-address + BMP388_CONFIG = 0x1F, // Configuration register sub-address + BMP388_TRIM_PARAMS = 0x31, // Trim parameter registers' base sub-address + BMP388_CMD = 0x7E // Command register sub-address +}; + +//////////////////////////////////////////////////////////////////////////////// +// BMP388_DEV Modes +//////////////////////////////////////////////////////////////////////////////// + +enum Mode { + SLEEP_MODE = 0x00, // Device mode bitfield in the control and measurement register + FORCED_MODE = 0x01, + NORMAL_MODE = 0x03 +}; + +//////////////////////////////////////////////////////////////////////////////// +// BMP388_DEV Register bit field Definitions +//////////////////////////////////////////////////////////////////////////////// + +enum Oversampling { + OVERSAMPLING_SKIP = 0x00, // Oversampling bit fields in the control and measurement register + OVERSAMPLING_X2 = 0x01, + OVERSAMPLING_X4 = 0x02, + OVERSAMPLING_X8 = 0x03, + OVERSAMPLING_X16 = 0x04, + OVERSAMPLING_X32 = 0x05 +}; + +enum IIRFilter { + IIR_FILTER_OFF = 0x00, // Infinite Impulse Response (IIR) filter bit field in the configuration register + IIR_FILTER_2 = 0x01, + IIR_FILTER_4 = 0x02, + IIR_FILTER_8 = 0x03, + IIR_FILTER_16 = 0x04, + IIR_FILTER_32 = 0x05, + IIR_FILTER_64 = 0x06, + IIR_FILTER_128 = 0x07 +}; + +enum TimeStandby { + TIME_STANDBY_5MS = 0x00, // Time standby bit field in the Output Data Rate (ODR) register + TIME_STANDBY_10MS = 0x01, + TIME_STANDBY_20MS = 0x02, + TIME_STANDBY_40MS = 0x03, + TIME_STANDBY_80MS = 0x04, + TIME_STANDBY_160MS = 0x05, + TIME_STANDBY_320MS = 0x06, + TIME_STANDBY_640MS = 0x07, + TIME_STANDBY_1280MS = 0x08, + TIME_STANDBY_2560MS = 0x09, + TIME_STANDBY_5120MS = 0x0A, + TIME_STANDBY_10240MS = 0x0B, + TIME_STANDBY_20480MS = 0x0C, + TIME_STANDBY_40960MS = 0x0D, + TIME_STANDBY_81920MS = 0x0E, + TIME_STANDBY_163840MS = 0x0F, + TIME_STANDBY_327680MS = 0x10, + TIME_STANDBY_655360MS = 0x11 +}; + +enum OutputDrive { // Interrupt output drive configuration + PUSH_PULL = 0x00, + OPEN_COLLECTOR = 0x01 +}; + +enum ActiveLevel { // Interrupt output active level configuration + ACTIVE_LOW = 0x00, + ACTIVE_HIGH = 0x01 +}; + +enum LatchConfig { // Interrupt output latch configuration + UNLATCHED = 0x00, // UNLATCHED: interrupt automatically clears after 2.5ms + LATCHED = 0x01 // LATCHED : interrupt requires INT_STATUS register read to clear +}; + +enum PressEnable { // FIFO pressure enable configuration + PRESS_DISABLED = 0x00, + PRESS_ENABLED = 0x01 +}; + +enum AltEnable { // FIFO altitude enable configuration + ALT_DISABLED = 0x00, + ALT_ENABLED = 0x01 +}; + +enum TimeEnable { // FIFO time enable configuration + TIME_DISABLED = 0x00, + TIME_ENABLED = 0x01 +}; + +enum Subsampling { // FIFO sub-sampling configuration + SUBSAMPLING_OFF = 0x00, + SUBSAMPLING_DIV2 = 0x01, + SUBSAMPLING_DIV4 = 0x02, + SUBSAMPLING_DIV8 = 0x03, + SUBSAMPLING_DIV16 = 0x04, + SUBSAMPLING_DIV32 = 0x05, + SUBSAMPLING_DIV64 = 0x06, + SUBSAMPLING_DIV128 = 0x07 +}; + +enum DataSelect { // FIFO data select configuration + UNFILTERED = 0x00, + FILTERED = 0x01 +}; + +enum StopOnFull { // FIFO stop on full configuration + STOP_ON_FULL_DISABLED = 0x00, + STOP_ON_FULL_ENABLED = 0x01 +}; + +enum FIFOStatus { // FIFO status + DATA_PENDING = 0x00, + DATA_READY = 0X01, + CONFIG_ERROR = 0x02 +}; + +enum WatchdogTimout { // I2C watchdog time-out + WATCHDOG_TIMEOUT_1MS = 0x00, + WATCHDOG_TIMEOUT_40MS = 0x01 +}; + +//////////////////////////////////////////////////////////////////////////////// +// BMP388_DEV Class declaration +//////////////////////////////////////////////////////////////////////////////// + +class BMP388_DEV : public Device { // Derive the BMP388_DEV class from the Device class + public: + BMP388_DEV(TwoWire& twoWire = Wire); // BMP388_DEV object for I2C operation +#ifdef ARDUINO_ARCH_ESP8266 + BMP388_DEV(uint8_t sda, uint8_t scl, TwoWire& twoWire = Wire); // BMP388_DEV object for ESP8266 I2C operation with user-defined pins +#endif + BMP388_DEV(uint8_t cs); // BMP388_DEV object for SPI operation +#ifdef ARDUINO_ARCH_ESP32 + BMP388_DEV(uint8_t sda, uint8_t scl, TwoWire& twoWire = Wire); // BMP388_DEV object for ESP32 I2C operation with user-defined pins + BMP388_DEV(uint8_t cs, uint8_t spiPort, SPIClass& spiClass); // BMP388_DEV object for SPI1 with supplied SPIClass object +#endif + uint8_t begin(Mode mode = SLEEP_MODE, // Initialise the barometer with arguments + Oversampling presOversampling = OVERSAMPLING_X16, + Oversampling tempOversampling = OVERSAMPLING_X2, + IIRFilter iirFilter = IIR_FILTER_OFF, + TimeStandby timeStandby = TIME_STANDBY_5MS); + uint8_t begin(Mode mode, uint8_t addr); // Initialise the barometer specifying start mode and I2C addrss + uint8_t begin(uint8_t addr); // Initialise the barometer specifying I2C address with default initialisation + uint8_t reset(); // Soft reset the barometer + void startNormalConversion(); // Start continuous measurement in NORMAL_MODE + void startForcedConversion(); // Start a one shot measurement in FORCED_MODE + void stopConversion(); // Stop the conversion and return to SLEEP_MODE + void setPresOversampling(Oversampling presOversampling); // Set the pressure oversampling: OFF, X1, X2, X4, X8, X16, X32 + void setTempOversampling(Oversampling tempOversampling); // Set the temperature oversampling: OFF, X1, X2, X4, X8, X16, X32 + void setIIRFilter(IIRFilter iirFilter); // Set the IIR filter setting: OFF, 2, 3, 8, 16, 32 + void setTimeStandby(TimeStandby timeStandby); // Set the time standby measurement interval: 5, 62, 125, 250, 500ms, 1s, 2s, 4s + void setSeaLevelPressure(float pressure = 1013.23f); // Set the sea level pressure value + uint8_t getTemperature(volatile float &temperature); // Get a temperature measurement + uint8_t getPressure(volatile float &pressure); // Get a pressure measurement + uint8_t getTempPres(volatile float &temperature, // Get a temperature and pressure measurement + volatile float &pressure); + uint8_t getAltitude(volatile float &altitude); // Get an altitude measurement + uint8_t getMeasurements(volatile float &temperature, // Get temperature, pressure and altitude measurements + volatile float &pressure, + volatile float &altitude); + void enableInterrupt(OutputDrive outputDrive = PUSH_PULL, // Enable the BMP388's interrupt pin + ActiveLevel activeLevel = ACTIVE_HIGH, + LatchConfig latchConfig = UNLATCHED); + void disableInterrupt(); // Disable the BMP388's interrupt pin + void setIntOutputDrive(OutputDrive outputDrive); // Sets the interrupt pin's output drive, PUSH_PULL OR OPEN_DRAIN, default PUSH_PULL + void setIntActiveLevel(ActiveLevel activeLevel); // Set the interrupt active level, ACTIVE_LOW or ACTIVE_HIGH, default ACTIVE_HIGH + void setIntLatchConfig(LatchConfig latchConfig); // Set the interrupt latch, UNLATCHED or LATCHED, default UNLATCHED + void enableFIFO(PressEnable pressEnable = PRESS_ENABLED, // Enable the FIFO + AltEnable altEnable = ALT_ENABLED, + TimeEnable timeEnable = TIME_ENABLED, + Subsampling subsampling = SUBSAMPLING_OFF, + DataSelect dataSelect = FILTERED, + StopOnFull stopOnFull = STOP_ON_FULL_ENABLED); + void disableFIFO(); // Disable the FIFO + uint8_t setFIFONoOfMeasurements(uint16_t noOfMeaurements); // Calculate the FIFO watermark from the number of measurements + uint8_t setFIFOWatermark(uint16_t fifoWatermark); // Set the FIFO watermark directly + uint16_t getFIFOWatermark(); // Get the FIFO watermark + void setFIFOPressEnable(PressEnable pressEnable); // Set the FIFO pressure enable configuration + void setFIFOTimeEnable(TimeEnable timeEnable); // Set the FIFO time enable configuration + void setFIFOSubsampling(Subsampling subsampling); // Set the FIFO sub-sampling rate + void setFIFODataSelect(DataSelect dataSelect); // Set the if the FIFO data is unfiltered or filtered + void setFIFOStopOnFull(StopOnFull stopOnFull); // Set the FIFO stop on full configuration + uint16_t getFIFOLength(); // Get the FIFO length + FIFOStatus getFIFOData(volatile float *temperature, // Get FIFO data + volatile float *pressure, + volatile float *altitude, + volatile uint32_t &sensorTime); + void enableFIFOInterrupt(OutputDrive outputDrive = PUSH_PULL, // Enable FIFO interrupt + ActiveLevel activeLevel = ACTIVE_HIGH, + LatchConfig latchConfig = UNLATCHED); + void disableFIFOInterrupt(); // Disable FIFO interrupt + void flushFIFO(); // Flush the FIFO + uint32_t getSensorTime(); // Get the BMP388 sensor time + void enableI2CWatchdog(); // Enable the I2C watchdog timer + void disableI2CWatchdog(); // Disable the I2C watchdog timer + void setI2CWatchdogTimout(WatchdogTimout watchdogTimeout); // Set the watchdog time-out: 1.25ms or 40ms + uint8_t getErrorReg(); // Read the error register + uint8_t getStatusReg(); // Read the status register + protected: + private: + void setMode(Mode mode); // Set the barometer mode + void setOversamplingRegister(Oversampling presOversampling, // Set the BMP388 oversampling register + Oversampling tempOversamping); + uint8_t dataReady(); // Checks if a measurement is ready + uint8_t fifoReady(); // Checks if the data FIFO is ready + + enum HeaderCode { // FIFO header codes + FIFO_EMPTY = 0x80, + FIFO_CONFIG_ERROR = 0x44, + FIFO_CONFIG_CHANGE = 0x48, + FIFO_SENSOR_TIME = 0xA0, + FIFO_SENSOR_TEMP = 0x90, + FIFO_SENSOR_PRESS = 0x94 + }; + + struct { // The BMP388 compensation trim parameters (coefficients) + uint16_t param_T1; + uint16_t param_T2; + int8_t param_T3; + int16_t param_P1; + int16_t param_P2; + int8_t param_P3; + int8_t param_P4; + uint16_t param_P5; + uint16_t param_P6; + int8_t param_P7; + int8_t param_P8; + int16_t param_P9; + int8_t param_P10; + int8_t param_P11; + } __attribute__ ((packed)) params; + + struct FloatParams { // The BMP388 float point compensation trim parameters + float param_T1; + float param_T2; + float param_T3; + float param_P1; + float param_P2; + float param_P3; + float param_P4; + float param_P5; + float param_P6; + float param_P7; + float param_P8; + float param_P9; + float param_P10; + float param_P11; + } floatParams; + + union { // Copy of the BMP388's chip id register + struct { + uint8_t chip_id_nvm : 4; + uint8_t chip_id_fixed : 4; + } bit; + uint8_t reg; + } chip_id = { .reg = 0 }; + + /*union { // Copy of the BMP388's error register + struct { + uint8_t fatal_err : 1; + uint8_t cmd_err : 1; + uint8_t ctrl_err : 1; + } bit; + uint8_t reg; + } err_reg = { .reg = 0 }; + + union { // Copy of the BMP388's status register + struct { + uint8_t : 4; + uint8_t cmd_rdy : 1; + uint8_t press_rdy : 1; + uint8_t temp_rdy : 1; + } bit; + uint8_t reg; + } status = { .reg = 0 };*/ + + union { // Copy of the BMP388's event register + struct { + uint8_t por_detected : 1; + } bit; + uint8_t reg; + } event = { .reg = 0 }; + + volatile union { // Copy of the BMP388's interrupt status register + struct { + uint8_t fwm_int : 1; + uint8_t ffull_int : 1; + uint8_t : 1; + uint8_t drdy : 1; + } bit; + uint8_t reg; + } int_status = { .reg = 0 }; + + union { // Copy of the BMP388's FIFO configuration register 1 + struct { + uint8_t fifo_mode : 1; + uint8_t fifo_stop_on_full : 1; + uint8_t fifo_time_en : 1; + uint8_t fifo_press_en : 1; + uint8_t fifo_temp_en : 1; + } bit; + uint8_t reg; + } fifo_config_1 = { .reg = 0 }; + + union { // Copy of the BMP388's FIFO configuration register 2 + struct { + uint8_t fifo_subsampling : 3; + uint8_t data_select : 3; + } bit; + uint8_t reg; + } fifo_config_2 = { .reg = 0 }; + + union { // Copy of the BMP388's interrupt control register + struct { + uint8_t int_od : 1; + uint8_t int_level : 1; + uint8_t int_latch : 1; + uint8_t fwtm_en : 1; + uint8_t ffull_en : 1; + uint8_t : 1; + uint8_t drdy_en : 1; + } bit; + uint8_t reg; + } int_ctrl = { .reg = 0 }; + + union { // Copy of the BMP388's interface configuration register + struct { + uint8_t spi3 : 1; + uint8_t i2c_wdt_en : 1; + uint8_t i2c_wdt_sel : 1; + } bit; + uint8_t reg; + } if_conf = { .reg = 0 }; + + volatile union { // Copy of the BMP388's power control register + struct { + uint8_t press_en : 1; + uint8_t temp_en : 1; + uint8_t : 2; + uint8_t mode : 2; + } bit; + uint8_t reg; + } pwr_ctrl = { .reg = 0 }; + + union { // Copy of the BMP388's oversampling register + struct { + uint8_t osr_p : 3; + uint8_t osr_t : 3; + } bit; + uint8_t reg; + } osr = { .reg = 0 }; + + union { // Copy of the BMP388's output data rate register + struct { + uint8_t odr_sel : 5; + } bit; + uint8_t reg; + } odr = { .reg = 0 }; + + union { // Copy of the BMP388's configuration register + struct { + uint8_t : 1; + uint8_t iir_filter : 3; + } bit; + uint8_t reg; + } config = { .reg = 0 }; + + float bmp388_compensate_temp(float uncomp_temp); // Bosch temperature compensation function + float bmp388_compensate_press(float uncomp_press, float t_lin); // Bosch pressure compensation function + volatile bool alt_enable; // Altitude enable flag + const uint16_t FIFO_SIZE = 0x01FF; // The BMP388 FIFO size 512 bytes + const uint8_t MAX_PACKET_SIZE = 7; // The BMP388 maximum FIFO packet size in bytes + float sea_level_pressure = 1013.23f; // Pressure at sea level +}; +#endif diff --git a/BMP388_DEV/Device.cpp b/BMP388_DEV/Device.cpp new file mode 100644 index 0000000..c9682b8 --- /dev/null +++ b/BMP388_DEV/Device.cpp @@ -0,0 +1,195 @@ +/* + Device is an I2C/SPI compatible base class library. + + Copyright (C) Martin Lindupp 2020 + + V1.0.0 -- Initial release + V1.0.1 -- Modification to allow user-defined pins for I2C operation on the ESP8266 + V1.0.2 -- Modification to allow user-defined pins for I2C operation on the ESP32 + V1.0.3 -- Initialise "device" constructor member variables in the same order they are declared + V1.0.4 -- Fix incorrect oversampling definition for x1, thanks to myval for raising the issue + V1.0.5 -- Modification to allow ESP8266 SPI operation, thanks to Adam9850 for the generating the pull request + V1.0.6 -- Fix compilation issue with Arduino Due + V1.0.7 -- Allow for additional TwoWire instances + V1.0.8 -- Fix compilation issue with STM32 Blue Pill + V1.0.9 -- Fixed uninitialised "Wire" pointer for ESP8266/ESP32 with user defined I2C pins + + The MIT License (MIT) + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#include + +//////////////////////////////////////////////////////////////////////////////// +// Device Class Constructors +//////////////////////////////////////////////////////////////////////////////// + +Device::Device(TwoWire& twoWire) : comms(I2C_COMMS), i2c(&twoWire) {} // Initialise constructor for I2C communications +#ifdef ARDUINO_ARCH_ESP8266 +Device::Device(uint8_t sda, uint8_t scl, TwoWire& twoWire) : // Constructor for ESP8266 I2C with user-defined pins + comms(I2C_COMMS_DEFINED_PINS), i2c(&twoWire), sda(sda), scl(scl) {} +#endif +Device::Device(uint8_t cs) : comms(SPI_COMMS), cs(cs), spiClockSpeed(1000000) {} // Constructor for SPI communications +#ifdef ARDUINO_ARCH_ESP32 +Device::Device(uint8_t sda, uint8_t scl, TwoWire& twoWire) : // Constructor for ESP32 I2C with user-defined pins + comms(I2C_COMMS_DEFINED_PINS), i2c(&twoWire), sda(sda), scl(scl) {} +Device::Device(uint8_t cs, uint8_t spiPort, SPIClass& spiClass) // Constructor for ESP32 HSPI communications + : comms(SPI_COMMS), cs(cs), spiPort(spiPort), spi(&spiClass), spiClockSpeed(1000000) {} +#endif + +//////////////////////////////////////////////////////////////////////////////// +// Device Public Member Function +//////////////////////////////////////////////////////////////////////////////// + +void Device::setClock(uint32_t clockSpeed) // Set the I2C or SPI clock speed +{ + if (comms == I2C_COMMS) + { + i2c->setClock(clockSpeed); + } + else + { + spiClockSpeed = clockSpeed; + } +} + +#if !defined ARDUINO_ARCH_ESP8266 && !defined ARDUINO_ARCH_ESP32 && !defined ARDUINO_SAM_DUE && !defined STM32F1 +void Device::usingInterrupt(uint8_t pinNumber) // Wrapper for the SPI usingInterrupt() function +{ + spi->usingInterrupt(pinNumber); +} + +void Device::notUsingInterrupt(uint8_t pinNumber) // Wrapper for the SPI notUsingInterrupt() function +{ + spi->notUsingInterrupt(pinNumber); +} +#endif + +//////////////////////////////////////////////////////////////////////////////// +// Device I2C & SPI Wrapper (Protected) Member Functions +//////////////////////////////////////////////////////////////////////////////// + +void Device::initialise() // Initialise device communications +{ + if (comms == I2C_COMMS) // Check with communications bus has been selected I2C or SPI + { + i2c->begin(); // Initialise I2C communication + i2c->setClock(400000); // Set the SCL clock to default of 400kHz + } +#if defined ARDUINO_ARCH_ESP8266 || defined ARDUINO_ARCH_ESP32 + else if (comms == I2C_COMMS_DEFINED_PINS) // Check if the ESP8266 has specified user-defined I2C pins + { + i2c->begin(sda, scl); // Initialise I2C communication with user-defined pins + i2c->setClock(400000); // Set the SCL clock to default of 400kHz + comms = I2C_COMMS; // Set the communications to standard I2C + } +#endif + else + { + digitalWrite(cs, HIGH); // Pull the chip select (CS) pin high + pinMode(cs, OUTPUT); // Set-up the SPI chip select pin +#ifdef ARDUINO_ARCH_ESP32 + if (spiPort == HSPI) // Set-up spi pointer for VSPI or HSPI communications + { + spi->begin(14, 27, 13, 2); // Start HSPI on SCK 14, MOSI 13, MISO 24, SS CS (GPIO2 acts as dummy pin) + } + else + { + spi = &SPI; // Start VSPI on SCK 5, MOSI 18, MISO 19, SS CS + spi->begin(); + } +#else + spi = &SPI; // Set-up spi pointer for SPI communications + spi->begin(); +#endif + } +} + +void Device::setI2CAddress(uint8_t addr) // Set the Device's I2C address +{ + address = addr; +} + +void Device::writeByte(uint8_t subAddress, uint8_t data) +{ + if (comms == I2C_COMMS) + { + i2c->beginTransmission(address); // Write a byte to the sub-address using I2C + i2c->write(subAddress); + i2c->write(data); + i2c->endTransmission(); + } + else // if (comms == SPI_COMMS) + { + spi->beginTransaction(SPISettings(spiClockSpeed, MSBFIRST, SPI_MODE0)); // Write a byte to the sub-address using SPI + digitalWrite(cs, LOW); + spi->transfer(subAddress & WRITE_MASK); + spi->transfer(data); + digitalWrite(cs, HIGH); + spi->endTransaction(); + } +} + +uint8_t Device::readByte(uint8_t subAddress) // Read a byte from the sub-address using I2C +{ + uint8_t data = 0x00; + if (comms == I2C_COMMS) + { + i2c->beginTransmission(address); + i2c->write(subAddress); + i2c->endTransmission(false); + i2c->requestFrom(address, (uint8_t)1); + data = i2c->read(); + } + else // if (comms == SPI_COMMS) + { + spi->beginTransaction(SPISettings(spiClockSpeed, MSBFIRST, SPI_MODE0)); // Read a byte from the sub-address using SPI + digitalWrite(cs, LOW); + spi->transfer(subAddress | READ_MASK); + spi->transfer(0x00); // Read dummy byte required by BMP388 for SPI + data = spi->transfer(data); + digitalWrite(cs, HIGH); + spi->endTransaction(); + } + return data; // Return data read from sub-address register +} + +void Device::readBytes(uint8_t subAddress, uint8_t* data, uint16_t count) +{ + if (comms == I2C_COMMS) // Read "count" bytes into the "data" buffer using I2C + { + i2c->beginTransmission(address); + i2c->write(subAddress); + i2c->endTransmission(false); + uint8_t i = 0; + i2c->requestFrom(address, (uint8_t)count); + while (i2c->available()) + { + data[i++] = i2c->read(); + } + } + else // if (comms == SPI_COMMS) + { + spi->beginTransaction(SPISettings(spiClockSpeed, MSBFIRST, SPI_MODE0)); // Read "count" bytes into the "data" buffer using SPI + digitalWrite(cs, LOW); + spi->transfer(subAddress | READ_MASK); + spi->transfer(0x00); // Read dummy byte required by BMP388 for SPI + spi->transfer(data, count); + digitalWrite(cs, HIGH); + spi->endTransaction(); + } +} diff --git a/BMP388_DEV/Device.h b/BMP388_DEV/Device.h new file mode 100644 index 0000000..a355f44 --- /dev/null +++ b/BMP388_DEV/Device.h @@ -0,0 +1,94 @@ +/* + Device is an I2C/SPI compatible base class library. + + Copyright (C) Martin Lindupp 2020 + + V1.0.0 -- Initial release + V1.0.1 -- Modification to allow user-defined pins for I2C operation on the ESP8266 + V1.0.2 -- Modification to allow user-defined pins for I2C operation on the ESP32 + V1.0.3 -- Initialise "device" constructor member variables in the same order they are declared + V1.0.4 -- Fix incorrect oversampling definition for x1, thanks to myval for raising the issue + V1.0.5 -- Modification to allow ESP8266 SPI operation, thanks to Adam9850 for the generating the pull request + V1.0.6 -- Fix compilation issue with Arduino Due + V1.0.7 -- Allow for additional TwoWire instances + V1.0.8 -- Fix compilation issue with STM32 Blue Pill + V1.0.9 -- Fixed uninitialised "Wire" pointer for ESP8266/ESP32 with user defined I2C pins + + The MIT License (MIT) + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#ifndef Device_h +#define Device_h + +#include +#include +#include + +//////////////////////////////////////////////////////////////////////////////// +// Device Communications +//////////////////////////////////////////////////////////////////////////////// + +#if defined ARDUINO_ARCH_ESP8266 || defined ARDUINO_ARCH_ESP32 +enum Comms { I2C_COMMS, SPI_COMMS, I2C_COMMS_DEFINED_PINS }; +#else +enum Comms { I2C_COMMS, SPI_COMMS }; +#endif + +//////////////////////////////////////////////////////////////////////////////// +// Device Class definition +//////////////////////////////////////////////////////////////////////////////// + +class Device{ + public: + Device(TwoWire& twoWire); // Device object for I2C operation +#ifdef ARDUINO_ARCH_ESP8266 + Device(uint8_t sda, uint8_t scl, TwoWire& twoWire); // Device object for ESP8266 I2C operation with user-defined pins +#endif + Device(uint8_t cs); // Device object for SPI operation +#ifdef ARDUINO_ARCH_ESP32 + Device(uint8_t sda, uint8_t scl, TwoWire& twoWire); // Device object for ESP32 I2C operation with user-defined pins + Device(uint8_t cs, uint8_t spiPort, SPIClass& spiClass); // Device object for ESP32 HSPI operation with supplied SPI object +#endif + void setClock(uint32_t clockSpeed); // Set the I2C/SPI clock speed +#if !defined ARDUINO_ARCH_ESP8266 && !defined ARDUINO_ARCH_ESP32 && !defined ARDUINO_SAM_DUE && !defined STM32F1 + void usingInterrupt(uint8_t pinNumber); // Wrapper for the SPI.usingInterrupt() function + void notUsingInterrupt(uint8_t pinNumber); // Wrapper for the SPI.notUsingInterrupt() function +#endif + protected: + void initialise(); // Initialise communications + void setI2CAddress(uint8_t addr); // Set the Device I2C address + void writeByte(uint8_t subAddress, uint8_t data); // I2C and SPI write byte wrapper function + uint8_t readByte(uint8_t subAddress); // I2C and SPI read byte wrapper function + void readBytes(uint8_t subAddress, uint8_t* dest, uint16_t count); // I2C and SPI read bytes wrapper function + private: + Comms comms; // Communications bus: I2C or SPI + uint8_t address; // The device I2C address + uint8_t cs; // The SPI chip select pin +#ifdef ARDUINO_ARCH_ESP32 + uint8_t spiPort; // SPI port type VSPI or HSPI +#endif + TwoWire* i2c; // Pointer to the Wire class + SPIClass* spi; // Pointer to the SPI class + uint32_t spiClockSpeed; // The SPI clock speed + const uint8_t WRITE_MASK = 0x7F; // Sub-address write mask for SPI communications + const uint8_t READ_MASK = 0x80; // Sub-address read mask for SPI communications +#if defined ARDUINO_ARCH_ESP8266 || defined ARDUINO_ARCH_ESP32 + uint8_t sda, scl; // Software I2C SDA and SCL pins +#endif +}; +#endif diff --git a/BMP388_DEV/LICENSE b/BMP388_DEV/LICENSE new file mode 100644 index 0000000..edc8fa7 --- /dev/null +++ b/BMP388_DEV/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 MartinL1 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/BMP388_DEV/README.md b/BMP388_DEV/README.md new file mode 100644 index 0000000..f626db5 --- /dev/null +++ b/BMP388_DEV/README.md @@ -0,0 +1,737 @@ +# BMP388_DEV +An Arduino compatible, non-blocking, I2C/SPI library for the Bosch BMP388 barometer. + +![alt text](https://cdn-learn.adafruit.com/assets/assets/000/072/428/small360/sensors_BMP388_Top_Angle.jpg?1551997243 "Adafruit BMP388 Breakout Board") + +© Copyright, image courtesy of [Adafruit Industries](https://www.adafruit.com/product/3966) lisensed under the terms of the [Create Commons Attribution-ShareAlike 3.0 Unported](https://creativecommons.org/licenses/by-sa/3.0/legalcode). + +This BMP388_DEV library offers the following features: + +- Returns temperature in degrees celcius (**°C**), pressure in hectoPascals/millibar (**hPa**) and altitude in metres (**m**) +- NORMAL or FORCED modes of operation +- I2C or hardware SPI communications with configurable clock rates +- Non-blocking operation +- In NORMAL mode barometer returns results at the specified standby time interval +- Highly configurable, allows for changes to pressure and temperature oversampling, IIR filter and standby time +- Polling or interrupt driven measurements (using the BMP388's external INT pin) +- Storage and burst reading of up to 72 temperature and pressure measurements using the BMP388's internal 512 byte FIFO memory + +--- +## __Contents__ + +1. [Version](#version) +2. [Arduino Compatiblility](#arduino_compatibility) +3. [Installation](#installation) +3. [Usage](#usage) + 1. [BMP388_DEV Library](#bmp388_dev_library) + 2. [Device Initialisation](#device_intialisation) + 3. [Device Configuration](#device_configuration) + 4. [Modes Of Operation](#modes_of_operation) + 5. [Results Acquisition](#results_acquisition) + 6. [Code Implementation](#code_implementation) +4. [Additional Features](#additional_features) + 1. [Interrupts](#interrupts) + 2. [FIFO (First In First Out) Operation](#fifo_operation) + 3. [FIFO Operation With Interrupts](#fifo_operation_with_interrupts) +5. [Example Code](#example_code) + + +## __Version__ + +- Version 1.0.11 -- Fixed uninitialised "Wire" pointer for ESP8266/ESP32 with user defined I2C pins +- Version 1.0.10 -- Removed default parameter causing ESP32 compilation error with user defined I2C pins +- Version 1.0.9 -- Fix compilation issue for STM32 Blue Pill +- Version 1.0.8 -- Allow for additional TwoWire instances +- Version 1.0.7 -- Fix compilation issue with Arduino Due +- Version 1.0.6 -- Include getErrorReg() and getStatusReg() functions +- Version 1.0.5 -- Modification to allow ESP8266 SPI operation, thanks to Adam9850 for the generating the pull request +- Version 1.0.4 -- Fix incorrect oversampling definition for x1, thanks to myval for raising the issue +- Version 1.0.3 -- Initialise "device" constructor member variables in the same order they are declared +- Version 1.0.2 -- Modification to allow user-defined pins for I2C operation on the ESP32 +- Version 1.0.1 -- Fix uninitialised structures, thanks to David Jade for investigating and flagging up this issue +- Version 1.0.0 -- Intial version + + +## __Arduino Compatibility__ + +- All Arduino boards, but for 5V Arduino boards (such as the Uno, Nano, Mega, Leonardo, etc...), please check if the BMP388 breakout board requires a 5V to +3.3V voltage level shifter + + +## __Installation__ + +The BMP388_DEV library can be installed using the Arduino IDE's Library Manager. To access the Library Manager, in the Arduino IDE's menu select _Sketch->Include Library->Manage Libraries..._. In the Library Manager's search bar type BMP388 then select the "Install" button in the BMP388_DEV entry. + +Alternatively simply download BMP388_DEV from this Github repository, un-zip or extract the files and place the BMP388_DEV directory in your _.../Arduino/libraries/..._ folder. The _.../Arduino/..._ folder is the one where your Arduino IDE sketches are usually located. + + +## __Usage__ + + +### __BMP388_DEV Library__ + +Simply include the BMP388_DEV.h file at the beginning of your sketch: + +``` +#include +``` + +For I2C communication the BMP388_DEV object is created (instantiated) without any parameters: + +``` +BMP388_DEV bmp388; // Set up I2C communications +``` + +Alternatively an auxiliary or secondary I2C (Wire) port can be specified: + +``` +BMP388_DEV bmp388(Wire1); // Set up I2C communications on a secondary port +``` + +By default the library uses the BMP388's I2C address 0x77. (To use the alternate I2C address: 0x76, see the begin() function below. + +The ESP8266 and ESP32 also offer the option of selecting the I2C SDA and SDA pins as parameters: + +``` +BMP388_DEV bmp388(A6, A7); // Set up I2C communications on ESP32 pins A6 (SDA) and A7 (SCL): bmp388(SDA, SCL); +``` + +If no parameters are selected, the ESP32 uses its default SDA and SCL pins. + +For SPI communication the chip select (CS) Arduino digital output pin is specified as an argument, for example digital pin 10: + +``` +BMP388_dev bmp388(10); // Set up SPI communications on digital pin D10 +``` + +The library also supports the ESP32 HSPI operation on pins: SCK 14, MOSI 13, MISO 27 and user defined SS (CS): + +``` +SPIClass SPI1(HSPI); // Create the SPI1 HSPI object +BMP388_DEV bmp388(21, HSPI, SPI1); // Set up HSPI port communications on the ESP32 +``` + +By default the I2C runs in fast mode at 400kHz and SPI at 1MHz. However it is possible to change either the I2C or SPI clock speed using the set clock function: + +``` +bmp388.setClock(4000000); // Set the SPI clock to 4MHz +``` + +--- + +### __Device Initialisation__ + +To initialise the BMP388 it is necessary to call the begin() function with or without arguments. The parameters specify the starting mode, pressure/temperature oversampling, IIR filter and standby time options respectively: + +``` +bmp388.begin(SLEEP_MODE, OVERSAMPLING_X16, OVERSAMPLING_X2, IIR_FILTER_4, TIME_STANDBY_5MS); +``` + +Alternatively simply call the begin function without any arguments, this sets up the default configuration: SLEEP_MODE, pressure oversampling X16, temperature oversampling X2, IIR filter OFF and a standby time of 5ms: + +``` +bmp388.begin(); // Initialise the BMP388 with default configuration +``` + +Another alternative is to pass the BMP388's mode as an argument: + +``` +bmp388.begin(NORMAL_MODE); // Initialise the BMP388 in NORMAL_MODE with default configuration +``` + +Or, specifying mode and alternate I2C address: + +``` +bmp388.begin(FORCED_MODE, BMP388_I2C_ALT_ADDR); // Initialise the BMP388 in FORCED_MODE with the alternate I2C address (0x76) +``` + +Or even just the alternate I2C address, (BMP388 initialised in SLEEP_MODE by default): + +``` +bmp388.begin(BMP388_I2C_ALT_ADDR); // Initialise the BMP388 with the alternate I2C address (0x76) +``` + +Note that the _begin()_ functions return the value 1 upon successful initialisation, otherwise it returns 0 for failure. + +--- + +### __Device Configuration__ + +After initialisation it is possible to change the BMP388 configuration with the following functions: + +``` +bmp388.setPresOversampling(OVERSAMPLING_X4); // Options are OVERSAMPLING_SKIP, _X1, _X2, _X4, _X8, _X16, _32 +``` + +``` +bmp388.setTempOversampling(OVERSAMPLING_X4); // Options are OVERSAMPLING_SKIP, _X1, _X2, _X4, _X8, _X16, _X32 +``` + +``` +bmp388.setIIRFilter(IIR_FILTER_16); // Options are IIR_FILTER_OFF, _2, _4, _8, _16, _32 +``` + +``` +bmp388.setTimeStandby(TIME_STANDBY_2000MS); // Options are TIME_STANDBY_5MS, _10MS, _20MS, _250MS, _40MS, _80MS, 160MS, 320MS, 640MS, 1280MS, 2560MS, 5120MS, 10240MS, 20480MS, 40960MS, 81920MS, 163840MS, 327680MS, 655360MS +``` +--- + +### __Modes Of Operation__ + +The BMP388 has 3 modes of operation: **SLEEP_MODE**, **NORMAL_MODE** and **FORCED_MODE**: + +- **SLEEP_MODE**: puts the device into an inactive standby state + +- **NORMAL_MODE**: performs continuous conversions, separated by the standby time + +- **FORCED_MODE**: performs a single conversion, returning to **SLEEP_MODE** upon completion + +To kick-off conversions in **NORMAL_MODE**: + +``` +bmp388.startNormalConversion(); // Start continuous conversions, separated by the standby time +``` + +To perform a single oneshot conversion in **FORCED_MODE**: + +``` +bmp388.startForcedConversion(); // Start a single oneshot conversion +``` + +To stop the conversion at anytime and return to **SLEEP_MODE**: + +``` +bmp388.stopConversion(); // Stop conversion and return to SLEEP_MODE +``` +--- + +### __Results Acquisition__ + +The BMP388 barometer library acquires temperature in degrees celcius (**°C**), pressure in hectoPascals/millibar (**hPa**) and altitude in metres (**m**). The acquisition functions scan the BMP388's status register and return 1 if the barometer results are ready and have been successfully read, 0 if they are not; this allows for non-blocking code implementation. The temperature, pressure and altitude results themselves are _float_ variables by passed reference to the function and are updated upon a successful read. + +Here are the results acquisition functions: + +``` +bmp388.getMeasurements(temperature, pressure, altitude); // Acquire temperature, pressue and altitude measurements +``` + +``` +bmp388.getTempPres(temperature, pressure); // Acquire both the temperature and pressure +``` + +``` +bmp388.getTemperature(temperature); // Acquire the temperature only +``` + +``` +bmp388.getPressure(pressure); // Acquire the pressure only, (also calculates temperature, but doesn't return it) +``` + +``` +bmp388.getAltitude(altitude); // Acquire the altitude only +``` +--- + +### __Code Implementation__ + +Here is an example sketch of how to use the BMP388 library for non-blocking I2C operation, default configuration with continuous conversion in NORMAL_MODE, but with a standby sampling time of 1 second: + +``` +#include // Include the BMP388_DEV.h library + +float temperature, pressure, altitude; // Create the temperature, pressure and altitude variables +BMP388_DEV bmp388; // Instantiate (create) a BMP388_DEV object and set-up for I2C operation (address 0x77) + +void setup() +{ + Serial.begin(115200); // Initialise the serial port + bmp388.begin(); // Default initialisation, place the BMP388 into SLEEP_MODE + bmp388.setTimeStandby(TIME_STANDBY_1280MS); // Set the standby time to 1280ms + bmp388.startNormalConversion(); // Start NORMAL conversion mode +} + +void loop() +{ + if (bmp388.getMeasurements(temperature, pressure, altitude)) // Check if the measurement is complete + { + Serial.print(temperature); // Display the results + Serial.print(F("*C ")); + Serial.print(pressure); + Serial.print(F("hPa ")); + Serial.print(altitude); + Serial.println(F("m")); + } +} +``` + +A second sketch example for I2C operation, default configuration in FORCED conversion mode: + +``` +#include // Include the BMP388_DEV.h library + +float temperature, pressure, altitude; // Create the temperature, pressure and altitude variables +BMP388_DEV bmp388; // Instantiate (create) a BMP388_DEV object and set-up for I2C operation (address 0x77) + +void setup() +{ + Serial.begin(115200); // Initialise the serial port + bmp388.begin(); // Default initialisation, place the BMP388 into SLEEP_MODE +} + +void loop() +{ + bmp388.startForcedConversion(); // Start a forced conversion (if in SLEEP_MODE) + if (bmp388.getMeasurements(temperature, pressure, altitude)) // Check if the measurement is complete + { + Serial.print(temperature); // Display the results + Serial.print(F("*C ")); + Serial.print(pressure); + Serial.print(F("hPa ")); + Serial.print(altitude); + Serial.println(F("m")); + } +} +``` + +The sketches for SPI operation are identical except that the line: + +``` +BMP388_DEV bmp388; // Instantiate (create) a BMP388_DEV object and set-up for I2C operation (address 0x77) +``` + +...should be replaced with the line: + +``` +BMP388_DEV bmp388(10); // Instantiate (create) a BMP388_DEV object and set-up for SPI operation with chip select on D10 +``` + +For more details see code examples provided in the _.../examples/..._ directory. + +--- + +## __Additional Features__ + + +### __Interrupts__ + +The BMP388 barometer has an interrupt (INT) output pin that enables measurements to be interrupt driven instead of using polling. Interrupts function in both in NORMAL and FORCED modes of operation. + +Interrupts are configured by calling the enable interrupt function with or without arguments. The parameters specify whether the INT pin output drive is: PUSH_PULL or OPEN_COLLECTOR, the signal is: ACTIVE_LOW or ACTIVE_HIGH and interrupt itself is: UNLATCHED or LATCHED. In UNLATCHED mode the interrupt signal automatically clears after 2.5ms, while in LATCHED mode the interrupt signal remains active until the data is read. + +The default settings are PUSH_PULL, ACTIVE_HIGH and UNLATCHED: + +``` +bmp388.enableInterrupt(PUSH_PULL, ACTIVE_HIGH, UNLATCHED); // Enable interrupts with default settings +``` + +Alternatively the enable interrupt function with default settings can be called without any arguments: + +``` +bmp388.enableInterrupt(); // Enable interrupts with default settings +``` +The interrupts can also be disabled by calling the disable interrupt function: + +``` +bmp388.disableInterrupt(); // Enable interrupts with default settings +``` +The interrupt settings can also be changed independently: + +``` +bmp388.setIntOutputDrive(OPEN_COLLECTOR); // Set the interrupt pin's output drive to open collector +``` + +``` +bmp388.setIntActiveLevel(ACTIVE_LOW); // Set the interrupt signal's active level to LOW +``` + +``` +bmp388.setIntLatchConfig(LATCHED); // Set the interrupt signal to latch until cleared +``` + +Attaching the Arduino microcontroller to the BMP388's INT pin is performed using the standard Arduino attachInterrupt() function: + +``` +attachInterrupt(digitalPinToInterrupt(2), interruptHandler, RISING); // Set interrupt to call interruptHandler function on D2 +``` + +If the SPI interface is being used and happens to be shared with other devices, then it is also necessary to call the SPI usingInterrupt function as well, (with the exception of the ESP32 and ESP8266): + +``` +bmp388.usingInterrupt(digitalPinToInterrupt(2)); // Invoke the SPI usingInterrupt() function +``` + +The I2C interface uses the Arduino Wire library. However as the Wire library generates interrupts itself during operation, it is unfortunately not possible to call the results acqusition functions (such as getTemperature(), getPressure() and getMeasurements()) from within the Interrupt Service Routine (ISR). Instead a data ready flag is set within the ISR that allows the barometer data to be read in the main loop() function. + +Here is an example sketch using I2C in NORMAL_MODE, default configuration with interrupts: + +``` +////////////////////////////////////////////////////////////////////////////////////////// +// BMP388_DEV - I2C Communications, Default Configuration, Normal Conversion, Interrupt +////////////////////////////////////////////////////////////////////////////////////////// + +#include // Include the BMP388_DEV.h library + +volatile boolean dataReady = false; // Define the data ready flag +float temperature, pressure, altitude; // Declare the measurement variables + +BMP388_DEV bmp388; // Instantiate (create) a BMP388_DEV object and set-up for I2C operation (address 0x77) + +void setup() +{ + Serial.begin(115200); // Initialise the serial port + bmp388.begin(); // Default initialisation, place the BMP388 into SLEEP_MODE + bmp388.enableInterrupt(); // Enable the BMP388's interrupt (INT) pin + attachInterrupt(digitalPinToInterrupt(2), interruptHandler, RISING); // Set interrupt to call interruptHandler function on D2 + bmp388.setTimeStandby(TIME_STANDBY_1280MS); // Set the standby time to 1.3 seconds * 10 = measurement every 13 seconds + bmp388.startNormalConversion(); // Start BMP388 continuous conversion in NORMAL_MODE +} + +void loop() +{ + if (dataReady) // Check if data is ready + { + bmp388.getMeasurements(temperature, pressure, altitude); // Read the measurements + Serial.print(temperature); // Display the results + Serial.print(F("*C ")); + Serial.print(pressure); + Serial.print(F("hPa ")); + Serial.print(altitude); + Serial.println(F("m")); + dataReady = false; // Clear the dataReady flag + } +} + +void interruptHandler() // Interrupt handler function +{ + dataReady = true; // Set the dataReady flag +} +``` + +The SPI interface on the other hand, does allow for the results acquisition functions to be called from within the ISR. + +Here is an example sketch using SPI in NORMAL_MODE, default configuration with interrupts: + +``` +/////////////////////////////////////////////////////////////////////////////////////////// +// BMP388_DEV - SPI Communications, Default Configuration, Normal Conversion, Interrupts +/////////////////////////////////////////////////////////////////////////////////////////// + +#include // Include the BMP388_DEV.h library + +volatile boolean dataReady = false; // Define the data ready flag +volatile float temperature, pressure, altitude; // Declare the measurement variables + +BMP388_DEV bmp388(10); // Instantiate (create) a BMP388_DEV object and set-up for SPI operation on digital pin D10 + +void setup() +{ + Serial.begin(115200); // Initialise the serial port + bmp388.begin(); // Default initialisation, place the BMP388 into SLEEP_MODE + bmp388.enableInterrupt(); // Enable the BMP388's interrupt (INT) pin + bmp388.usingInterrupt(digitalPinToInterrupt(2)); // Invoke the SPI usingInterrupt() function + attachInterrupt(digitalPinToInterrupt(2), interruptHandler, RISING); // Set interrupt to call interruptHandler function on D2 + bmp388.setTimeStandby(TIME_STANDBY_1280MS); // Set the standby time to 1.3 seconds + bmp388.startNormalConversion(); // Start BMP388 continuous conversion in NORMAL_MODE +} + +void loop() +{ + if (dataReady) // Check if the measurement is complete + { + dataReady = false; // Clear the data ready flag + Serial.print(temperature); // Display the results + Serial.print(F("*C ")); + Serial.print(pressure); + Serial.print(F("hPa ")); + Serial.print(altitude); + Serial.println(F("m")); + } +} + +void interruptHandler() // Interrupt handler function +{ + bmp388.getMeasurements(temperature, pressure, altitude); // Read the measurement data + dataReady = true; // Set the data ready flag +} +``` + +--- + +### __FIFO (First In First Out) Operation__ + +The BMP388 barometer contains a 512 byte FIFO memory, capable of storing and burst reading up to 72 temperature and pressure measurements in NORMAL_MODE. + +By default the BMP388_DEV library always enables temperature, pressure, altitude and sensor time. Sensor time is the internal timing of the BMP388 barometer, the datasheet however does not specify the time's units. Additional parameters include the FIFO sub-sampling time, data select and stop on FIFO full. + +Sub-sampling divides down the FIFO sampling rate down further with the settings from OFF, DIV2, DIV4,...DIV128. This allows FIFO measurements to be taken over an extended period. For instance, if the barometer sampling rate is set to TIME_STANDBY_655360MS or 655.36 seconds, and the FIFO sub-sampling rate to SUBSAMPLING_DIV128 or divided down by 128, this gives a FIFO sampling time every 23 hours, 18 minutes. Over 72 samples the FIFO would return data almost every 70 days. + +Data select determines whether the data placed in the FIFO is unfiltered or filtered by the IIR filter. + +Stop on FIFO full, stops the FIFO from receiving data when it is full, otherwise the FIFO will continue to allow new data to overwrite old. + +The enableFIFO() function parameters include pressure enable, altitude enable, sensor time enable, subsampling rate, data select and stop FIFO on full: + +``` +bmp388.enableFIFO(PRES_ENABLED, ALT_ENABLED, TIME_ENABLED, SUBSAMPLETIME_OFF, FILTERED, STOP_FIFO_ON_FULL); // Enable FIFO with default argurments +``` + +Alternatively, to enable the FIFO with default settings and without arguments: + +``` +bmp388.enableFIFO(); // Enable the BMP388's FIFO operation +``` + +To disable the FIFO: + +``` +bmp388.disableFIFO(); // Disable the BMP388's FIFO +``` + +It is also possible to change the FIFO settings independently: + +``` +bmp388.setFIFOPressEnable(PRESS_ENABLED); // Enable FIFO pressure measurements, options: PRESS_DISABLED, PRESS_ENABLED +``` + +``` +bmp388.setFIFOAltEnable(ALT_ENABLED); // Enable FIFO altitude measurements, options: ALT_DISABLED, ALT_ENABLED +``` + +``` +bmp388.setFIFOTimeEnable(TIME_ENABLED); // Enable FIFO sensor time, options: IME_DISABLED, TIME_ENABLED +``` + +``` +bmp388.SetFIFOSubSampling(SUBSAMPING_OFF); // Enable FIFO sub-sampling, options: SUBSAMPING_OFF, DIV2, DIV4, DIV8, DIV16, DIV32, DIV64, DIV128 +``` + +``` +bmp388.SetDataSelect(FILTERED); // Set FIFO to store unfiltered or filtered data, options UNFILITERED, FILTERED +``` + +``` +bmp388.StopFIFOOnFull(STOP_ON_FULL_ENABLED); // Set FIFO to stop when full, options: STOP_ON_FULL_DISABLED, STOP_ON_FULL_ENABLED +``` + +The _setFIFONoOfMeasurements()_ function calculates the FIFO size in bytes required to store the specified number of either temperature and pressure or temperature meaurements. The function returns 1 if successful, 0 for failure, The maximum number of measurements is 72 for temperature and pressure and 126 for temperature alone: + +``` +bmp388.setFIFONoOfMeasurements(NO_OF_MEASUREMENTS); // Calculate the size of the FIFO required to store the measurements +``` + +To check if the FIFO measurements are ready the _getFIFOData()_ function can be polled. The function returns 1 if the measurements are ready, 0 if they are still pending. The parameters include _float_ pointers to temperature, pressure and altitude arrays, as well the sensorTime append to each batch of measurements that is a _uint32_t_ (_unsigned long_) variable passed by reference: + +``` +bmp388.getFifoData(float *temperature, float *pressure, float *altitude, float &sensorTime); +``` + +The _float_ arrays are decleared, whose size (number of indices) matches the number of measurements: + +``` +float temperature[NO_OF_MEASUREMENTS]; // Create the temperature, pressure and altitude array variables +float pressure[NO_OF_MEASUREMENTS]; +float altitude[NO_OF_MEASUREMENTS]; +uint32_t sensorTime; // Sensor time +``` + +A pointer to the head of each temperature, pressure and altitude array, as well as the sensor time are passed to the function, each time the FIFO is polled for data: + +``` +if (bmp388.getFifoData(float temperature, float pressure, float altitude, float sensorTime) +{ + // The FIFO measurements are ready +} +``` + +Here is an example sketch using SPI in NORMAL_MODE, default configuration with FIFO operation: + +``` +///////////////////////////////////////////////////////////////////////////////////// +// BMP388_DEV - SPI Communications, Default Configuration, Normal Conversion, FIFO +///////////////////////////////////////////////////////////////////////////////////// + +#include // Include the BMP388_DEV.h library + +#define NO_OF_MEASUREMENTS 10 // Number of measurements to be stored in the FIFO before reading + +float temperature[NO_OF_MEASUREMENTS]; // Create the temperature, pressure and altitude array variables +float pressure[NO_OF_MEASUREMENTS]; +float altitude[NO_OF_MEASUREMENTS]; +uint32_t sensorTime; // Sensor time +BMP388_DEV bmp388(10); // Instantiate (create) a BMP388_DEV object and set-up for SPI operation on digital pin D10 + +void setup() +{ + Serial.begin(115200); // Initialise the serial port + bmp388.begin(); // Default initialisation, place the BMP388 into SLEEP_MODE + bmp388.setTimeStandby(TIME_STANDBY_1280MS); // Set the standby time to 1.3 seconds * 10 = measurement every 13 seconds + bmp388.enableFIFO(); // Enable the BMP388's FIFO + bmp388.setFIFONoOfMeasurements(NO_OF_MEASUREMENTS); // Store 10 measurements in the FIFO before reading + bmp388.startNormalConversion(); // Start BMP388 continuous conversion in NORMAL_MODE + Serial.println(F("Please wait for 13 seconds...")); // Wait message +} + +void loop() +{ + if (bmp388.getFIFOData(temperature, pressure, altitude, sensorTime)) // If the FIFO data is ready: get the 10 measurement readings + { + for (uint16_t i = 0; i < NO_OF_MEASUREMENTS; i++) // Display the results + { + Serial.print(i + 1); + Serial.print(F(" : ")); + Serial.print(temperature[i]); + Serial.print(F("*C ")); + Serial.print(pressure[i]); + Serial.print(F("hPa ")); + Serial.print(altitude[i]); + Serial.println(F("m")); + } + Serial.print(F("Sensor Time: ")); + Serial.println(sensorTime); + Serial.println(); + Serial.println(F("Please wait for 13 seconds...")); // Wait message + } +} +``` + +--- + +### __FIFO Operation with Interrupts__ + +In NORMAL_MODE the BMP388 barometer also allows FIFO operation to be integrated with interrupts, using its INT pin to indicate to the microcontroller when a batch of measurements are ready. This is extremely useful for ultra low power applications, since it allows the barometer to independently collect data over a long duration, while the microcontroller remains asleep. + +To enable FIFO interrupts simply call the FIFO interrupt function, the parameters are identical to the standard enable interrupt function: + +``` +bmp388.enableFIFOInterrupt(PUSH_PULL, ACTIVE_HIGH, UNLATCHED); // Enable FIFO interrupts +``` + +Alternatively, this function can also be called with default arguments: + +``` +bmp388.enableFIFOInterrupt(); // Enable FIFO interrupts +``` + +To disable FIFO interrupts: + +``` +bmp388.enableFIFOInterrupt(); // Disable FIFO interrupts +``` + +It is also possible to change the FIFO interrupt settings independently using the standard interrupt settings, for example: + +``` +bmp388.setOutputDrive(OPEN_COLLECTOR); // Set the interrupt pin output drive to open collector +``` + +Attaching the Arduino microcontroller to the BMP388's INT pin is performed using the standard Arduino attachInterrupt() function, as described in the Interrupts section above. + +When using the SPI interface with the _getFIFOData()_ function called from within the interrupt service routine, it is necessary to declare the measurement arrays and sensor time variable as _volatile_: + +``` +volatile float temperature[NO_OF_MEASUREMENTS]; // Create the temperature, pressure and altitude array variables +volatile float pressure[NO_OF_MEASUREMENTS]; +volatile float altitude[NO_OF_MEASUREMENTS]; +volatile uint32_t sensorTime; // Sensor time +``` + +Here is an example sketch using SPI in NORMAL_MODE, default configuration with FIFO operation and interrupts: + +``` +///////////////////////////////////////////////////////////////////////////////////////////////// +// BMP388_DEV - SPI Communications, Default Configuration, Normal Conversion, Interrupts, FIFO +///////////////////////////////////////////////////////////////////////////////////////////////// + +#include // Include the BMP388_DEV.h library + +#define NO_OF_MEASUREMENTS 10 // Number of measurements to be stored in the FIFO before reading + +volatile float temperature[NO_OF_MEASUREMENTS]; // Create the temperature, pressure and altitude array variables +volatile float pressure[NO_OF_MEASUREMENTS]; +volatile float altitude[NO_OF_MEASUREMENTS]; +volatile uint32_t sensorTime; // Sensor time +volatile boolean fifoDataReady = false; +BMP388_DEV bmp388(10); // Instantiate (create) a BMP388_DEV object and set-up for SPI operation on digital pin D10 + +void setup() +{ + Serial.begin(115200); // Initialise the serial port + bmp388.begin(); // Default initialisation, place the BMP388 into SLEEP_MODE + bmp388.enableFIFOInterrupt(); // Enable the BMP388's FIFO interrupts on the INT pin + bmp388.usingInterrupt(digitalPinToInterrupt(2)); // Invoke the SPI usingInterrupt() function + attachInterrupt(digitalPinToInterrupt(2), interruptHandler, RISING); // Set interrupt to call interruptHandler function on D2 + bmp388.setTimeStandby(TIME_STANDBY_1280MS); // Set the standby time to 1.3 seconds * 10 = measurement every 13 seconds + bmp388.enableFIFO(); // Enable the BMP388's FIFO + bmp388.setFIFONoOfMeasurements(NO_OF_MEASUREMENTS); // Store 10 measurements in the FIFO before reading + bmp388.startNormalConversion(); // Start BMP388 continuous conversion in NORMAL_MODE + Serial.println(F("Please wait for 13 seconds...")); // Wait message +} + +void loop() +{ + if (fifoDataReady) // If the FIFO data is ready: get the 10 measurement readings + { + fifoDataReady = false; // Clear the FIFO data ready flag + for (uint16_t i = 0; i < NO_OF_MEASUREMENTS; i++) // Display the results + { + Serial.print(i + 1); + Serial.print(F(" : ")); + Serial.print(temperature[i]); + Serial.print(F("*C ")); + Serial.print(pressure[i]); + Serial.print(F("hPa ")); + Serial.print(altitude[i]); + Serial.println(F("m")); + } + Serial.print(F("Sensor Time: ")); + Serial.println(sensorTime); + Serial.println(); + Serial.println(F("Please wait for 13 seconds...")); // Wait message + } +} + +void interruptHandler() // Interrupt service routine (ISR) +{ + bmp388.getFIFOData(temperature, pressure, altitude, sensorTime); // Get the FIFO data + fifoDataReady = true; // Set the FIFO data ready flag +} +``` + +--- + +## __Example Code__ + +Here is the list of the Arduino example sketches: + +- __BMP388_I2C_Normal.ino__ : I2C Interface, Normal Mode, Standard I2C Address (0x77) + +- __BMP388_I2C_Alt_Normal.ino__ : I2C Interface, Normal Mode, Alternative I2C Address (0x76) + +- __BMP388_I2C_Forced.ino__ : I2C Interface, Forced Mode + +- __BMP388_I2C_Normal_Interrupt.ino__ : I2C Interface, Normal Mode, Interrupts + +- __BMP388_I2C_Forced_Interrupt.ino__ : I2C Interface, Forced Mode, Interrupts + +- __BMP388_I2C_Normal_FIFO.ino__ : I2C Interface, Normal Mode, FIFO Operation + +- __BMP388_I2C_Normal_Interrupt_FIFO.ino__ : I2C Interface, Normal Mode, Interrupts, FIFO Operation + +- __BMP388_SPI_Normal.ino__ : SPI Interface, Normal Mode + +- __BMP388_SPI_Forced.ino__ : SPI Interface, Forced Mode + +- __BMP388_SPI_Normal_Interrupt.ino__ : SPI Interface, Normal Mode, Interrupts + +- __BMP388_SPI_Forced_Interrupt.ino__ : SPI Interface, Forced Mode, Interrupts + +- __BMP388_SPI_Normal_FIFO.ino__ : SPI Interface, Normal Mode, FIFO Operation + +- __BMP388_SPI_Normal_Interrupt_FIFO.ino__ : SPI Interface, Normal Mode, Interrupts, FIFO Operation + +- __BMP388_SPI_Normal_Multiple.ino__ : SPI Interface, Normal Mode, Multiple Devices + +- __BMP388_ESP32_HSPI_Normal.ino__ : ESP32 HSPI Interface, Normal Mode + +- __BMP388_ESP8266_I2C_Normal_DefinedPins.ino__ : ESP8266 I2C Interface, Normal Mode, User-Defined Pins + +- __BMP388_ESP32_I2C_Normal_DefinedPins.ino__ : ESP32 I2C Interface, Normal Mode, User-Defined Pins diff --git a/BMP388_DEV/examples/BMP388_ESP32_HSPI_Normal/bmp388_ESP32_HSPI_Normal.ino b/BMP388_DEV/examples/BMP388_ESP32_HSPI_Normal/bmp388_ESP32_HSPI_Normal.ino new file mode 100644 index 0000000..7a80eb2 --- /dev/null +++ b/BMP388_DEV/examples/BMP388_ESP32_HSPI_Normal/bmp388_ESP32_HSPI_Normal.ino @@ -0,0 +1,43 @@ +////////////////////////////////////////////////////////////////////////////////////// +// BMP388_DEV - ESP32 HSPI Communications, Default Configuration, Normal Conversion +////////////////////////////////////////////////////////////////////////////////////// + +#include // Include the BMP388_DEV.h library + +float temperature, pressure, altitude; // Create the temperature, pressure and altitude variables +//BMP388_DEV bmp388(21); // Create BMP388_DEV object and set-up for VSPI operation, SCK 5, MOSI 18, MISO 19, SS 21 +SPIClass SPI1(HSPI); // Create (instantiate) the SPI1 object for HSPI operation +BMP388_DEV bmp388(21, HSPI, SPI1); // Create BMP388_DEV object and set-up for HSPI operation, SCK 14, MOSI 13, MISO 27, SS 21 + +void setup() +{ + Serial.begin(115200); // Initialise the serial port + bmp388.begin(); // Default initialisation, place the BMP388 into SLEEP_MODE + bmp388.setTimeStandby(TIME_STANDBY_1280MS); // Set the standby time to 1.3 seconds + bmp388.startNormalConversion(); // Start NORMAL continuous conversion + + xTaskCreatePinnedToCore( // Kick-off "TaskOne" pinned to core 1 + taskOne, + "TaskOne", + 10000, + NULL, + 1, + NULL, + 1); +} + +void taskOne(void* parameter) +{ + while(true) + { + if (bmp388.getMeasurements(temperature, pressure, altitude)) // Check if the measurement is complete + { + Serial.print(temperature); // Display the results + Serial.print(F("*C ")); + Serial.print(pressure); + Serial.print(F("hPa ")); + Serial.print(altitude); + Serial.println(F("m")); + } + } +} diff --git a/BMP388_DEV/examples/BMP388_ESP32_I2C_Normal_DefinedPins/BMP388_ESP32_I2C_Normal_DefinedPins.ino b/BMP388_DEV/examples/BMP388_ESP32_I2C_Normal_DefinedPins/BMP388_ESP32_I2C_Normal_DefinedPins.ino new file mode 100644 index 0000000..71b88dc --- /dev/null +++ b/BMP388_DEV/examples/BMP388_ESP32_I2C_Normal_DefinedPins/BMP388_ESP32_I2C_Normal_DefinedPins.ino @@ -0,0 +1,29 @@ +////////////////////////////////////////////////////////////////////////////////////////////////////////// +// BMP388_DEV - ESP32, I2C Communications, Default Configuration, Normal Conversion, User-Defined Pins +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#include // Include the BMP388_DEV.h library + +float temperature, pressure, altitude; // Create the temperature, pressure and altitude variables +BMP388_DEV bmp388(A6, A7); // Instantiate (create) a BMP388 object and set-up for I2C operation on pins SDA: A6, SCL: A7 + +void setup() +{ + Serial.begin(115200); // Initialise the serial port + bmp388.begin(); // Default initialisation, place the BMP388 into SLEEP_MODE + bmp388.setTimeStandby(TIME_STANDBY_1280MS); // Set the standby time to 1.2 seconds + bmp388.startNormalConversion(); // Start BMP388 continuous conversion in NORMAL_MODE +} + +void loop() +{ + if (bmp388.getMeasurements(temperature, pressure, altitude)) // Check if the measurement is complete + { + Serial.print(temperature); // Display the results + Serial.print(F("*C ")); + Serial.print(pressure); + Serial.print(F("hPa ")); + Serial.print(altitude); + Serial.println(F("m")); + } +} diff --git a/BMP388_DEV/examples/BMP388_ESP8266_I2C_Normal_DefinedPins/BMP388_ESP8266_I2C_Normal_DefinedPins.ino b/BMP388_DEV/examples/BMP388_ESP8266_I2C_Normal_DefinedPins/BMP388_ESP8266_I2C_Normal_DefinedPins.ino new file mode 100644 index 0000000..5977a5e --- /dev/null +++ b/BMP388_DEV/examples/BMP388_ESP8266_I2C_Normal_DefinedPins/BMP388_ESP8266_I2C_Normal_DefinedPins.ino @@ -0,0 +1,29 @@ +////////////////////////////////////////////////////////////////////////////////////////////////////////// +// BMP388_DEV - ESP8266, I2C Communications, Default Configuration, Normal Conversion, User-Defined Pins +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#include // Include the BMP388_DEV.h library + +float temperature, pressure, altitude; // Create the temperature, pressure and altitude variables +BMP388_DEV bmp388(6, 7); // Instantiate (create) a BMP388 object and set-up for I2C operation on pins SDA: 6, SCL: 7 + +void setup() +{ + Serial.begin(115200); // Initialise the serial port + bmp388.begin(); // Default initialisation, place the BMP388 into SLEEP_MODE + bmp388.setTimeStandby(TIME_STANDBY_2000MS); // Set the standby time to 2 seconds + bmp388.startNormalConversion(); // Start BMP388 continuous conversion in NORMAL_MODE +} + +void loop() +{ + if (bmp388.getMeasurements(temperature, pressure, altitude)) // Check if the measurement is complete + { + Serial.print(temperature); // Display the results + Serial.print(F("*C ")); + Serial.print(pressure); + Serial.print(F("hPa ")); + Serial.print(altitude); + Serial.println(F("m")); + } +} diff --git a/BMP388_DEV/examples/BMP388_I2C_Forced/BMP388_I2C_Forced.ino b/BMP388_DEV/examples/BMP388_I2C_Forced/BMP388_I2C_Forced.ino new file mode 100644 index 0000000..052c462 --- /dev/null +++ b/BMP388_DEV/examples/BMP388_I2C_Forced/BMP388_I2C_Forced.ino @@ -0,0 +1,28 @@ +/////////////////////////////////////////////////////////////////////////////// +// BMP388_DEV - I2C Communications, Default Configuration, Forced Conversion +/////////////////////////////////////////////////////////////////////////////// + +#include // Include the BMP388_DEV.h library + +float temperature, pressure, altitude; // Create the temperature, pressure and altitude variables +BMP388_DEV bmp388; // Instantiate (create) a BMP388_DEV object and set-up for I2C operation (address 0x77) + +void setup() +{ + Serial.begin(115200); // Initialise the serial port + bmp388.begin(); // Default initialisation, place the BMP388 into SLEEP_MODE +} + +void loop() +{ + bmp388.startForcedConversion(); // Start BMP388 forced conversion (if we're in SLEEP_MODE) + if (bmp388.getMeasurements(temperature, pressure, altitude)) // Check if the measurement is complete + { + Serial.print(temperature); // Display the results + Serial.print(F("*C ")); + Serial.print(pressure); + Serial.print(F("hPa ")); + Serial.print(altitude); + Serial.println(F("m")); + } +} diff --git a/BMP388_DEV/examples/BMP388_I2C_Forced_Interrupt/BMP388_I2C_Forced_Interrupt.ino b/BMP388_DEV/examples/BMP388_I2C_Forced_Interrupt/BMP388_I2C_Forced_Interrupt.ino new file mode 100644 index 0000000..45742f0 --- /dev/null +++ b/BMP388_DEV/examples/BMP388_I2C_Forced_Interrupt/BMP388_I2C_Forced_Interrupt.ino @@ -0,0 +1,39 @@ +////////////////////////////////////////////////////////////////////////////////////////// +// BMP388_DEV - I2C Communications, Default Configuration, Forced Conversion, Interrupt +////////////////////////////////////////////////////////////////////////////////////////// + +#include // Include the BMP388_DEV.h library + +volatile boolean dataReady = false; +float temperature, pressure, altitude; + +BMP388_DEV bmp388; // Instantiate (create) a BMP388_DEV object and set-up for I2C operation (address 0x77) + +void setup() +{ + Serial.begin(115200); // Initialise the serial port + bmp388.begin(); // Default initialisation, place the BMP388 into SLEEP_MODE + bmp388.enableInterrupt(); // Enable the BMP388's interrupt (INT) pin + attachInterrupt(digitalPinToInterrupt(2), interruptHandler, RISING); // Set interrupt to call interruptHandler function on D2 +} + +void loop() +{ + bmp388.startForcedConversion(); // Start BMP388 forced conversion (if we're in SLEEP_MODE) + if (dataReady) + { + bmp388.getMeasurements(temperature, pressure, altitude); // Read the measurements + Serial.print(temperature); // Display the results + Serial.print(F("*C ")); + Serial.print(pressure); + Serial.print(F("hPa ")); + Serial.print(altitude); + Serial.println(F("m")); + dataReady = false; // Clear the dataReady flag + } +} + +void interruptHandler() // Interrupt handler function +{ + dataReady = true; // Set the dataReady flag +} diff --git a/BMP388_DEV/examples/BMP388_I2C_Normal/BMP388_I2C_Normal.ino b/BMP388_DEV/examples/BMP388_I2C_Normal/BMP388_I2C_Normal.ino new file mode 100644 index 0000000..2043e53 --- /dev/null +++ b/BMP388_DEV/examples/BMP388_I2C_Normal/BMP388_I2C_Normal.ino @@ -0,0 +1,29 @@ +/////////////////////////////////////////////////////////////////////////////// +// BMP388_DEV - I2C Communications, Default Configuration, Normal Conversion +/////////////////////////////////////////////////////////////////////////////// + +#include // Include the BMP388_DEV.h library + +float temperature, pressure, altitude; // Create the temperature, pressure and altitude variables +BMP388_DEV bmp388; // Instantiate (create) a BMP388_DEV object and set-up for I2C operation (address 0x77) + +void setup() +{ + Serial.begin(115200); // Initialise the serial port + bmp388.begin(); // Default initialisation, place the BMP388 into SLEEP_MODE + bmp388.setTimeStandby(TIME_STANDBY_1280MS); // Set the standby time to 1.3 seconds + bmp388.startNormalConversion(); // Start BMP388 continuous conversion in NORMAL_MODE +} + +void loop() +{ + if (bmp388.getMeasurements(temperature, pressure, altitude)) // Check if the measurement is complete + { + Serial.print(temperature); // Display the results + Serial.print(F("*C ")); + Serial.print(pressure); + Serial.print(F("hPa ")); + Serial.print(altitude); + Serial.println(F("m")); + } +} diff --git a/BMP388_DEV/examples/BMP388_I2C_Normal_FIFO/BMP388_I2C_Normal_FIFO.ino b/BMP388_DEV/examples/BMP388_I2C_Normal_FIFO/BMP388_I2C_Normal_FIFO.ino new file mode 100644 index 0000000..e6d964c --- /dev/null +++ b/BMP388_DEV/examples/BMP388_I2C_Normal_FIFO/BMP388_I2C_Normal_FIFO.ino @@ -0,0 +1,46 @@ +///////////////////////////////////////////////////////////////////////////////////// +// BMP388_DEV - I2C Communications, Default Configuration, Normal Conversion, FIFO +///////////////////////////////////////////////////////////////////////////////////// + +#include // Include the BMP388_DEV.h library + +#define NO_OF_MEASUREMENTS 10 // Number of measurements to be stored in the FIFO before reading + +float temperature[NO_OF_MEASUREMENTS]; // Create the temperature, pressure and altitude array variables +float pressure[NO_OF_MEASUREMENTS]; +float altitude[NO_OF_MEASUREMENTS]; +uint32_t sensorTime; // Sensor time +BMP388_DEV bmp388; // Instantiate (create) a BMP388_DEV object and set-up for I2C operation (address 0x77) + +void setup() +{ + Serial.begin(115200); // Initialise the serial port + bmp388.begin(); // Default initialisation, place the BMP388 into SLEEP_MODE + bmp388.enableFIFO(); // Enable the BMP388's FIFO + bmp388.setFIFONoOfMeasurements(NO_OF_MEASUREMENTS); // Store 10 measurements in the FIFO before reading + bmp388.setTimeStandby(TIME_STANDBY_1280MS); // Set the standby time to 1.3 seconds + bmp388.startNormalConversion(); // Start BMP388 continuous conversion in NORMAL_MODE + Serial.println(F("Please wait for 13 seconds...")); // Wait message +} + +void loop() +{ + if (bmp388.getFIFOData(temperature, pressure, altitude, sensorTime)) // If the FIFO data is ready: get the 10 measurement readings + { + for (uint16_t i = 0; i < NO_OF_MEASUREMENTS; i++) // Display the results + { + Serial.print(i + 1); + Serial.print(F(" : ")); + Serial.print(temperature[i]); + Serial.print(F("*C ")); + Serial.print(pressure[i]); + Serial.print(F("hPa ")); + Serial.print(altitude[i]); + Serial.println(F("m")); + } + Serial.print(F("Sensor Time: ")); + Serial.println(sensorTime); + Serial.println(); + Serial.println(F("Please wait for 13 seconds...")); // Wait message + } +} diff --git a/BMP388_DEV/examples/BMP388_I2C_Normal_Interrupt/BMP388_I2C_Normal_Interrupt.ino b/BMP388_DEV/examples/BMP388_I2C_Normal_Interrupt/BMP388_I2C_Normal_Interrupt.ino new file mode 100644 index 0000000..969b251 --- /dev/null +++ b/BMP388_DEV/examples/BMP388_I2C_Normal_Interrupt/BMP388_I2C_Normal_Interrupt.ino @@ -0,0 +1,40 @@ +////////////////////////////////////////////////////////////////////////////////////////// +// BMP388_DEV - I2C Communications, Default Configuration, Normal Conversion, Interrupt +////////////////////////////////////////////////////////////////////////////////////////// + +#include // Include the BMP388_DEV.h library + +volatile boolean dataReady = false; +float temperature, pressure, altitude; + +BMP388_DEV bmp388; // Instantiate (create) a BMP388_DEV object and set-up for I2C operation (address 0x77) + +void setup() +{ + Serial.begin(115200); // Initialise the serial port + bmp388.begin(); // Default initialisation, place the BMP388 into SLEEP_MODE + bmp388.enableInterrupt(); // Enable the BMP388's interrupt (INT) pin + attachInterrupt(digitalPinToInterrupt(2), interruptHandler, RISING); // Set interrupt to call interruptHandler function on D2 + bmp388.setTimeStandby(TIME_STANDBY_1280MS); // Set the standby time to 1.3 seconds + bmp388.startNormalConversion(); // Start BMP388 continuous conversion in NORMAL_MODE +} + +void loop() +{ + if (dataReady) + { + bmp388.getMeasurements(temperature, pressure, altitude); // Read the measurements + Serial.print(temperature); // Display the results + Serial.print(F("*C ")); + Serial.print(pressure); + Serial.print(F("hPa ")); + Serial.print(altitude); + Serial.println(F("m")); + dataReady = false; // Clear the dataReady flag + } +} + +void interruptHandler() // Interrupt handler function +{ + dataReady = true; // Set the dataReady flag +} diff --git a/BMP388_DEV/examples/BMP388_I2C_Normal_Interrupt_FIFO/BMP388_I2C_Normal_Interrupt_FIFO.ino b/BMP388_DEV/examples/BMP388_I2C_Normal_Interrupt_FIFO/BMP388_I2C_Normal_Interrupt_FIFO.ino new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/BMP388_DEV/examples/BMP388_I2C_Normal_Interrupt_FIFO/BMP388_I2C_Normal_Interrupt_FIFO.ino @@ -0,0 +1 @@ + diff --git a/BMP388_DEV/examples/BMP388_SPI_Forced/BMP388_SPI_Forced.ino b/BMP388_DEV/examples/BMP388_SPI_Forced/BMP388_SPI_Forced.ino new file mode 100644 index 0000000..c629bb9 --- /dev/null +++ b/BMP388_DEV/examples/BMP388_SPI_Forced/BMP388_SPI_Forced.ino @@ -0,0 +1,28 @@ +/////////////////////////////////////////////////////////////////////////////// +// BMP388_DEV - SPI Communications, Default Configuration, Forced Conversion +/////////////////////////////////////////////////////////////////////////////// + +#include // Include the BMP388_DEV.h library + +float temperature, pressure, altitude; // Create the temperature, pressure and altitude variables +BMP388_DEV bmp388(10); // Instantiate (create) a BMP388_DEV object and set-up for SPI operation on digital pin D10 + +void setup() +{ + Serial.begin(115200); // Initialise the serial port + bmp388.begin(); // Default initialisation, place the BMP388 into SLEEP_MODE +} + +void loop() +{ + bmp388.startForcedConversion(); // Start BMP388 forced conversion (if we're in SLEEP_MODE) + if (bmp388.getMeasurements(temperature, pressure, altitude)) // Check if the measurement is complete + { + Serial.print(temperature); // Display the results + Serial.print(F("*C ")); + Serial.print(pressure); + Serial.print(F("hPa ")); + Serial.print(altitude); + Serial.println(F("m")); + } +} diff --git a/BMP388_DEV/examples/BMP388_SPI_Forced_Interrupt/BMP_SPI_Forced_Interrupt.ino b/BMP388_DEV/examples/BMP388_SPI_Forced_Interrupt/BMP_SPI_Forced_Interrupt.ino new file mode 100644 index 0000000..1f345f9 --- /dev/null +++ b/BMP388_DEV/examples/BMP388_SPI_Forced_Interrupt/BMP_SPI_Forced_Interrupt.ino @@ -0,0 +1,40 @@ +/////////////////////////////////////////////////////////////////////////////////////////// +// BMP388_DEV - SPI Communications, Default Configuration, Forced Conversion, Interrupts +/////////////////////////////////////////////////////////////////////////////////////////// + +#include // Include the BMP388_DEV.h library + +volatile boolean dataReady = false; +volatile float temperature, pressure, altitude; + +BMP388_DEV bmp388(10); // Instantiate (create) a BMP388_DEV object and set-up for SPI operation on digital pin D10 + +void setup() +{ + Serial.begin(115200); // Initialise the serial port + bmp388.begin(); // Default initialisation, place the BMP388 into SLEEP_MODE + bmp388.enableInterrupt(); // Enable the BMP388's interrupt (INT) pin + bmp388.usingInterrupt(digitalPinToInterrupt(2)); // Invoke the SPI usingInterrupt() function + attachInterrupt(digitalPinToInterrupt(2), interruptHandler, RISING); // Set interrupt to call interruptHandler function on D2 +} + +void loop() +{ + bmp388.startForcedConversion(); // Start BMP388 forced conversion (if we're in SLEEP_MODE) + if (dataReady) // Check if the measurement is complete + { + dataReady = false; // Clear the data ready flag + Serial.print(temperature); // Display the results + Serial.print(F("*C ")); + Serial.print(pressure); + Serial.print(F("hPa ")); + Serial.print(altitude); + Serial.println(F("m")); + } +} + +void interruptHandler() // Interrupt handler function +{ + bmp388.getMeasurements(temperature, pressure, altitude); // Read the measurement data + dataReady = true; // Set the data ready flag +} diff --git a/BMP388_DEV/examples/BMP388_SPI_Normal/BMP388_SPI_Normal.ino b/BMP388_DEV/examples/BMP388_SPI_Normal/BMP388_SPI_Normal.ino new file mode 100644 index 0000000..ab34036 --- /dev/null +++ b/BMP388_DEV/examples/BMP388_SPI_Normal/BMP388_SPI_Normal.ino @@ -0,0 +1,29 @@ +/////////////////////////////////////////////////////////////////////////////// +// BMP388_DEV - SPI Communications, Default Configuration, Normal Conversion +/////////////////////////////////////////////////////////////////////////////// + +#include // Include the BMP388_DEV.h library + +float temperature, pressure, altitude; // Create the temperature, pressure and altitude variables +BMP388_DEV bmp388(10); // Instantiate (create) a BMP388_DEV object and set-up for SPI operation on digital pin D10 + +void setup() +{ + Serial.begin(115200); // Initialise the serial port + bmp388.begin(); // Default initialisation, place the BMP388 into SLEEP_MODE + bmp388.setTimeStandby(TIME_STANDBY_1280MS); // Set the standby time to 1.3 seconds + bmp388.startNormalConversion(); // Start BMP388 continuous conversion in NORMAL_MODE +} + +void loop() +{ + if (bmp388.getMeasurements(temperature, pressure, altitude)) // Check if the measurement is complete + { + Serial.print(temperature); // Display the results + Serial.print(F("*C ")); + Serial.print(pressure); + Serial.print(F("hPa ")); + Serial.print(altitude); + Serial.println(F("m")); + } +} diff --git a/BMP388_DEV/examples/BMP388_SPI_Normal_FIFO/BMP388_SPI_Normal_FIFO.ino b/BMP388_DEV/examples/BMP388_SPI_Normal_FIFO/BMP388_SPI_Normal_FIFO.ino new file mode 100644 index 0000000..d8faf8d --- /dev/null +++ b/BMP388_DEV/examples/BMP388_SPI_Normal_FIFO/BMP388_SPI_Normal_FIFO.ino @@ -0,0 +1,46 @@ +///////////////////////////////////////////////////////////////////////////////////// +// BMP388_DEV - SPI Communications, Default Configuration, Normal Conversion, FIFO +///////////////////////////////////////////////////////////////////////////////////// + +#include // Include the BMP388_DEV.h library + +#define NO_OF_MEASUREMENTS 10 // Number of measurements to be stored in the FIFO before reading + +float temperature[NO_OF_MEASUREMENTS]; // Create the temperature, pressure and altitude array variables +float pressure[NO_OF_MEASUREMENTS]; +float altitude[NO_OF_MEASUREMENTS]; +uint32_t sensorTime; // Sensor time +BMP388_DEV bmp388(10); // Instantiate (create) a BMP388_DEV object and set-up for SPI operation on digital pin D10 + +void setup() +{ + Serial.begin(115200); // Initialise the serial port + bmp388.begin(); // Default initialisation, place the BMP388 into SLEEP_MODE + bmp388.setTimeStandby(TIME_STANDBY_1280MS); // Set the standby time to 1.3 seconds * 10 = measurement every 13 seconds + bmp388.enableFIFO(); // Enable the BMP388's FIFO + bmp388.setFIFONoOfMeasurements(NO_OF_MEASUREMENTS); // Store 10 measurements in the FIFO before reading + bmp388.startNormalConversion(); // Start BMP388 continuous conversion in NORMAL_MODE + Serial.println(F("Please wait for 13 seconds...")); // Wait message +} + +void loop() +{ + if (bmp388.getFIFOData(temperature, pressure, altitude, sensorTime)) // If the FIFO data is ready: get the 10 measurement readings + { + for (uint16_t i = 0; i < NO_OF_MEASUREMENTS; i++) // Display the results + { + Serial.print(i + 1); + Serial.print(F(" : ")); + Serial.print(temperature[i]); + Serial.print(F("*C ")); + Serial.print(pressure[i]); + Serial.print(F("hPa ")); + Serial.print(altitude[i]); + Serial.println(F("m")); + } + Serial.print(F("Sensor Time: ")); + Serial.println(sensorTime); + Serial.println(); + Serial.println(F("Please wait for 13 seconds...")); // Wait message + } +} diff --git a/BMP388_DEV/examples/BMP388_SPI_Normal_Interrupt/BMP_SPI_Normal_Interrupt.ino b/BMP388_DEV/examples/BMP388_SPI_Normal_Interrupt/BMP_SPI_Normal_Interrupt.ino new file mode 100644 index 0000000..0d9e5dc --- /dev/null +++ b/BMP388_DEV/examples/BMP388_SPI_Normal_Interrupt/BMP_SPI_Normal_Interrupt.ino @@ -0,0 +1,41 @@ +/////////////////////////////////////////////////////////////////////////////////////////// +// BMP388_DEV - SPI Communications, Default Configuration, Normal Conversion, Interrupts +/////////////////////////////////////////////////////////////////////////////////////////// + +#include // Include the BMP388_DEV.h library + +volatile boolean dataReady = false; +volatile float temperature, pressure, altitude; + +BMP388_DEV bmp388(10); // Instantiate (create) a BMP388_DEV object and set-up for SPI operation on digital pin D10 + +void setup() +{ + Serial.begin(115200); // Initialise the serial port + bmp388.begin(); // Default initialisation, place the BMP388 into SLEEP_MODE + bmp388.enableInterrupt(); // Enable the BMP388's interrupt (INT) pin + bmp388.usingInterrupt(digitalPinToInterrupt(2)); // Invoke the SPI usingInterrupt() function + attachInterrupt(digitalPinToInterrupt(2), interruptHandler, RISING); // Set interrupt to call interruptHandler function on D2 + bmp388.setTimeStandby(TIME_STANDBY_1280MS); // Set the standby time to 1.3 seconds + bmp388.startNormalConversion(); // Start BMP388 continuous conversion in NORMAL_MODE +} + +void loop() +{ + if (dataReady) // Check if the measurement is complete + { + dataReady = false; // Clear the data ready flag + Serial.print(temperature); // Display the results + Serial.print(F("*C ")); + Serial.print(pressure); + Serial.print(F("hPa ")); + Serial.print(altitude); + Serial.println(F("m")); + } +} + +void interruptHandler() // Interrupt handler function +{ + bmp388.getMeasurements(temperature, pressure, altitude); // Read the measurement data + dataReady = true; // Set the data ready flag +} diff --git a/BMP388_DEV/examples/BMP388_SPI_Normal_Interrupt_FIFO/BMP388_SPI_Normal_Interrupt_FIFO.ino b/BMP388_DEV/examples/BMP388_SPI_Normal_Interrupt_FIFO/BMP388_SPI_Normal_Interrupt_FIFO.ino new file mode 100644 index 0000000..b4f3abf --- /dev/null +++ b/BMP388_DEV/examples/BMP388_SPI_Normal_Interrupt_FIFO/BMP388_SPI_Normal_Interrupt_FIFO.ino @@ -0,0 +1,57 @@ +///////////////////////////////////////////////////////////////////////////////////////////////// +// BMP388_DEV - SPI Communications, Default Configuration, Normal Conversion, Interrupts, FIFO +///////////////////////////////////////////////////////////////////////////////////////////////// + +#include // Include the BMP388_DEV.h library + +#define NO_OF_MEASUREMENTS 10 // Number of measurements to be stored in the FIFO before reading + +volatile float temperature[NO_OF_MEASUREMENTS]; // Create the temperature, pressure and altitude array variables +volatile float pressure[NO_OF_MEASUREMENTS]; +volatile float altitude[NO_OF_MEASUREMENTS]; +volatile uint32_t sensorTime; // Sensor time +volatile boolean fifoDataReady = false; +BMP388_DEV bmp388(10); // Instantiate (create) a BMP388_DEV object and set-up for SPI operation on digital pin D10 + +void setup() +{ + Serial.begin(115200); // Initialise the serial port + bmp388.begin(); // Default initialisation, place the BMP388 into SLEEP_MODE + bmp388.enableFIFOInterrupt(); // Enable the BMP388's FIFO interrupts on the INT pin + SPI.usingInterrupt(digitalPinToInterrupt(2)); // Invoke the SPI usingInterrupt() function + attachInterrupt(digitalPinToInterrupt(2), interruptHandler, RISING); // Set interrupt to call interruptHandler function on D2 + bmp388.setTimeStandby(TIME_STANDBY_1280MS); // Set the standby time to 1.3 seconds * 10 = measurement every 13 seconds + bmp388.enableFIFO(); // Enable the BMP388's FIFO + bmp388.setFIFONoOfMeasurements(NO_OF_MEASUREMENTS); // Store 10 measurements in the FIFO before reading + bmp388.startNormalConversion(); // Start BMP388 continuous conversion in NORMAL_MODE + Serial.println(F("Please wait for 13 seconds...")); // Wait message +} + +void loop() +{ + if (fifoDataReady) // If the FIFO data is ready: get the 10 measurement readings + { + fifoDataReady = false; // Clear the FIFO data ready flag + for (uint16_t i = 0; i < NO_OF_MEASUREMENTS; i++) // Display the results + { + Serial.print(i + 1); + Serial.print(F(" : ")); + Serial.print(temperature[i]); + Serial.print(F("*C ")); + Serial.print(pressure[i]); + Serial.print(F("hPa ")); + Serial.print(altitude[i]); + Serial.println(F("m")); + } + Serial.print(F("Sensor Time: ")); + Serial.println(sensorTime); + Serial.println(); + Serial.println(F("Please wait for 13 seconds...")); // Wait message + } +} + +void interruptHandler() // Interrupt service routine (ISR) +{ + bmp388.getFIFOData(temperature, pressure, altitude, sensorTime); // Get the FIFO data + fifoDataReady = true; // Set the FIFO data ready flag +} diff --git a/BMP388_DEV/examples/BMP388_SPI_Normal_Multiple/BMP388_SPI_Normal_Multiple.ino b/BMP388_DEV/examples/BMP388_SPI_Normal_Multiple/BMP388_SPI_Normal_Multiple.ino new file mode 100644 index 0000000..f08cbf9 --- /dev/null +++ b/BMP388_DEV/examples/BMP388_SPI_Normal_Multiple/BMP388_SPI_Normal_Multiple.ino @@ -0,0 +1,44 @@ +/////////////////////////////////////////////////////////////////////////////////////////////////// +// BMP388_DEV - SPI Communications, Default Configuration, Normal Conversion, Mulitple Devices +/////////////////////////////////////////////////////////////////////////////////////////////////// + +#include // Include the BMP388_DEV.h library + +float temperature, pressure, altitude; // Create the temperature, pressure and altitude variables +BMP388_DEV bmp388_1(10); // Instantiate (create) a BMP388_DEV object and set-up for SPI operation on digital pin D10 +BMP388_DEV bmp388_2(9); // Instantiate (create) a BMP388_DEV object and set-up for SPI operation on digital pin D9 + +void setup() +{ + Serial.begin(115200); // Initialise the serial port + bmp388_1.begin(); // Default initialisation, place the BMP388 into SLEEP_MODE + bmp388_1.setTimeStandby(TIME_STANDBY_1280MS); // Set the standby time to 1.3 seconds + bmp388_1.startNormalConversion(); // Start BMP388 continuous conversion in NORMAL_MODE + bmp388_2.begin(); // Default initialisation, place the BMP388 into SLEEP_MODE + bmp388_2.setTimeStandby(TIME_STANDBY_1280MS); // Set the standby time to 1.3 seconds + bmp388_2.startNormalConversion(); // Start BMP388 continuous conversion in NORMAL_MODE +} + +void loop() +{ + if (bmp388_1.getMeasurements(temperature, pressure, altitude)) // Check if the measurement is complete + { + Serial.print(F("BMP388_1 ")); // Display the results + Serial.print(temperature); + Serial.print(F("*C ")); + Serial.print(pressure); + Serial.print(F("hPa ")); + Serial.print(altitude); + Serial.println(F("m")); + } + if (bmp388_2.getMeasurements(temperature, pressure, altitude)) // Check if the measurement is complete + { + Serial.print(F("BMP388_2 ")); // Display the results + Serial.print(temperature); + Serial.print(F("*C ")); + Serial.print(pressure); + Serial.print(F("hPa ")); + Serial.print(altitude); + Serial.println(F("m")); + } +} diff --git a/BMP388_DEV/keywords.txt b/BMP388_DEV/keywords.txt new file mode 100644 index 0000000..f431e0d --- /dev/null +++ b/BMP388_DEV/keywords.txt @@ -0,0 +1,135 @@ +####################################### +# Syntax Coloring Map For The BMP388 +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +BMP388 KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +begin KEYWORD2 +reset KEYWORD2 +startNormalConversion KEYWORD2 +startForcedConversion KEYWORD2 +stopConversion KEYWORD2 +setPresOversampling KEYWORD2 +setTempOversampling KEYWORD2 +setIIRFilter KEYWORD2 +setTimeStandby KEYWORD2 +setSeaLevelPressure KEYWORD2 +getPressure KEYWORD2 +getTempPres KEYWORD2 +getAltitude KEYWORD2 +getMeasurements KEYWORD2 +setClock KEYWORD2 +enableInterrupt KEYWORD2 +disableInterrupt KEYWORD2 +setIntOutputDrive KEYWORD2 +setIntActiveLevel KEYWORD2 +setIntLatchConfig KEYWORD2 +enableFIFO KEYWORD2 +disableFIFO KEYWORD2 +setFIFONoOfMeasurements KEYWORD2 +setFIFOWatermark KEYWORD2 +getFIFOWatermark KEYWORD2 +setFIFOPressEnable KEYWORD2 +setFIFOTimeEnable KEYWORD2 +setFIFOSubsampling KEYWORD2 +setFIFODataSelect KEYWORD2 +setFIFOStopOnFull KEYWORD2 +getFIFOLength KEYWORD2 +getFIFOData KEYWORD2 +enableFIFOInterrupt KEYWORD2 +disableFIFOInterrupt KEYWORD2 +flushFIFO KEYWORD2 +getSensorTime KEYWORD2 +enableI2CWatchdog KEYWORD2 +disableI2CWatchdog KEYWORD2 +setI2CWatchdogTimeout KEYWORD2 +getErrorReg KEYWORD2 +getStatusReg KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### + +BMP388_I2C_ADDR LITERAL1 +BMP388_I2C_ALT_ADDR LITERAL1 + +SLEEP_MODE LITERAL1 +FORCED_MODE LITERAL1 +NORMAL_MODE LITERAL1 + +OVERSAMPLING_SKIP LITERAL1 +OVERSAMPLING_X1 LITERAL1 +OVERSAMPLING_X2 LITERAL1 +OVERSAMPLING_X4 LITERAL1 +OVERSAMPLING_X8 LITERAL1 +OVERSAMPLING_X16 LITERAL1 + +IIR_FILTER_OFF LITERAL1 +IIR_FILTER_2 LITERAL1 +IIR_FILTER_4 LITERAL1 +IIR_FILTER_8 LITERAL1 +IIR_FILTER_16 LITERAL1 +IIR_FILTER_32 LITERAL1 + +TIME_STANDBY_5MS LITERAL1 +TIME_STANDBY_10MS LITERAL1 +TIME_STANDBY_20MS LITERAL1 +TIME_STANDBY_40MS LITERAL1 +TIME_STANDBY_80MS LITERAL1 +TIME_STANDBY_160MS LITERAL1 +TIME_STANDBY_320MS LITERAL1 +TIME_STANDBY_640MS LITERAL1 +TIME_STANDBY_1280MS LITERAL1 +TIME_STANDBY_2560MS LITERAL1 +TIME_STANDBY_5129MS LITERAL1 +TIME_STANDBY_10240MS LITERAL1 +TIME_STANDBY_20480MS LITERAL1 +TIME_STANDBY_40960MS LITERAL1 +TIME_STANDBY_81920MS LITERAL1 +TIME_STANDBY_163840MS LITERAL1 +IME_STANDBY_327680MS LITERAL1 +TIME_STANDBY_655360MS LITERAL1 + +PUSH_PULL LITERAL1 +OPEN_DRAIN LITERAL1 + +ACTIVE_LOW LITERAL1 +ACTIVE_HIGH LITERAL1 + +UNLATCHED LITERAL1 +LATCHED LITERAL1 + +PRESS_DISABLED LITERAL1 +PRESS_ENABLED LITERAL1 + +ALT_DISABLED LITERAL1 +ALT_ENABLED LITERAL1 + +TIME_DISABLED LITERAL1 +TIME_ENABLED LITERAL1 + +SUBSAMPLING_OFF LITERAL1 +SUBSAMPLING_DIV2 LITERAL1 +SUBSAMPLING_DIV4 LITERAL1 +SUBSAMPLING_DIV8 LITERAL1 +SUBSAMPLING_DIV16 LITERAL1 +SUBSAMPLING_DIV32 LITERAL1 +SUBSAMPLING_DIV64 LITERAL1 +SUBSAMPLING_DIV128 LITERAL1 + +UNFILTERED LITERAL1 +FILTERED LITERAL1 + +STOP_ON_FULL_DISABLED LITERAL1 +STOP_ON_FULL_ENABLED LITERAL1 + +WATCHDOG_TIMEOUT_1MS LITERAL1 +WATCHDOG_TIMEOUT_40MS LITERAL1 diff --git a/BMP388_DEV/library.properties b/BMP388_DEV/library.properties new file mode 100644 index 0000000..3a523e7 --- /dev/null +++ b/BMP388_DEV/library.properties @@ -0,0 +1,9 @@ +name=BMP388_DEV +version=1.0.11 +author=Martin Lindupp +maintainer=Martin Lindupp +sentence=An Arduino compatible, non-blocking, I2C/SPI library for the Bosch BMP388 barometer. +paragraph=The BMP388 library can operate the barometer in either NORMAL or FORCED modes. NORMAL mode automatically samples at the device sample rate. In addition, it supports both interrupt and FIFO operation using the BMP388's external INT pin and internal 512 byte FIFO memory. +category=Sensors +url=https://github.com/MartinL1/BMP388_DEV +architectures=*