Tag Archives: microcontrollers

Spark Core

I’ve been spending some time playing with the Spark Core. This device is an open source ARM-based microcontroller with WiFi on-board. It belongs to the Spark OS ecosystem, which aims to be an easy, secure, and scalable solution for connecting devices to graphical interfaces, web services, and other devices. One interesting feature is how you interact with the Spark Core: it has support for mobile devices (iOS or Android), a Web Integrated Development Environment (IDE), and a command line.

The Spark Core devices (also known as “cores”) function in tandem  with the Spark Cloud service (also called the “cloud”) on the internet. The cloud is responsible for managing your cores, developing the core code, and loading applications on your core. Spark Cloud accounts are free and can be created on the Spark build page. Many cores can communicate with each other through a publish/subscribe messaging system made available through the cloud.

IMG_1340The Spark Core comes in a great package. The box promises that “when the internet spills over into the real world, exciting things happen.” Conveniently, the core comes with a breadboard and a micro USB cable right in the box. This all-inclusiveness makes it ideal for beginners. And it even comes with a sticker!

The easiest way to get your core up and running is to use your mobile device. Simply download the Spark mobile application and connect your mobile device to the same network that the core will use. Turn on your core and make sure it is in listening mode.  Next, use your mobile application to log into your cloud account. You will then be prompted for the network credentials to be used by the core. This will begin a search and registration process where the mobile device finds the core, connects it to the network, and registers the core to your cloud account. The RGB LED on the core shows the status of the internet connection. Once your core is online and registered to your account, you are ready to start playing it!


First, I wanted to try interacting with my core from my mobile device. This can be done using a part of the Spark mobile application called Tinker.

IMG_1346Tinker is more of a prototyping app than it is a dedicated programming environment. It allows you to simulate analog and digital inputs and outputs on the core. Tinker can be integrated with code written for the core so that an application running on your core can interface with the Tinker application on your mobile device.  My experience with Tinker was only so-so as it crashed a number of times on my iPhone 6.

Next, I wanted to try programming my core from the web through the Spark Cloud build website. To do this, I simply logged on to my cloud account which automatically loaded the web IDE. I was curious about how easy it was to import and implement external libraries. To get a feel for this, I tried to connect my core to an LED strip and control it via the Tinker app.

Screen Shot 2014-10-22 at 8.02.45 PMThe web IDE is very clean and easy to use. There are mouse-over tips to help you navigate the environment. The controls (located on the left panel of the IDE) are as follows from top to bottom: flash, verify, save, code, libraries, docs, cores and settings. Double clicking any one of these icons expands and collapses the grey information pane.

The Spark Core language is Arduino compatible as it supports the functions defined in the Arduino language specification. It also includes some extra features that enable you to do things like interact with the network settings and subscribe to specific events from the cloud. Unfortunately, many of the Arduino libraries included in the Arduino IDE have not been implemented for the Spark platform. This may create some problems if you are trying to port your old Arduino code to a core.

Screen Shot 2014-11-05 at 8.58.16 PMIncluding the Adafruit NeoPixel library was very easy. I simply searched the available libraries and clicked the import button for the library I wanted to use. All of the necessary includes were automatically inserted into my code. The library display pane also allowed me to browse and/or import the sample code from the library I selected.

Once my code was complete and verified, I simply clicked the flash button and waited for the cloud to update my core. Success!

IMG_1362Finally, I tried connecting to my core with the Spark Command Line Interface (also called spark-cli). This package is an open source command line tool which uses node.js to program your core. It  works over both WiFi and USB (which is handy when the network is unavailable). The spark-cli tool is not packaged well and was a little tricky to install. After installing node.js, I kept getting compile failures. After some digging I finally got it to work by opening XCode and accepting some license agreements.

The spark-cli tool allows you to interact with your core in a more advanced way. The command line allows you log into the core and read any serial output being generated by the application. It also enables you to manage the application running on a core, such as compiling and uploading new applications or reverting the core to its factory state. Much like Tinker, the spark-cli allows you to simulate both analog and digital input or output. It also enables you to publish and subscribe to events in the cloud so that you can communicate with other cores.

On the hardware front, it is important to note that the internal WiFi chip uses an older version of the 802.11 standard. As the Spark Core uses 802.11b/g, it won’t connect with newer 802.11n networks. I ran into this issue when moving my core between networks. In this case, I had to connect to the core via USB and use a serial connection to enter my network credentials manually. I later discovered that this could also be done via the spark-cli tool.

spark_core_serialStoring all of your code in the Spark Cloud is both a blessing and a curse. Currently, there is no easy way to version your code or to determine what version of a library is available in the web IDE. I fumbled a bit programming the LED strip because I had to dig around to see which version of the NeoPixel library was available. Additionally, Having the code in a private remote location also makes it harder to share code with other people. Because the core is programmed over the internet, it takes longer to program. This can be too time consuming if you are doing rapid iterative development.  On the positive side, remote code storage and programming means that you can easily modify and upload your application to any core from any web browser. This means no more frantic searching for the correct cable, code version, library version and so on.

To give you an idea how the Spark Core stacks up to other ARM-based microcontrollers, I compared it to two other devices in my project box:

Feature Spark Core 1.0 Arduino Due Teensy 3.1
Processor 72 MHz ARM Cortex M3 84 MHz ARM Cortex M3 72 MHz ARM Cortex M4
Memory (Flash) 128KB 512 KB 256 KB
Memory (SRAM) 20 KB 96 KB 64 KB
Voltage 3.3v 3.3v 3.3v
Regulated output voltage 3.3v 3.3v and 5v 3.3v
Cost $39 $50 $20
Size 1.47" x 0.8" 4" x 2.1" 1.4" x 0.7"
Digital pins 18 54 34
Analog pins 8 12 21
5v tolerant input pins 7 0 21
SPI yes yes yes
UART (Tx/Rx) 1 4 3
I2C (SDA/SLC) 1 2 2
JTAG yes yes no
WiFi yes (802.11 b/g) no no
Programming environment Web and Mobile IDE (WiFi), command line (USB or WiFi) Arduino IDE (USB) Arduino IDE + Teensyduino (USB)

The online nature of this device makes it a good choice for people new to Arduino programming. Since the core is internet based, setup is easier than with an Arduino as there are no FTDI drivers to install or serial issues to debug. The RGB LED used for network status is a clever way to assist beginners with debugging connectivity issues. The Spark Core shields are a great starting point for many projects. The Shield Shield makes any Arduino shield compatible with the Spark Core layout, which allows you to take advantage of the large number of Arduino shields already out there. The Spark documentation is very clear and it has a helpful community of users in case you have any questions.

Veteran Arduino programmers can enjoy the advanced features of the Spark OS ecosystem. The distributed nature of the Spark OS makes it simple to connect devices together. The publish/subscribe messaging mechanism allows devices to interact with each other in real time. The RESTful API built into the Spark Cloud makes it easy for any web service to interact with any of your devices on the cloud. On the administrative front, the command line tool gives more power to the user. I was especially pleased that I could use the command line to remotely read the serial output while the core was running.

All in all, I think this is a great board for both beginners and advanced Arduino users. Just like any new device, the Spark Core has some growing pains to work through. Despite that, it offers some great features that make it easy to look past some of the shortcomings.  The on-board WiFi is a real game changer in the hobbyist microcontroller market. I look forward to more internet-enabled projects!

DIY LED Strip Controller

On a whim I decided to add LED lighting to my desk hutch. I already had a reel of LED strips but nothing to control them. As I wanted to build a controller that afternoon, I constructed it from parts which could be purchased locally. The controller I made has an on/off switch and two knobs: one to control the brightness and the other to control the color of the lights. Here is how I built it!

This project required the following parts: two 10K ohm potentiometers with knobs, an on/off switch, a project box, a 5 volt power supply, a power jack, some wire, and a small Arduino compatible microcontroller. RadioShack sells the Arduino Micro, but I used a Teensy 2.0 I had on hand as it is a much cheaper alternative. Of course, you also need some programmable LED strips. I used some 5 volt WS2812B LED strips (similar to Adafruit’s NeoPixel strips). It’s also useful but not required to have some connectors for the LED strips so that they can be detached from the controller. I used some JST connectors from my project stash.

The first step is to make holes in the project box. I did this with my trusty Dremel. Drill five holes: two for the potentiometers, one for the power switch, one for the power jack and a one for where the LED strip wires will enter the project box. Once the box is drilled out, place the power switch, potentiometers and power jack into the project box. Solder the power wires to the components.

IMG_9702Next, I assembled the LED strips. If you are adding connectors to the LED strips, solder those on to the strips. If you’re connecting multiple strips, be sure that you bundle the wires together properly. I’ve found that using colored wire or marking wires with different colors of tape makes it easier to keep everything straight.

IMG_9722Next, solder the potentiometers and LED strips. Mark the data lines for the LED strip and the potentiometers so you know which wire corresponds to a given component. It makes coding the microcontroller easier.

IMG_9761Next, solder the microcontroller.  Keep track of the pins and their corresponding data lines. When soldering the potentiomenter to the microcontroller, make sure to connect the potentiometer data wire to pins that can support the analogRead function. These pins generally begin with the letter ‘A’.

IMG_9767Now it’s time to program the microcontroller. The simple code can be found here. Update the code to reflect the length of your LED strip and the pins that correspond to your components. Be sure to test everything!

IMG_9771Once you’ve verified that everything works, tape up any solder joints so that there are no shorts. Close up the box and you’re done!



Arduino and Motion

Today I took the Making Things Move With Arduino class taught by Ranjit Bhatnagar at NYC Resistor. I was particularly excited for this class as all of my Arduino projects have been rather stationary. This class was a great overview of some different ways to add motion to your Arduino project. It featured the Adafruit motor party pack.

We had five separate gizmos to play with: one DC motor, one stepper motor, two sizes of servos and one solenoid.

Left to right: small servo, large servo, solenoid, DC motor, stepper motor

We also assembled the Adafruit motor shield which simplifies using multiple motors with an Arduino. There was a lot of soldering to do up front but it was worth it! Once everything was assembled, we got to play with all of the different types of motors. We even got to keep the motors so the fun could go on all night long!

Arduino and Motors

What was my favorite part of the class? THE MOTOR PARTY!!! WOOOOH!!!

Arduino and Sensors

I’ve been busy putting the finishing touches on a class I am teaching at NYC Resistor called Arduino and Sensors. The purpose of this class is to teach people how to use common sensors with Arduino so they can build awesome interactive projects. The class features the Adafruit Sensor Pack 900, as this pack contains a nice selection of common sensors. I’ve written some sample code for each of the sensors in the pack. We will discuss both digital signal and analog signal sensors.


Digital signal sensors are the simplest to use. They simply return a 1 or a 0 based on the reading of the sensor (just like a switch, it’s on or off). Therefore, reading the state of one of these sensors is as simple as hooking the output of the sensor to a digital pin on the Arduino (pins 2-13 on the Uno) and calling digitalRead() on that pin. Here is a simple example – an IR sensor:


Analog signal sensors are more complex. These sensors return a voltage on an analog pin somewhere from 0 volts to the max voltage of the microcontroller (with the Uno, it’s 5 volts). In order to read an analog sensor value, the sensor output needs to be connected to an analog pin on the Arduino (pins A0-A5 on the Uno). In the code, calling analogRead() on the analog pin will give you the sensor reading. The Arduino automatically converts the voltage on the analog pin to an integer between 0 (no power) and 1023 (full power). Generally, the reading can be mapped back to some meaningful value. For example, here is a simple analog sensor – a temperature sensor:


According to the datasheet, this sensor returns 0 volts at -50 degrees Celsius and 1.75 volts at 125 degrees Celsius. It has a scale of 10 millivolts per degree Celsius. To get the raw voltage reading, we take our reading value, divide it by 1024 (to get the percentage of the full voltage) and then multiply that by 5 (since the microcontroller is supplying 5 volts). To scale the voltage to the range, we can simply multiply the voltage by 100 (according to our scale factor, 1/100 volt is 1 degree Celsius) and then subtract 50 (since zero volts is -50 degrees Celsius).

Of course, many sensors are more complex than just reading a simple pin. We’ll discuss a number of different scenarios and how to handle them. Did you ever wonder what the AREF pin is for? It’s the analog voltage reference pin and we will be discussing how to use it. We’re also going to use potentiometers to tune the sensitivity of some of the sensors.

The class is already almost sold out! If all goes well, I will hopefully teach it again soon!



Looking through some of my electronics stuff, I realized that I ten different kinds of microcontrollers! That’s not bad at all, considering that I only discovered my love of them last summer. There are five flavors of Arduino: Uno, Uno Ethernet, MEGA, MEGA ADK and Due. There are three flavors of Teensy: Teensy 2.0, Teensy++ 2.0 and Teensy 3.0. There are also two wearables: Lilypad Arduino and Adafruit Flora. So many microcontrollers, so little time!