Multiple Adafruit libraries causing I2C conflicts <Wire.h>

I am using three libraries (Adafruit_ADS1X15, Adafruit_AM2315, Adafruit_BME280) sourced from Particle: include library to connect to three I2C devices. From there I had two bugs.

  1. While testing each device independently, the AM2315 and BME280 libraries Wire->begin() would cause firmware corruption after multiple compiles. The firmware would compile and flash to the device without issue, but would immediatly turn solid white and the d7 LED would blink at 1Hz. This issue was resolved by removing offending Wire->begin() calls and #include Arduino.h statements in the two libraries.

  2. With each device is working independently, another issue appeared. When all three are used simultaneously the ADS1X15 and BME280 are functioning correctly, but the AM2315 fails to read from I2C.

Removing the Wire->begin() calls seems like a pretty hacky fix. Is there a standard way to deal with this issue? Has anyone else run into issues with <Wire.h> in Particle vetted libraries? Any help would be greatly appreciated.


Could there be an I2C address conflict with AM2315? Is there anywhere to select the address? Adafruit libraries generally need some porting to Particle.

Calling Wire.begin() multiple times does not cause a problem in my experience.

Generally Arduino.h include is not required if you have Particle.h unless there is something used that relies on a #define.

The community libraries are not vetted by Particle.

Checking the warnings in the compile is usually a good way to see where there may be problems.

Looks like you were right, the Adafuit libraries required porting.The issue was fixed by removing every reference to Arduino.h and Wire.h library and replacing them with particle specific functions. There were no warnings before or in the compile, everything looks clean until the firmware is running.

This was an easy enough fix once the offending code was identified. I am relatively new to Particle and I’m loving it so far. However, I have been running into more undiagnosed issues than I am used to on other platforms. Have you noticed this at all?

This shouldn’t be required for newer device OS versions since additional compatibility macros were incorporated in Particle.h and some “dummy” files got created to get rid of these pesky file not found messages.
Just make sure you target a fairly recent version.