paint-brush
Diving into Javascript on Microcontrollers with ThingsSDK with Andrew Chalkleyby@anaptfox
989 reads
989 reads

Diving into Javascript on Microcontrollers with ThingsSDK with Andrew Chalkley

by Taron FoxworthFebruary 10th, 2017
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Andrew Chalkley is the host of <a href="https://www.youtube.com/watch?v=JTDfub5Yj-Y&amp;t=1s" target="_blank">That Maker Show</a>, Project Lead of <a href="https://twitter.com/thingsSDK" target="_blank">@thingsSDK</a>, and a Teacher <a href="https://twitter.com/treehouse" target="_blank">@treehouse</a>. Hosting the interview is <a href="http://twitter.com/anaptfox" target="_blank">Taron Foxworth</a>, the Developer Evangelist at <a href="http://losant.com" target="_blank">Losant</a>.

People Mentioned

Mention Thumbnail

Companies Mentioned

Mention Thumbnail
Mention Thumbnail

Coins Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Diving into Javascript on Microcontrollers with ThingsSDK with Andrew Chalkley
Taron Foxworth HackerNoon profile picture

Andrew Chalkley is the host of That Maker Show, Project Lead of @thingsSDK, and a Teacher @treehouse. Hosting the interview is Taron Foxworth, the Developer Evangelist at Losant.

In this conversation, we focused on thingsSDK, which is a set of tools for web developers to create internet-connected hardware projects using Javascript. We also cover:

  • How Andrew got started with hardware
  • The 3 fundamental problems when it comes to hardware and the internet of things
  • Why you should use Javascript when building an app for IoT
  • The challenges when building a Javascript platform for hardware
  • How you can get started and contribute to thingsSDK

Andrew, could you give a little background about yourself?

Taron Foxworth: Before we dive into thingsSDK, could you give a little background about yourself?

Andrew Chalkley: Sure. By day I teach at online school Treehouse where I teach JavaScript and SQL among other things. By night, I’m tinkering :) I host That Maker Show, which aims to break down the barriers to entry into the Maker Movement. I’m also the project lead of thingsSDK.

I’ve been working with computers for most all of my professional life. I’m self-taught, and had development jobs in PHP, Ruby, Java and Objective-C. I’m currently stabilized around JavaScript :)

Taron Foxworth: The self-taught jack of all trades! For the record, That Maker Show is awesome! The Introduction to 3D Printing episode is what got me hooked on 3D printing.

What made you interested in becoming a maker?

Andrew Chalkley: I’ve learned so many programming languages over the years. It didn’t feel challenging to me anymore. The excitement of pushing pixels on a screen had lost it’s appeal.

So I wanted to stretch myself and get involved with hardware. I feel that I thrive the most at the edge of my current limits. And hardware was a that outlet.

Taron Foxworth: So, you turned to the physical world. Nice

What hardware or framework did you start with?

Andrew Chalkley: I started with an Arduino. The way I learn the best is to immerse myself in the language of the thing I’m trying to learn. I watched a ton of Adafruit videos and other maker videos online.

Then, I did a write up “The Absolute Beginner’s Guide to Arduino”. It still gets lots of traffic and people love it and it seems to resonate with the beginner — because I was a beginner too :)

Taron Foxworth: Yes! I love that. Beginners should write too. It sounds like Arduino + Adafruit is a perfect hardware starter kit. This leads us now to thingsSDK.

Can you tell us what thingsSDK is, and how you came up with the idea?

Andrew Chalkley: There are 3 fundamental problems when it comes with hardware and the internet of things.

  • Firstly, the cost of these development boards are quite high — especially if you want to connect an Arduino to the internet. Anywhere between $50 and $90 dollars.
  • Secondly, the programming languages aren’t that user friendly. C and C++ have a lot of challenges to new hardware enthusiasts even if you’ve been programming in a more modern language.
  • Thirdly, even if you could get a programming language on the device, there were no modern developer workflows for the professional developer. You had to use clunky IDEs.

Out of this frustration came thingsSDK. I run a JavaScript and Internet of Things group in Portland, OR. We around 500 people on the books with 30–40 people turn up every month. At the end of one our meetups, I was venting my frustration about the points above. And a close friend of mine, Craig Dennis, offered to help tackle this problem with me.

The first problem — cost. We wanted to be able open this up to as many people as possible. The ESP8266 is a cheap microcontroller module with wifi built in. Costs between $2 — $4 for a development board!

The ESP8266 can run Lua and can have Arduino sketches flashed to it. Around this time last year MicroPython was doing a Kickstarter to be ported to the boards. And Gordon Williams, of Espruino, started distributing his runtime binaries for the ESP8266. You can think of the Espruino as the Node of microcontrollers.

We created a GUI called Flasher.js to have a one click install for your ESP8266 based development boards, like the NodeMCU and the Adafruit Feather HUZZAH.

Flasher.js reduced the amount of time and friction developers had to spend getting JavaScript on the device.

To solve the third and final problem, the modern work flow, I wanted to create a CLI utility that was opinionated enough that it would be easy for current JavaScript web developers. They didn’t have to learn anything new, all they need to know is Node and npm. By simply issuing one command you can deploy modern ES2015 JavaScript to a microcontroller.

I put a short video together showing off the tools here:

Taron Foxworth: Oh so beautiful. You’re bringing the power of a convenient toolchain to the physical world. It looks like we have a question from a community member:

Why should I use Javascript for doing IoT?

Why should I use Javascript for doing IoT?

- Martin Bavio

Andrew Chalkley: Great question. Because it’s not C. I jest. JavaScript is great for event-driven programming. It’s asynchronous too. You don’t have to keep checking on the state of a button. You can implement a handler for when a button presses. When someone presses the button it triggers the code. Same goes for HTTP requests. While data is loading, you can display things on a screen. Writing non-blocking C code is possible but is challenging. To a JavaScript developer, it’s second nature. JavaScript as meant for hardware!

I have a story about how Marvell (a chip manufacturer) was building an eReader with Sony. In Japan, the firmware and UI were written in C. In the US the UI was written in JavaScript. When comparing the two devices the one in the US was performing faster than the one written in C!

I’m not saying people can’t write good C code, it’s just easier to write responsive JavaScript code :)

Taron Foxworth: Good point! The real world if event-driven just like javascript. It makes since. But, I’m sure this task isn’t trivial.

What are some of the challenges you face creating thingsSDK?

Andrew Chalkley: Great question. Where do I start? Some of the challenges are to do with the limitations of the ESP8266 devices. Having a JavaScript interpreter on there doesn’t leave much room for complex applications. But most home automation projects that require an internet connection and the ability to switch a couple pins is fine. Or if you want to drive 5 displays and have animation that’s fine too. But if you want to drive 5 displays and connect to the internet you’re pushing it. We’re exploring using the ESP32 and some other devices so people can really go-to-town on this stuff.

Other problems include being able to decipher C and Python code to write the flasher. A lot of the source code looked magic. Craig Dennis did a great job and extracted the flashing code from those languages and he’s even refactored it to be written in functionally reactive programming using RxJS. We’re hoping to do the same for other chips too.

Another challenge is not being in control of the runtime environment directly. Ideally, we’d want a small runtime with only the features you’d want in an IoT-based development board. A lot of runtimes have additional overhead and bloat. I’m currently exploring more low-level alternatives and really pushing the limits of my capabilities :)

If anyone wants to help on that front let me know :)

Taron Foxworth: So, most of the efforts have been to support ESP8266 devices. From what it looks like, the immediate future is to support more devices and figure out a more efficient runtime.

What does the future of thingsSDK look like?

Andrew Chalkley: From the outset, we wanted to make thingsSDK projects portable. The CLI uses what we call “strategies” to transpile for a targeted runtime — in our case it’s Espruino. But we’re not married to it. We — or anyone in that fact — could create other strategies for other runtimes like Kinoma’s JavaScript runtime XS6. Right now, we’re looking at creating additional abstractions to work with other devices.

In other words — if you learn the tools around thingsSDK you won’t need to learn something new even in this ever changing world of IoT runtimes and development boards.

We abstract that away from you to some degree — we’re hoping to abstract it further :)

Taron Foxworth: So fantastic! So now, I’m going to ask the golden question.

If I wanted to get started with thingsSDK, how would I start?

Andrew Chalkley: Over on http://thingssdk.com we have links to getting started guides and some simple starter projects. We also have a link to our community Slack channel and everyone is welcome.

There are low-hanging-fruit issues on our GitHub where people can contribute. We’ve had many Open Source first-time contributors help with the project so come on in!

Taron Foxworth: I can honestly say that the JS IoT Slack channel has been the best hardware resource I’ve seen so far. So many smart people in there! Andrew, thank you for leading such an awesome product. I’m excited to see thingsSDK grow and contribute to it.

Do you have any closing points you would like to add?

Andrew Chalkley: Thanks for having me! I’m really excited to see what the future holds. I think getting this technology in as many hands as possible will give birth to some awesome innovations and products.

If you’re new to hardware be sure to check out That Maker Show, our next two episodes have been shot on “Single Board Computers” and “Internet of Things” and should be coming out in the next couple of weeks! Stay tuned for more!

What Next?

Make sure you guys follow Andrew and thingSDK If you guys enjoyed this, give it a heart and/or let me know on Twitter!

This interview was originally discussed as “Diving into Javascript on Microcontrollers with ThingsSDK with Andrew Chalkley” on Sideway.

Until next time, Stay Connected 😉