I2C not compiling with BLUZ


#1

I have an I2C library that works fine with a Photon. However, compiling with a Bluz gave first an Arduino.h error. I changed that to application.h but then I got a Wire.h error which I have not been able to fix. The error is “file not found”.

The library I am referring to is this one:

          https://github.com/garmin/LIDARLite_v3_Arduino_Library

I was wondering if anyone has a solution?

Thanks in advance.


#2

Please note that the current bluz firmware is based on 0.5.X of the Particle branch. This means that if you are compiling something on the Photon with 0.6.X that there may be features that aren’t yet in the bluz firmware. Specifically in this case, there is this: https://github.com/spark/firmware/issues/1278 which adds Arduino.h compatibility. Before the upgrade to 0.6.0, everyone in the Photon world had to remove Arduino.h and Wire.h library references, just as you do now.

We plan to upgrade our firmware to 0.6.0 in the near future, but it is not a small effort. Things change pretty rapidly and we are trying to address our own BLE based features and stay on top of Particle releases, it is quite a lot to balance.

To get your specific library working, you can do the following. Remove all references to Arduino.h and Wire.h, and in LIDARLite.h, replace them with:

#include "application.h"
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
#undef ARDUINO
#define ARDUINO 158

Then, in LIDARLite.cpp, you need to fix one line as the Particle 0.5.0 firmware wasn’t compatible with Arduino, so change this line:

Wire.setClock(400000UL); // Set I2C frequency to 400kHz, for Arduino Due

to

Wire.setSpeed(400000UL); // Set I2C frequency to 400kHz, for Arduino Due

With those changes, I can compile this library (though I can’t test it since I don’t have this device).


#3

Thank you Eric. I will try it and update.


#4

T H A N K Y O U Eric. The changes you proposed worked. I appreciate it.

If I connect 2 I2C sensors to the same board, are there any changes needed to the code you sent (I understand of course they have to have different addresses)?