|By Lyza Danger Gardner
Let’s see if we can answer these questions.
The trick to getting this setup to work is to make the client hardware (e.g. microcontroller) and host system (e.g. your laptop) communicate with each other using a mutually-intelligible “language”, i.e. a common API.
Figure 2 For host computer and client hardware to communicate in this method, they both need to communicate using a common API.
Let’s imagine that we want to build a little gadget that would automatically turn a fan on when it gets warm. This miniature, independent climate control device could continuously monitor the temperature of the surrounding environment. When it gets too hot, the fan comes on. When it’s nice and cool again, the fan turns off. Let’s also imagine that we already have most of the parts we need (fan, temp sensor, etc.). To configure our automatic fan system gadget to use the aforementioned method, we’d first need to prepare the embedded hardware by uploading special firmware to the microcontroller’s program memory.
Instead of a specific, single-purpose program for controlling the fan, this firmware program makes the microcontroller able to communicate back and forth with other sources that speak the same “language” (i.e. API). That is, it turns the microcontroller-based hardware into a client, all ears and ready to do the bidding of the host computer.
Figure 3 Specific firmware converts the microcontroller into a client.
The hardware is ready to communicate—the next step is to write software for the fan, using the host computer. For the hardware and software to understand each other, the host computer needs to bark out instructions in a language the microcontroller can comprehend. To make this happen, we can write code using a library or framework that implements the common API.
Figure 4 The host needs to communicate using the common API, also.
The benefits of the host-client approach are that it’s easy to set up and supported on many platforms. What’s more, it gives you access to the entire Node.js ecosystem, while avoiding the performance and memory constraints of inexpensive microcontrollers. The down side is that the client hardware is helpless without the host—it can only do its thing when the host computer is actively running the software. And while we’ll go wireless eventually, we’ll be starting out with the simplest of host-client options—USB tethering. That means that for a while, your projects will be physically attached to your computer.
Figure 6 The Espruino platform combines small hardware boards with an IDE development environment.
Figure 7 The Tessel 2 (http://tessel.io) is an open-source platform that combines modular hardware with Node.js-driven software.
Figure 8 Several single-board computers (SBCs). Intel Galileo, Gen 2 (top); Raspberry Pi 2 Model B (bottom left); Raspberry Pi Zero (bottom right).
These single-board computers are getting cheap. At this moment, there’s the $5 Raspberry Pi Zero (at least, if you can get your hands on one—they’re notoriously out-of-stock), the $9 C.H.I.P. Even cheaper options are inevitable. There is no longer such a cost differential between low-power microcontroller hardware and legitimate tiny computers with processors that rival tablets and smartphones.