Adapting the TMP102 temp sensor library to work with Bluz


#1

I’ve been working on connecting the TMP102 temperature sensor from SparkFun to Bluz and I have it working great!

But I’ve had to change the #include’s in .h and .cpp to get it to compile. My question is how can I check this library in, in such a way that it still builds fine for the Arduino projects that it was created for, but also can be built for Bluz or Particle?

I’ve removed the following from the header:

#if defined(ARDUINO) && ARDUINO >= 100
 #include "Arduino.h"
#else
 #include "WProgram.h"
#endif
#include <Wire.h>

and replaced all of that with this:

#include "spark_wiring_usbserial.h"
#include "spark_wiring_i2c.h"
#include "spark_wiring_constants.h"

Are there some defines that I can check? I’ve been using the Particle Dev IDE to build this application.

I’d love to make this library available to everyone after it can be setup to build for all kinds of hardware.


#2

It looks like PLATFORM_ID can be used for this. I’ve replaced it all with this:

#if PLATFORM_ID == 103 || PLATFORM_ID == 10 || PLATFORM_ID == 6
	#include "spark_wiring_usbserial.h"
	#include "spark_wiring_i2c.h"
	#include "spark_wiring_constants.h"
#else
	#if defined(ARDUINO) && ARDUINO >= 100
 		#include "Arduino.h"
	#else
 		#include "WProgram.h"
	#endif
	#include "Wire.h"
#endif

Please do let me know if I’m off the mark on this one.


#3

You beat me to it, I was going to suggest that very thing. There are other Particle device with different Platform ID’s that you may want to include, the Core is 0 for example, but what you are doing is perfectly fine.


#4

So how do I go about contributing this library for everyone to use?


#5

You can follow the tutorial here to make it available in the Web IDE for anyone: https://docs.particle.io/guide/tools-and-features/libraries/#contributing-libraries


#6

For right now my library is located here and it works great with the Bluz.

https://github.com/karnlund/SparkFun_TMP102_Arduino_Library/

I have it sending a temperature to the particle cloud that triggers an IfThisThenThat rule that turns on the fan on our Nest when it’s above a certain temp.