We just shipped Spark Libraries to the Build IDE. This feature let’s you pull in firmware code from GitHub and reuse it in your applications. Thanks so much to the incredible folks in the Spark community for providing the input to build this feature–we could not have done it without you! Here are a few links to get you started:
Blog Post: Get started. Include a library in an app.
Neopixel: An implementation of Adafruit’s NeoPixel RGB LED Library for the Spark Core by BDub
Thermistor: A simple class for calculating temperature from simple 10K negative temperature coefficient (NTC) thermistors by wgbartley
Also, a few rough edges we’re currently aware of as well:
Limitations
Libraries cannot depend on other libraries.
You can’t yet fork examples from the library, you need to copy and paste into the app that includes the library.
Bugs
Non UTF8 source files break things; there should be a validation.
Upgrading a library in an app requires you to first remove it from the app, then re-add it.
There are some edge cases where “number of including apps” metric is not correct.
If you happen to run into snags or bugs with this feature, please report it here and we’ll try our best to get you unstuck. Additionally, two very simple workarounds that often fix the subtle IDE bugs include 1) refreshing the page, or 2) creating a new app and copy and pasting things into it.
Please let us know if you have questions or comments too.
We’re excited to see what you do with this feature!
Hi, I am completely new to the Spark community and a novice Arduino enthusiast. I just received my Spark Core yesterday and have been struggling with trying to compile an existing Arduino sketch. In particular, can someone post how I can include Spark Libraries.
For my sketch I need the following libraries: Time.h, String.h, LiquidCrystal.h and stdlib.h in my code?
When I compile I keep getting the error “…bruster999/ArduinoLibraries/Time/Time.h: No such file or directory”.
Hey @Bruster , many of the libraries you’re accustom to using with Arduino are available without needing to make explicit #include statements. Check out http://docs.spark.io/firmware/ for lots of documentation and examples! I’m fairly certain that all of the functionality in Time.h, String.h, and stdlib.h are available without an #include statement.
The Liquid Crystal library will require some additional custom code, check out this thread for more information. This library has not been imported and published into the Build IDE, so it still requires a bit of copy and pasting to get it to work.
Thanks for that. I'm new to GitHub (ugh) as well as Spark and I'm having trouble getting the Build app to recognize my library when I upload it. Can you point me to a how-to on adding custom libraries via GitHub?
Also, how can I tell what libraries are available (Time, stdlib, etc.)?
I’ve managed to port 5 libraries today, and I’m still a relative noob to C/C++, so it’s not terrible to create a library. I have definitely gotten much better/faster at it.
I don’t know where to find what stuff is already available in the core firmware. If you get errors with variable types not being found (like uint16_t, uint32_t, etc), add #include "application.h" at the top of your .h file. Some math functionality like pow() and log() are not included by default, so you’ll want to add #include <math.h> at the top of your .h file as well.
…additional info. I have uploaded the files to the following location on GitHub:/bruster999/ArduinoLibraries/LiquidCrystal_I2C. I have uploaded this to the Build app as well, however, when I click the ArduinoLibraries icon then the “Verify” button I see a blank screen to the right so that in itself is suspect.
Here is my include:
’#include “ArduinoLibraries/LiquidCrystal_I2C/LiquidCrystal_I2C.h”’
Is this the correct format/syntax for the include?
You’ll need to make a new repository for each library you wish to import into the web IDE. So you can take your code from ArduinoLibraries/LiquidCrystal_I2C/* and create a new LiquidCrystal_I2C repository from that code.
Just playing with creating a library from a general purpose function I wrote into one my my first applications. Seems like the only way I can use a library is to publish it and make it available to the world, which is a bit annoying cos I’d quite like to test it works first…
Private libraries would be nice. It might be something easy to add just by toggling a flag in the web IDE, but I don’t want to assume too much!
It does not automatically update changes from GitHub. You will simply need to increment the version number in the spark.json file and contribute it again. It’ll still list older versions in your view of the web IDE, but I think it only shows the latest version to other users. I know they plan on allowing users to do a little more clean-up, but they wanted to push the library functionality out to users ASAP. You can bet it’ll get better every sprint cycle.
I'm feeling kinda foolish here as I still cannot get the library into Spark. I took wgbartley's advice and created a new LiquidCrystal_I2C repository in GitHub (repo is bruster999/LiquidCrystal_I2C where bruster999 is my account name). In Spark I clicked on the "Contribute Library" button then entered "bruster999/LiquidCrystal_I2C" in the entry field and clicked on the Add Repository button. No errors appeared. The next screen shows text in the left panel - "Current Library" and below it is my library name - "LiquidCrystal_I2C". There are two buttons, "Validate" and "Remove Library" on the left and a blank white screen on the right panel. Clicking on "Validate" does nothing. Clicking on Remove Library removes the library. I never see the "Include in App" button, there are no files listed and I see no way of publishing it.
Why is Spark not importing my library? What Am I doing wrong?
You'll need to structure the files similar to the uber-library-example. If you're still having trouble, I can try to help set it up for you after I get all the kids to bed tonight.
Thanks for bringing this issue up and suggested solution, good idea. There definitely needs to be a way to iterate more quickly to ensure the library behaves as expected before publishing to everyone.
It is temporary. The game plan was to get library support out in the wild and hammer out the kinks that didn't crop up in development. Once it's settled, library dependencies and possible git submodule support would begin work.
@jgoggins, Feel free to tell me to shut up if I "oversold" something.