[SOLVED] I2c problems with Bluz


I have a project that uses the bme280 sensor over i2c. It is working just fine with a Photon. I am using the Adafruit bme280 library from Github. When I try using a Bluz the values being returned are way out of range, for instance > 300 degrees. I am also experiencing something similar with the si1145 light sensor. With a Bluz the light sensor always returns 0 for visible light (however IR and UV index are reasonable…). Is there some extra configuring for i2c with the Bluz that I am missing? It seems to partially work because it will correctly read back the device IDs and the light sensor seems to half work.

I have tried the following with no luck:

  • Explicitly set the i2c speed to 100khz
  • Different power sources for my Bluz circuit
  • Different sensors (a breadboard with breakout boards from Adafruit as well as a custom PCB I designed with everything integrated)

I am scratching my head about what next to try to diagnose the problem. Any help would be appreciated!

Temperature/humidity device

I don’t have either of these sensors, unfortunately. We have tested bluz with many I2C devices and don’t currently have any issues on compatibility.

I did look through the BME280 library. It seems the begin() command returns a boolean indicating it was able to successfully connect. Would it be possible for you to log the return value from this and make sure it is true?

In the meantime, this device does seem to work with SPI as well as I2C. Would you be able to try that? Looks like a simple wiring change and a minimal code change.


I verified that .begin() returns true


I was just reading the Cortex M0 does not have a floating point unit. The library makes extensive use of the ‘float’ datatype. Could I be running into floating point problems?


That shouldn’t be the issue. Even without hardware, M0 can perform floating point operations in software, and we do in fact specify the necessary flags to support it, mainly -mfloat-abi=soft

I have ordered both of these sensors. Perhaps we can figure out the issue before I get them, but if not, I will try it towards the end of the week when I get my hands on them.


Awesome. Thanks for diving into this!


The SI1145 is much simpler than the BME280 so I am focusing on getting that one to work first. I just discovered that if I read the visible light twice in a row, then I got a good reading the 2nd time. The first one will always be 0.


Another update. Hooking up the SI1145 in isolation works fine. If I completely remove the BME280 from the equation then I no longer have to read the visible light register twice. I guess the problem has something to do with the BME280.


I figured it out.

In the BME280 library it has the following block of code in a couple of places:

Wire.requestFrom((uint8_t)_i2caddr, (byte)2);
value = (Wire.read() << 8) | Wire.read();

That last call to Wire.endTransmission() is the culprit. If I take those out then it works.

I need a beer.


Ugh… this was fixed in Github a long time ago. I guess this is the danger of libraries having being copied over into Particle.


Glad you got to the bottom of the issue!


I am having an issue compiling BME280 library (ported to Photon) for BluzDK.
I tried on both Particle Dev Desktop IDE and Web IDE. Still no luck. :frowning2:
Could you possibly share the BME280 library file, that you use, which is compatible with Bluz DK?
Thanks in advance.:blush:
Error on web IDE.

Error on desktop IDE.


That first error looks like the app is too big. Did you try compiling this with v2.0.50-beta.5?


Yes! It says code verified after changing firmware target.:blush:
Does the actual BluzDK need to be on the latest firmware to be able flash it?
If yes, how do I update the firmware on BluzDK? Sorry… I am quite confused. :persevere:


You just need to flash the code from the Web IDE. You will see a pop-up that tells you it will Upgrade your device to 2.0. Follow the instructions and it will handle everything for you.


After flashing the code, BluzDK cannot connect to cloud anymore. Green light keeps on blinking like every 1 sec on BluzDK. :persevere:
Below is the code… I have no idea what is interfering with the cloud connectivity.
Sorry. Formatting to the code seems not working.

// This #include statement was automatically added by the Particle IDE.
#include "Adafruit_BME280/Adafruit_Sensor.h"
#include "Adafruit_BME280/Adafruit_BME280.h"
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme;
double temperature = 0;
double pressure = 0;
double altitude = 0;
double humidity = 0;

void setup() {

  if (!bme.begin()) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  Spark.variable("temperature", &temperature, DOUBLE);
  Spark.variable("pressure", &pressure, DOUBLE);
  Spark.variable("altitude", &altitude, DOUBLE);
  Spark.variable("humidity", &humidity, DOUBLE);

void loop() {

  temperature = bme.readTemperature();
  pressure = bme.readPressure() / 100.0F;
  altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
  humidity = bme.readHumidity();



I fixed the formatting, you can add code blocks by starting with three accent characters (the one below the ~ in US keyboards) and ending the code block with three more accent characters.

To your question, my guess would be that the bme sensor isn’t hooked up properly or isn’t being detected, and the while(1) loop is entered. A while(1) loop will block all system firmware calls as we simply call the setup and loop functions in-line. So blocking the program execution like that will block it from working.

You can remove that while(1) and handle that case a different way, such as setting a flag and publishing an event. But you should also check to make sure the bme280 is hooked up and working properly