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

Unique fingerprint BME280 #98

Open
Bolukan opened this issue Oct 28, 2018 · 12 comments
Open

Unique fingerprint BME280 #98

Bolukan opened this issue Oct 28, 2018 · 12 comments

Comments

@Bolukan
Copy link

Bolukan commented Oct 28, 2018

Expected behavior

I would like to fingerprint each BME280 using the hash of the individual trimming parameters. I need a function that returns a copy of uint8_t m_dig[32].

Actual behavior

Individual trimming parameters are not public.

@Bolukan Bolukan changed the title Expose m_dig Unique fingerprint BME280 Oct 28, 2018
@finitespace
Copy link
Owner

finitespace commented Oct 28, 2018 via email

@Bolukan
Copy link
Author

Bolukan commented Oct 29, 2018

Took right a shot: Changes

The receiving array has to be supplied by reference. The function returns the reference to this array (so not void, see below an example).
Alternative was to return a struct. The advantage would be the parameters (dig_T1 - dig_T3, dig_P1 - dig_P9 and dig_H1 - dig_H6) could be added. But I don't need them now, so I prefer keeping it simple.

Please comment, I am not proud on the long function name, but thought it should be descriptive.

Example use:

uint8_t parameters[32];
CRC32 crc;
uint32_t checksum = CRC32::calculate(bme.compensationParameters(parameters), 32);

Serial.printf("SensorID: 0x%08X\nHash(CRC32) of ", checksum);  
for (int i=0; i<32; i++) Serial.printf("%02X ", parameters[i]);  
Serial.print("\n");

Output:

SensorID: 0x27F4DEF5
Hash(CRC32) of CF 6C AF 65 32 00 54 91 5F D6 D0 0B 66 1D BC FF F9 FF 0C 30 20 D1 88 13 4B 47 01 00 1A 20 03 1E

@Bolukan
Copy link
Author

Bolukan commented Nov 23, 2018

Little bump as your first reaction was so quick.

@zoomx
Copy link

zoomx commented Nov 26, 2018

I believe that the simplest way is to add this in the library.
If I have understand first you have to call the ReadTrim private function and then you have all data in m_dig private array.
Then you can have a pointer to this array (so I believe it should be public) and calculate the CRC or calculate the CRC inside the library.

@Internetwurm
Copy link

Internetwurm commented Dec 22, 2019

BME280_ID
Hello Bolukan,

in the past i discovered this and it really works as suggested by Bosch.
https://community.bosch-sensortec.com/t5/MEMS-sensors-forum/Unique-IDs-in-Bosch-Sensors/td-p/6012

This is how you read the unique ID in any BME sensor.
As suggested it should work same way for BMP and also the 680 sensor.

Edit: I added example screen for two BME280 sensors.
Here is my code for grabbing and building the ID.

uid_regs0[0] = BME0.readRegister(0x83);
uid_regs0[1] = BME0.readRegister(0x84);
uid_regs0[2] = BME0.readRegister(0x85);
uid_regs0[3] = BME0.readRegister(0x86);
unique_id0 = ((((uint32_t)uid_regs0[3] + ((uint32_t)uid_regs0[2] << 8)) & 0x7fff) << 16) + (((uint32_t)uid_regs0[1]) << 8)+ (uint32_t)uid_regs0[0];
Serial.print("BME0 ID: ");
Serial.println(unique_id0, HEX);
Serial.println("");

@Bolukan
Copy link
Author

Bolukan commented Dec 22, 2019

Fantastic. Let’s have this implemented !

@Bolukan
Copy link
Author

Bolukan commented Dec 27, 2019

Implementation: https://github.com/Bolukan/BME280/
Example for use is added

@zoomx
Copy link

zoomx commented Dec 28, 2019

Example show an error here (IDE 1.8.10 and AVR core 1.8.2)
Serial.printf("Unique ID: 0x%08X\n", uniqueID);
'class HardwareSerial' has no member named 'printf';
print doesn't work too
no matching function for call to 'print(const char [19], uint32_t&)'

this compile but not tested

  uint32_t uniqueID = bme.UniqueId();
  char buffer[19];
  sprintf("Unique ID: 0x%08X\n", uniqueID);
  Serial.print(buffer);

@Bolukan
Copy link
Author

Bolukan commented Dec 28, 2019

You are right: printf is not available for all Arduino family members. I will use your code to adapt the example. Thanks for testing!
For me (using esp8266) it worked: I got different numbers for different BME280's

@zoomx
Copy link

zoomx commented Dec 28, 2019

I thought it was ESP8266 code, that's the reason I specified the AVR core.
Thank you for your unique ID add, it is very useful when you calibrate this sensor so you can easily associate calibration data with sensor as one can do with DS18B20.

@Bolukan
Copy link
Author

Bolukan commented Jan 5, 2020

Example updated (Btw, 19 would be too small)

@finitespace
Copy link
Owner

Has a pull request been created for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants