Read pressure and temperature
What this example shows
The sensor runs in NORMAL mode, the setting begin() leaves it in: it measures
on its own at 50 Hz and keeps the newest result ready. The sketch fetches that
result ten times a second and prints pressure in pascals and temperature in °C.
Connect the breakout over I2C (3V3, GND, SDA, SCL, or a Qwiic cable)
and leave the ADDRESS jumper (JP3) at its default, 0x47.
The example code
#include <BMP585-SOLDERED.h>
// Create an instance of the BMP585 sensor
Soldered_BMP585 pressureSensor;
void setup()
{
// Initialize serial for output
Serial.begin(115200);
Serial.println("BMP585 Example - Basic Readings");
// Initialize I2C bus
Wire.begin();
// Check if sensor is connected and initialize it.
// Address is optional, defaults to 0x47
while (pressureSensor.begin() != BMP5_OK)
{
Serial.println("Error: BMP585 not connected, check wiring and I2C address!");
delay(1000);
}
Serial.println("BMP585 connected!");
}
void loop()
{
// Get new measurements from the sensor. This must be called before
// accessing the pressure and temperature data, otherwise it will never update
if (pressureSensor.getSensorData() == BMP5_OK)
{
Serial.print("Pressure: ");
Serial.print(pressureSensor.pressure, 2);
Serial.print(" Pa\t");
Serial.print("Temperature: ");
Serial.print(pressureSensor.temperature, 2);
Serial.println(" degC");
}
// Print 10x per second
delay(100);
}
Expected result:
BMP585 Example - Basic Readings
BMP585 connected!
Pressure: 101316.52 Pa Temperature: 23.42 degC
Pressure: 101316.86 Pa Temperature: 23.43 degC
Pressure: 101318.69 Pa Temperature: 23.43 degC
Pressure: 101317.38 Pa Temperature: 23.42 degC
A new line arrives every 100 ms: the pressure in pascals and the temperature in
°C, each with two decimals. Until the sensor answers, the sketch prints
Error: BMP585 not connected, check wiring and I2C address! once a second.
Functions used
Soldered_BMP585()returns Soldered_BMP585Creates the sensor object. Nothing is sent to the sensor until you call begin().
ReturnsThe sensor object.
Wire.begin()returns voidStarts the Arduino Wire (I2C) library and joins the I2C bus as a controller. Call it once, before begin(). Wire comes with the Arduino core and is not part of the BMP585 library.
ReturnsNothing.
pressureSensor.begin(uint8_t address = BMP5_I2C_ADDR_SEC, TwoWire &wirePort = Wire)returns int8_tStarts the sensor over I2C: a soft reset, a check that the BMP585 is there, then temperature oversampling 64x, pressure oversampling 4x, a 50 Hz output data rate with pressure enabled, and NORMAL power mode. The library supports I2C only.
ReturnsBMP5_OK (0) on success, a negative error code otherwise.
Parameters
| Type | Name | Description |
|---|---|---|
uint8_t | address | I2C address. BMP5_I2C_ADDR_SEC (0x47) by default; pass BMP5_I2C_ADDR_PRIM (0x46) when the ADDRESS jumper is moved. |
TwoWire & | wirePort | The I2C bus to use. Wire by default. |
pressureSensor.getSensorData()returns int8_tReads the latest pressure and temperature from the sensor and stores them in the public members pressure (float, Pa) and temperature (float, °C). Call it before reading those members, or they keep their old values.
ReturnsBMP5_OK (0) on success, a negative error code otherwise.
Putting it together
begin() is called in a loop until it returns BMP5_OK, so the sketch waits
for the sensor instead of printing zeros. In loop(), every successful
getSensorData() refreshes pressureSensor.pressure and
pressureSensor.temperature, and the sketch prints both with two decimals.