As more and more hardware related initiatives started to float around our department, we decided in February to buy a few development boards that run JavaScript code. We knew that JavaScript has a very creative community who managed to put it to good use outside the browser but running it on an embedded system was something that we had to see with our own eyes.

Transition from C++ to JavaScript

As soon as the Espruino Pico boards arrived, I was really curious to see how easy would be for me to write some code for one of them. Since I had a C++ background and no experience with JavaScript, the basic structure of any application looked funny to me at first. Despite my lack of experience, I found the language and the IDE very user-friendly, and it didn’t take long before I was trying really ambitious applications for an embedded platform.

Embedded web server

One of the first examples found online that I was eager to try was a web server with Wi-Fi. I don’t even want to think about implementing this in C++. The solution with the Espruino is similar to a Node.js implementation, so it takes about 20 lines of code. For the Wi-Fi module, I used the famous ESP8266, which is supported by Espruino through a dedicated Node.js-like module.
As hello.JS was approaching, I decided to organize a small workshop to see how people with a web programming background would interact with the platform. The experiment was a success, and anybody managed to get the onboard LEDs to blink in no time.
I also showed the platform to our visitors at Evozon Open Day, where I prepared a traffic lights state machine as a demo project. Some of them were interested to see what was under the hood so I gave them a link to my GitHub repository.

You can also see it in action here:

          

Writing asynchronous code

Although the platform has a few bugs, it was a great experience for me to experiment with this platform. Switching to another paradigm is also a great learning experience. In my case, the event-driven, asynchronous code for the Espruino was nothing like what I’ve seen before (in C++), but I realized how things worked and I didn’t let the callback hell bite me.

Will JavaScript become a trend on embedded systems?

At this point, it’s hard to tell whether or not JavaScript will become more popular with embedded systems, but I hope it will eventually supersede the current industry standard.

 

 

 Article written by Stelian Saracut

Original link