Node.js for Embedded Systems
by Patrick Mulder and Kelsey Breseman
Copyright 2017 Patrick Mulder and Kelsey Breseman. All rights reserved.
Printed in the United States of America.
Published by OReilly Media, Inc. , 1005 Gravenstein Highway North, Sebastopol, CA 95472.
OReilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://safaribooksonline.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com.
- Editors: Nan Barber and Susan Conant
- Production Editor: Colleen Cole
- Copyeditor: Jasmine Kwityn
- Proofreader: Christina Edwards
- Indexer: WordCo Indexing Services, Inc.
- Interior Designer: David Futato
- Cover Designer: Karen Montgomery
- Illustrator: Rebecca Demarest
- October 2016: First Edition
Revision History for the First Edition
- 2016-10-06: First Release
See http://oreilly.com/catalog/errata.csp?isbn=9781491928998 for release details.
The OReilly logo is a registered trademark of OReilly Media, Inc. Node.js for Embedded Systems, the cover image, and related trade dress are trademarks of OReilly Media, Inc.
While the publisher and the authors have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the authors disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
978-1-491-92899-8
[LSI]
Foreword
It is a wonderful time to be playing with physical computing!
In the early 2000s, there were few options for any given physical computing technology. If you wanted to measure humidity you had one optionwith the annoying subtleties of that particular manufacturer. Thanks to the pressure of free market forces and open source hardware, by the mid-2010s there were dozens of manufacturers all creating similar humidity sensors. The pinouts were identical, the protocols were identical (and finally standardized to I2C), and the prices were falling. Today I dont have to wonder if the sensor came from silicon foundry X or Y, I just have to decide do I want to measure the humidity inside my lunchbox? I plug in whatever humidity sensor is most readily available and let the library handle the necessary low-level interactions to get the data. I am no longer worrying about the underlying hardware; I can instead concentrate on the user experience.
The user experience is central to the popularity of Arduino. Its simplified interface enabled the crashing of two worlds: designers and engineers. Similarly, the JavaScript and the Node.js ecosystem are easy to learn for designers and non-professional programmers. In the future the mindset of designers and users of hardware will matter more than who holds the keys to building electronics. Thanks to the Web, baseline tools (gcc, serial bootloaders, skillet reflow, etc.) are universal and now easy to master. Anyone with a hot plate and a pair of tweezers can begin making small batches of products that connect to the Internet. And thanks to the Web we can market and sell all manner of devices across the globe.
A base-level microcontroller is now ambiguous between manufacturers. Does it have serial, I2C, SPI? Does it have multichannel ADCs? Does it have good low-power performance? Is it cheap and readily available? Can I program it with the industrys standard toolchain? Nearly every microcontroller on the market satisfies these requirements. Microcontroller manufacturers are now having to develop advancements on the fringes: Does it come with BLE and WiFi? Can I reprogram it over-the-air?
The hardware industry will continue to jam more processing power into smaller spaces, with inconceivable amounts of storage and connectivity. Im not sure where we will end this next decade, but its clear that specific chip manufacturers will begin to look like the DEC and Tandy computers of the 1980s: no one cared about the hardware inside their computer; they just wanted their spreadsheet to open. Thankfully, advancements in open source software are continuing to push what us regular folks can do. Node.js and JavaScript in the browser make it possible for the vast majority of folks to move up the toolchain. I can stop worrying about whether my serial buffer is going to overrun and concentrate on the bigger picture.
I dream of the day that I can purchase a clock, a desk lamp, or a wristwatch and configure its interactions the way I want them. I should be able to plug a USB cable into a consumer product and have a known set of inputs and outputs. The compiler, or whatever it becomes, should warn me when Im doing something wrong (but allow me to do it anyway :). These new tools increase the leverage we have over hardware. But we should all remember its not the hardware, its how you use it. Lets hope better tools enable us to build things that matter.
Nathan Seidle
Founder, SparkFun Electronics
TEDx Speaker on Open Source Business
Preface
This book describes the role that JavaScript plays in embedded devices. Driven by Arduino and Raspberry Pi, there is an ongoing democratization of hardware development processes. New boards and software toolchains make hardware development more accessible, the same way full stack JavaScripts usability made programming easier to approach.
Inspired by open feedback and worldwide collaboration, there are evolving communities on the Web where people join hands to build weather stations, robots, or spectrometers (for a nice overview of this trend, see the entries for the 2015 Hackaday Prize).
Compared to those hobby projects, professional hardware development often comes with high costs of special computer-aided design (CAD) software products or additional toolchains. This is very different from web development, where the free and open source tools hobbyists use to build are often the same tools used by professionals. In open source software, the lines frequently blur between the work of professional and hobbyist: thousands of examples can be found on GitHub, where many software developers (often joined by hobbyists) build solutions for business or private needs.
The Arduino and Raspberry Pi ecosystems already heavily depend on open source projects hosted on GitHub. But for building embedded systems, GitHub is not a complete solution because it is not built for collaboration on hardware, and change detection between revisions of a hardware board can be very messy. (There are web collaboration platforms specifically designed for building open source hardware, including Upverter and Autodesk Circuits; however, these platforms are in very early stages and not yet ready for primetime).
GitHub is not the only place where you can find the ingredients to embedded systems with JavaScript. You can also turn to Hackster.io (where you can post projects and compare your design with those created by other members), or OSH Park and Tindie (where you can find ideas to assemble circuits or buyand selldirectly from and to other makers). In addition, companies such as Seeed Studio, SparkFun, Adafruit, Amazon, and eBay offer a variety of kits and ready-made devices. If you are stuck with building hardware, you can find instructional videos on YouTube or Vimeo about basic and advanced electronics.