Spark Core tips and tricks

Spark Core’s team has built an incredible WEB IDE (Spark Build) to allow you to develop your application directly from your browser. When your Spark Core is connected to the internet you can deploy your code directly from Spark Build.

Spark Build includes the Spark Apps section, which displays the name of the current app in your editor, as well as a list of your other applications and community-supported example apps.

Spark Build is a powerful tool and it’s perferct for beginners; but you’d surely prefer to use your beloved text editor, thus being a lot faster.

Here some tips to improve your experience:

Use Spark CLI

With Spark CLI you can interacts with your cores directly from your terminal. First make sure you have node.js installed. Then open your command prompt or terminal and enter:

npm install -g spark-cli

Organize your code

Build a basic structure for your projects. Your first applications will be a large copy/paste of code found on internet, but with the right organization you can reuse library and easily find the code you have written. For example:

In this example I’ve divided Spark Core dev folder in 3 subfolders apps, firmware, libraries.

Compile and Flash from command line

Spark CLI gives you the ability to compile your project with all the dependent library files. For example if you want to compile thermostat_relay.ino from the above example you can run:

spark compile thermostat_relay.ino ../libraries/Adafruit_DHT.cpp ../libraries/Adafruit_DHT.h 
../libraries/HttpClient.cpp ../libraries/HttpClient.h 
--saveTo ../firmware/firmware_thermostat_relay.bin 

This command takes your library files as arguments and --saveTo defines where the generated firmware will be saved.

If build succeded you can run command to flash firmware on Spark Core:

spark flash XXXXXXXXXXXX ../firmware/firmware_thermostat_relay.bin

Replace XXXXXXXXXXXX with your core id.

Serial outputs

When your Spark Core is connected to your computer through usb you can debug it using the serial port. In my experience this is a good way to start and understand what is going on under the hood on your core.

spark serial monitor /dev/cu.usbmodem1421

Keep in mind that the serial port path can change. To discover your current connected Spark Core just run:

spark serial list

Leave a Reply

Please Login to comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.