A JavaScript Interpreter For ARM ‘micros

When programming a microcontroller to do your bidding, you only have two choices. You could write your code in a proper language such as C and cross-compile your source into a piece of firmware easily understood by a micro. Alternatively, your could load an interpreter on your microcontroller and write code via a serial connection. Interpreters are a really fast and easy method to dig in to the hardware but unfortunately most microcontroller interpreters available are based on BASIC or Forth.

[Gordon] figured it’s not 1980 anymore, and interpreters for these relatively low-level languages aren’t a good fit with the microcontrollers of today. To solve this problem, he created Espruino, a JavaScript interpreter for the new batch of ARM development boards that have been cropping up.

Espruino is designed for the STM32VL Discovery board, although [Gordon] plans on porting his interpreter to the Arduino Due when he can get his hands on one. Installation is as easy as uploading any other piece of firmware, and even though [Gordon]’s STM32VL doesn’t have a USB port for a serial terminal, it’s a snap to connect a USB to TTL converter and get this interpreter working.

Espruino isn’t open source yet, only because [Gordon] would like to clean up his code and write a bit of documentation. He’d also like to make Espruino profitable so he can work on it full-time, so if anyone has an idea on how [Gordon] can do that, leave a note in the comments.

42 thoughts on “A JavaScript Interpreter For ARM ‘micros

    1. True, and there’s the BeagleBone too. They’re not very lightweight though – run them off a few AAs and see how long they last…

      Also generally you don’t want your torch/etc to take 30 seconds to boot!

    2. The RPi with Archlinux takes ~10 seconds, maybe too long for some. Torch/etc? You mean torch, like a flashlight? Who needs to run javascript on their flashlight? LOL actually I use my HTC Incredible 2 for a flashlight. It has a flashlight app and not only runs javascript but lots of other stuff. Seems I recall it being built with an ARM processor of some stripe.

      1. Yes, flashlight – Maybe you want to hack one to flash out morse code. For someone with minimal programming knowledge but a desire to do things like that, Espruino is perfect.

        I’m just thinking of small projects that I’ve seen people put together with Arduino. Things like Plant Waterers, Cocktail Makers, Time lapse photography, etc.

        Those types of things don’t require lots of CPU power, but being able to code them quickly and get instant feedback is a real bonus.

      1. Actually, to clear things up; I think it’s a good project, and you have all rights to profit from it–just not from my ideas, as HAD seems to sum it up (I didn’t see any such requests on your site, so I apologize for that).

    1. Perhaps because you’re not interested in just doing it yourself but you support the maker/small entrepreneur world and want to see this guy succeed because it’s not only a good thing to do but it benefits others by availability of a neat, new dev environment.

  1. While it’s nice to see more development tools for the ARM, I disagree with the assessment that interpreters based on BASIC are ‘Unfortunate’, or that they’re not a good fit for microcontrollers. Actually, I think it’s the phenomenon of interpreters that belong in the 1980’s. I built a very capable POCSAG decoder (Think old pager signals) in an 8051-compatible Atmel chip in compiled BASIC over 10 years ago. 15 years ago, I made a graphic fire alarm annunciator in BASIC.

    Sorry, sometimes I just get tired of all the ignorant Anti-BASIC prejudice.

    1. I learned many types of BASIC in my childhood… really cut my teeth in programming and tinkered with all the TRS-80, apple ][, commodore etc. Imagine my glee when comping across the Microsoft QuickBasic compiler. I immediately purchased it for around $80 at a Babbages in Canton Ohio on the assumption that it really did produce compiled code.

      Imagine my disappointment, when I realized that all it did was wrap up the QBasic interpreter and the source code texts into a self-extracting-and-running exe of sorts.

      BASIC itself is perhaps just fine, but Microsoft proceeded to make it one of the worst programming languages ever. Just trying to shed some light on the anti-basic prejudices coming from my camp.

    2. +1. There’s nothing at all wrong with BASIC itself.

      Of course a version of BASIC from the 80’s is going to suck. Most languages from the 80’s suck. Yet when someone ports BASIC to a MCU, they typically port a dialect of BASIC from that era with line numbers and GOTO; instead of any modern dialect, with structured programming and object support. That’s not BASIC’s fault.

      I guess some folks would rather be trendy and go for a new language, instead of acknowledge that old languages are still around, have been updated, and are still competitive. I can think of no better testament than to mention even good old VB (not VB.NET) still has four times more users than JavaScript, according to last month’s TIOBE survey. It was for a long time the world’s third most popular language, behind only C and C++. And if Microsoft had handled .NET better and without alienating so many programmers, I think VB.NET would today be at least as popular as Java, if not more so.

      Still, that doesn’t stop someone from putting a decent BASIC on an MCU if they wanted. And I agree there’s a certain hypocrisy in claiming BASIC is stuck in the 80’s in one breath, then asking how to profit off an 80’s-style interpreter in the next.

      1. I refuse believe the accuracy of any poll that claims VB classic has “four times as many users” as Javascript. Everyone who visits a modern web page “uses” javascript, whether they know it or not. That’s just a completely ridiculous claim.

      2. The only reason there millions of pages using javascript is because its the only language in a web browser thats commonly supported by them. So thats not a relevant argument sorry..

        Its like going to Spain and saying well Spanish is the best language because everyone here speaks it. Well more or less its the only language thats spoken…
        .

  2. this makes me immensely happy. javascript gets a lot of hate, but i find it to be very fun. i think it’s a better fit for rapid prototyping than a language like C++, even with simplification thanks to things like the arduino environment.

  3. He could look up the business evolution of Superwaba/TotalCross, which was a Java-like VM originally for PalmOS that migrated from free open source to some profit-from-support scheme.

  4. Money could be made like the other opensource projects do:
    – sell support to corporates
    – get sponsor money for porting
    – get invitations for speaking
    – sell books on the topic
    – etc
    Prerequisite for all of the above is that the project gets traction first.

    Alternatively one could:
    – design “node.js-on-a-chip” stuff, there’s a market for java on a chip as well..
    – try to get a job with the node.us guys

    1. Thanks for the input!

      I hadn’t considered a lot of those, like the book/talk side of things…

      In terms of support, I’d have hoped that the people using TinyJS would be amateurs and people tempted over from web development – so I can’t really sell support to them!

      I’ve been hoping that some board manufacturers would pay for the work required to port it to their board. It’d be even better if some would pre-install it, but I may be being too hopeful there!

      1. Mind you, imho most of the projects where the maintainer does make a living out of it did not start for the money. They started because they were passionate about their idea. Only when their project became a hit, they started spending enough paid time on it to be able to quit their daytime job. Becoming a hit requires a lot of elbow grease and a bit of luck …

  5. That’s very interesting, i searched something like this one year ago and ended up using Squirrel because i couldn’t find any js engine that was simple enough to integrage in my project. The javascript engines in recent browser are kind of compex, have many advanced features that i don’t need (like JIT compilation) and are not very easy to port.
    Squirrel has a C-like syntax, is object oriented and is very portable.
    I’ll keep an eye on Espruino and tiny-js for the future, while the language has some downsides it’s very easy to use and i can easily remember the syntax.

  6. I’m sure people will argue this but personally I find this counter productive. C andC++ hey why not objective c are amazingly strong programming languages and as someone who has worked with hardware and software I find c is a top notch way to go, other than going to assembly languages which require much more specific knowledge of a specific chipset and time. (This route for optimization only..)

    After all most languages like javascript are based on c. And projects no matter what type they are are done better with a strong knowledge of internals… and c helps that. When in rome do like the romans and c is more like the roman language of these chips. Also if time is spent creating good c/c++ libraries one shouldn’t find it more difficult to program than javascript. Personally myself and many coders I have worked with cringe at javascript even though it is a necessary evil in web development . Also c produces smaller binaries leaving smaller footprints and more space to use on the chip… and this is something that is scare on these chips.

    My advice when I see projects like this is to have people try to collaborate to create a great framework like Apple has done not only in code but in documentation. Maybe even using objective-c….

  7. When are we going to get a real language featured in these popular blogs? How about Limbo, and the Inferno OS? Inferno arose about the same time as Java, its bytecode is more efficient than Java’s, it’s very easy to port…

    Or if you want C, try Plan 9 where every compilation is a cross-compile. You want to build for arm, you set one environment variable & go. You even get the compiler with the system.

    1. I forgot to mention Inferno’s shell. For one thing it has modules, for another with the whole system running on a bytecode machine, forking off shell tools is pretty-much zero-cost.

  8. The only way I could think of to make money off of this is to sell some sort of ide with all the conventional syntax highlighting and code refactoring and formatting, and then possibly sell support for it.

    No real experience, just what I thought would make a decent business model.

    1. Same as “compiled” code.

      However, the whole premise of the effort is fundamentally flawed. BASIC and Forth and so on are every bit as viable on these embedded platforms (especially Forth, for that’s its whole niche!!). Porting Javascript would be a disaster.

      Remember that embedded devices are called embedded devices because they need to be low power. I’d rather spend 100 cycles calculating something in Forth than 10,000 in Javascript (thanks in large part to the 10x performance hit due to interpretation and another 10x due to memory consumption rates and the overhead of GC). The power savings alone is palpable.

      He’s free to port Javascript all he wants. I still won’t use it.

      1. No problem – I’m not trying to take over the world with it. I’m just trying to make some people’s lives easier.

        An interesting point though: Compiled Arduino code of:
        void loop() {
        digitalWrite(1, digitalRead(0));
        }

        Will be significantly LESS power efficient than:
        setWatch(“digitalWrite(1, digitalRead(0));”, 0, true);

        Because the JS interpreter can put the device into a low-power mode while it is waiting for the input to change.

        Sure, you could do that in C – but I bet most Arduino users will never bother.

    1. Hadn’t thought about ads… Definitely sponsored how-to videos would be cool.

      With Stellaris – not yet. Unfortunately these boards all have different APIs for accessing the hardware, so it’s not just a job of recompiling.

      When more boards are done it’ll be great though – you should be able to run the same code on whichever board you have.

  9. Gordon, never mind the nay sayers. JavaScript little understood language with features in advance of C++ or Java. It is a perfect fit for event based programming as many embedded systems require. Node.js has shown us how useful it can be outside of the browser and despite what the ignorant say is damn fast. I have javascript almost equalling C++ performance in some server tasks.

    That leaves the little problem of finding the space to put it on a small embedded system.

    I would suggest you make a version fro the Raspberry Pi. There are a lot of people in that world who clamour for “bare metal” programming without Linux or whatever OS.

    If you could get Espurino up on the Pi and enable users to add drivers/modules in C or C++ I’m sure it would get attention.

Leave a Reply to GordonCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.