Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return individual trimming parameters. #99

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions examples/UniqueId/UniqueBMEId.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
UniqueBMEId.ino

This code shows how to read the unique BME Id from the BME280 environmental sensor.

GNU General Public License

Written: Dec 27 2019.

Connecting the BME280 Sensor:
Sensor -> Board
-----------------------------
Vin (Voltage In) -> 3.3V
Gnd (Ground) -> Gnd
SDA (Serial Data) -> A4 on Uno/Pro-Mini, 20 on Mega2560/Due, 2 Leonardo/Pro-Micro, D2 on ESP8266
SCK (Serial Clock) -> A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-Micro, D1 on ESP8266

*/

#include <BME280I2C.h>
#include <Wire.h>

#define SERIAL_BAUD 115200

BME280I2C::Settings settings(
BME280::OSR_X1,
BME280::OSR_X1,
BME280::OSR_X1,
BME280::Mode_Forced,
BME280::StandbyTime_1000ms,
BME280::Filter_16,
BME280::SpiEnable_False,
BME280I2C::I2CAddr_0x76
);

BME280I2C bme(settings);

//////////////////////////////////////////////////////////////////
void setup()
{
Serial.begin(SERIAL_BAUD);

while(!Serial) {} // Wait

Wire.begin();

while(!bme.begin())
{
Serial.println("Could not find BME280 sensor!");
delay(1000);
}

switch(bme.chipModel())
{
case BME280::ChipModel_BME280:
Serial.println("Found BME280 sensor! Success.");
break;
case BME280::ChipModel_BMP280:
Serial.println("Found BMP280 sensor! No Humidity available.");
break;
default:
Serial.println("Found UNKNOWN sensor! Error!");
}

uint32_t uniqueID = bme.UniqueId();
Serial.printf("Unique ID: 0x%08X\n", uniqueID);

}

//////////////////////////////////////////////////////////////////
void loop()
{
delay(500);
}

19 changes: 18 additions & 1 deletion src/BME280.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bool BME280::Initialize()
{
InitializeFilter();
}

WriteSettings();
}

Expand All @@ -82,6 +82,8 @@ bool BME280::InitializeFilter()
read(dummy, dummy, dummy);

m_settings.filter = filter;

return true;
}


Expand Down Expand Up @@ -119,6 +121,8 @@ bool BME280::WriteSettings()
WriteRegister(CTRL_HUM_ADDR, ctrlHum);
WriteRegister(CTRL_MEAS_ADDR, ctrlMeas);
WriteRegister(CONFIG_ADDR, config);

return true;
}


Expand Down Expand Up @@ -429,3 +433,16 @@ BME280::ChipModel BME280::chipModel
{
return m_chip_model;
}

/****************************************************************/
uint32_t BME280::UniqueId
(
)
{
uint8_t buffer[4];
bool success;
success = ReadRegister(UNIQUE_ID_ADDR, buffer, 4);
return ((((uint32_t)buffer[3] + ((uint32_t)buffer[2] << 8)) & 0x7fff) << 16) + (((uint32_t)buffer[1]) << 8)+ (uint32_t)buffer[0];
}


5 changes: 5 additions & 0 deletions src/BME280.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ class BME280
/// Method used to return ChipModel.
ChipModel chipModel();

////////////////////////////////////////////////////////////////
/// Unique Id of BME chip.
uint32_t UniqueId();

protected:

/*****************************************************************/
Expand Down Expand Up @@ -245,6 +249,7 @@ class BME280
static const uint8_t HUM_DIG_ADDR1 = 0xA1;
static const uint8_t HUM_DIG_ADDR2 = 0xE1;
static const uint8_t ID_ADDR = 0xD0;
static const uint8_t UNIQUE_ID_ADDR = 0x83;

static const uint8_t TEMP_DIG_LENGTH = 6;
static const uint8_t PRESS_DIG_LENGTH = 18;
Expand Down