[Solved] Arduino user, help clarify libraries

I’m an Arduino user, just getting started with Spark. I’d like to clarify the difference between how libraries are used in Arduino vs. Spark’s online IDE.

If I want to use a common library (servo.h, wire.h, spi.h), I shouldn’t use the #include. I can just instantiate the object, and the Spark online IDE knows what to compile in the library?

And I can see a list of libraries that Spark knows about by looking at the library window, right?

Hi @butters

Almost all of the usual Arduino libraries like servo, wire, and spi are built-in and you can just use them. See this doc for a list:


There are a couple of exceptions like Serial2, the third hardware serial port where you need to include a library. There are some things like the WiFi class that are just different since Spark doesn’t have ethernet, just WiFi.

Libraries in the web IDE are user-contributed libraries for things that are not built-in. One-wire, various chip-specific drivers, etc. can found there.

1 Like

To use custom/user created libraries you have to both “Include” them in your app using the libraries browser in the WebIDE and make sure the proper “#include” statement is added to your project. The “#include” should be added automatically but sometimes it can get deleted by accident and even though the library is added to the project it won’t be found because it’s not "#include"d. Does that makes sense?

To keep from having to edit every file/library I use, I’ve found that the following code stuffed into a file called “Arduino.h” in my sketch folders helps. It would be a small step forward if the Particle dev env would provide something like this :wink:

#include <application.h>

#define PI 3.1415926535897932384626433832795
#define HALF_PI 1.5707963267948966192313216916398
#define TWO_PI 6.283185307179586476925286766559
#define DEG_TO_RAD 0.017453292519943295769236907684886
#define RAD_TO_DEG 57.295779513082320876798154814105
#define EULER 2.718281828459045235360287471352

#define abs(x) ((x)>0?(x):-(x))
#define round(x)     ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
#define radians(deg) ((deg)*DEG_TO_RAD)
#define degrees(rad) ((rad)*RAD_TO_DEG)
#define sq(x) ((x)*(x))

#define lowByte(w) ((uint8_t) ((w) & 0xff))
#define highByte(w) ((uint8_t) ((w) >> 8))

#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))

in addition, the missing “binary constants” that the 'duino world defines for you (“B000”, “B10100000”, etc) can easily be ‘fixed’ by adding a ‘0’ in front of the ‘B’: 0B000, 0B10100000, etc.

1 Like