There are a ton of people out there that can program in JavaScript, but give them an embedded device, and they’re up the creek without a paddle. Not anymore, that is, thanks to [Gordon]’s wonderful Espruino, a JavaScript interpreter for ARM microcontrollers. Oh, it’s also a very capable dev board that has more than enough power to turn just about any project you can imagine into reality.
On board the Espruino is an ARM Cortex M3 in the form of an STM32 chip, 256kB Flash, 48kB of RAM, and a ton of PWM and ADC pins to go along with 2 SPI ports, 2 I2C ports, and 2 DACs. It’s a very capable piece of hardware, and if you’re looking to build anything, it would be hard to pick a better general purpose dev board.
[Gordon] has put his board up on Kickstarter, and since it’s already been successfully funded, he’ll be releasing the hardware and software sources under an Open Source license. If you’ve ever wanted to run JavaScript on an ARM board, it looks like Espruino is just the ticket.
*There are a ton of people out there that can program badly in JavaScript
JavaScript is a scripting language not a programming language.
Um, that comment is sooooooo 2001.
Has something changed since 2001 that I am unaware of?
nothing, nothing at all ;)
That’s if you define “scripting” as completely different from “programming”.
Personally, I view it as a subset of programming, where you happen to be using a scripting language.
Assembly? Machine? Java? Javascript? C? All programming to me, but at different levels of abstraction, and with different toolsets and libraries.
Well a programming language is defined as a script that compiles to a machine code (C, C++) or a Pseudo machine code (java, C#, Python). Since a scripting language is read by an interpreter, and not compiled to machine code it is a scripting language. it is a mater of semantics, nothing more.
.. except that most modern browsers compile JS to machine code for improved execution speed. See “JIT”, e.g. https://blog.mozilla.org/javascript/2013/04/05/the-baseline-compiler-has-landed/ . Javascript is a fairly nice programming language that’s been trapped in an awkward environment since birth.
Where did you get your definition from? Scripting languages are a subset of programming languages – you still program. Check out: http://en.wikipedia.org/wiki/Programming_language#Implementation
I consider scripting being programming without having to manage memory, mind buffers or pointers and all that jazz. In scripting those things are being taken care off for you.
@voxnulla
That would make C#, D, and Java scripting languages.
The point of that “sooo 2001” comment is that the range of technologies available has broadened such that scripting/programming distinctions don’t actually make a whole lot of sense except in particular contexts.
I think of scripting in a shell-script kind of way. Tying together fully implemented programs that actually do most of the work. The scripting just does a bit of basic guiding and routing between them.
Programming is creating a program from scratch. No library by itself does anything useful.
“That would make C#, D, and Java scripting languages.”
The way these are used, I would indeed agree that these languages are more often than not scripting languages.
It makes no sense determining what is or isn’t programming on whether you first have to produce a machine understandable binary, or that this is done JIT/at runtime.
Perhaps a better way of looking at is is this : To program you have to understand the hardware, to script the hardware is arbitrary.
I’d’ve said “horrible stapled-together misbegotten abortion”. Out of all the languages to take over the world… I’m really starting to believe that there are gods and that they really enjoy fucking with us.
FWIW BBC BASIC had a lot of expansion potential, why not that? Or INTERCAL?
I do agree, When I started programming I picked up Basic and what then was the first iterations of JavaScript. and I though I was a good programmer. until I got to college. It was then that I leaned how to program, and not just duct tape code together.
Are you putting down the handyman’s secret weapon?
Sure, bitch and moan about semantics, that’s what nerds do, but please leave duct tape out of this. ;)
Just wait a couple years. You will figure out that you are a terrible programmer unfit of the title.
Happens every few years.
Who wrote this crap?
*Looks at svn blame tool* -> Oops
I know that feel -_-
Oooh, I remember a beautiful early book on Javascript. It was specifically about doing graphics programming with it. The whole book relied on the scheme of doing a, say, 200×200 grid of individual 1-pixel sized GIFs. Replacing each GIF by index with one of whichever colour was the basic pixel-plot. From there it went on to implement the standard methods of drawing lines and circles and things. Like a book on graphics from the 1970s, bizarrely hammered into a web browser!
It was a heavy book! And somebody published it! Which means that somebody might accidentally have ended up buying it! This was back around 10 years ago, when the CPU and RAM of most computers would’ve meant watching the “pixels” change before your eyes. Assuming it didn’t crash the Javascript interpreter in versions of Netscape at the time, which it certainly must have.
Hu. They are really pushing this. This is the second HAD post on this device.
Source http://hackaday.com/2012/10/05/a-javascript-interpreter-for-arm-micros/
Perhaps I easy to please or hard to tick off. In either event a second post in nearly a year seems to be a follow up, not pushing something.
Makes sense. For some reason I thought they were the same post. My bad.
Right you are, maybe we should have include “Update:” in the title. Either way I think this warrants a new post since it’s pretty interesting stuff.
Not the worlds first, lol
Even Parallax has one, I use to program in JS on it years ago, for embedded JS theory when I lectured.
I think that’s Java? Could be wrong though ;)
sorry for 2nd post, but I dont see this as open source, it says if I want my program to start when device starts, I have to pay $4.95, and I cant find the source code either.
The author says it will become open once they complete the kickstarter campaign. I can understand it, but now that the money goal has been met let’s see if he keeps his word.
In the meantime I would give a look at Elua (http://www.eluaproject.net) which seems much more powerful, is already open source and comes from a very powerful, compact language aimed from scratch at programming and not web page automation.
There is that virtue known as patience ;) Clearly stated from the beginning it will be released as open source after the kickstarter is fully funded, kickstarter has stated that will take place later this month. In the event the creator decides that the pledge amount is sufficient for release, release should be impending.
The $4.95 is because I haven’t updated the images since before the KickStarter. If you go to register it does remind you that it’ll be completely free in 3 weeks :) When the campaign completes, I guarantee I’ll release the source code though.
I’m not releasing right this second because I want a bit of time to tidy it up – I think that’s probably reasonable :)
@Gordon – nice work. Something I’ve wished I had time for and probably still don’t, but it is very edifying to see someone skilled bring this sort of thing to the geek public. A big thank you for your time well spent on something I hope many will enjoy. Hopefully, I will find time to join them!
Let’s not forget that node.js will run on a Raspberry Pi.
But that uses around 250mA (model B) and Espruino uses 0.2mA :)
Gordon, that is awesome. Good point.
Tessel board make the same… http://technical.io/
no need for hate… no one forces you to use them
With the way it manages variables and memory, Javascript seems like a really bad choice for embedded system.
Do you mean how JavaScript works or how JavaScript is often implemented? Implementations often suck in one way or another, but the specification for JS is pretty impressive for a lot of reasons. Memory management is up to the implementor and some, like IE, really do a bad job at it. I suspect Gordon, having an embedded system as his target has made a tight implementation, though I won’t know till I can see what he’s done in more detail. Just a hunch though.
What am I missing? JavaScript runs in a browser to add another layer of processing to the data that gets returned by a Web server, just before showing it to a human. Or to respond to user input within the page that got returned by a Web server.
I can understand JS on a Raspberry Pi – you can hook up a monitor to it – but an MCU? Who or what is the recipient of the data processed by that JS?
The device itself or whatever you have connected to it. Very little machine instruction is created for human readable output.
Were you recently defrosted? check out nodejs, javascript moved out of the browser jail long ago.
Good idea. More viruses and script kiddies for embedded systems. That’s what we need.
I’m still waiting on *duino board that supports Brainfuck.
What!!! You don’t like lolcat.
Am I the only one who thinks that 48kB RAM might be a bit tight for running a high-level interpreted language like JS?
I’m sure you’re not – but I’ve spent a very long time trying to make it as efficient with memory as possible, and I think you’ll be surprised how capable it is.
48K RAM would be useless if your interpreter was written in an intermediate language but it’s very useful if you interpreter is written in the devices native assembly.
This is really neat. Javascript can be a powerful language if you learn it properly. I might have to pick one of these up!
@Gordon,
What about interrupts, watchdog timers and low level nitty gritty? How do those type of things work in your environment?
Thanks,
Robot
@Robot I don’t currently use a watchdog timer, but when you use ‘setWatch’ on a pin, changes on it trigger an interrupt which timestamps the event and sticks it in a queue. JavaScript always runs in the main loop, but because those events are timestamped you can do really accurate timing very easily (eg. for Ultrasonic Distance sensors).
Espruino won’t be suitable for some things – but for 95% of what people do with Arduinos it’s significantly easier to use…
I’m sorry, but if the plethora of libraries with accompanied examples from which you can snag code without writing but a single line yourself is so hard that you need something easier, perhaps you should not even be dealing with electronics do to the 100% chance you’ll set the house on fire.
Apart from that, how can the implementation of a language that has been designed to be as remote and detached from the real iron form a solution for this non existent problem?
If you consider BitLash and Bus Pirate to be useful, then I really can’t see why you have such a problem with Espruino. Is it just that it uses a completely standard language rather than one I made up?
You’re welcome to actually try Espruino and see for yourself. There are downloadable versions for a bunch of different ARM boards on the website http://www.espruino.com/Other+Boards
@Gordon, thanks for the reply. Interesting. . . with a 72 MHz clock your setWatch as being sufficient for most applications. I could see this as a gratifying entry into the world of hardware for the object oriented types. . . certainly less painful than the experience of cutting my teeth writing HDL for a CPLD and ASM for the 68HC11. I think hardware engineer types like myself can’t help but be defensive of the hard won experience of working at the bit level.
As an aside some years ago I asked a friend “what exactly makes a language object oriented?” He was baffled and struggled to explain something he felt to be so fundamental. Honestly, I still don’t know the answer to that question :P
I’m still waiting for someone to show me what that looks like in machine code.
Regards,
Robot
@Robot: Thanks for the positivity! People seem to think I’m trying to replace C with it – I’m not. It’s probably best to think of it as a scripting language for hardware.
However I still believe that most of what people do with Arduino is actually quite simple, and is well-suited to JavaScript. Of course for the bigger projects you’ll probably still want to use C – and you’ll need real knowledge of the underlying hardware.
I am not understanding this well lol. To me the greatest advantage of using JavaScript for hardware is that you can attach event handlers to pin interrupts. ie not in the main loop.
This is very interesting but I don’t know it will appeal to.
JavaScript would be a good hardware language because of it Property/Method/Event structure. The dot, curly bracket, semicolon syntax would be comfortable for a wide range of programmers.
The problem is that most JavaScript programmers who have had any experience with web implementations of JavaScript hate it with a vengeance.
Just watch as the sweat form over a web developers brow when you ask if his code is cross browser compatible. For this reason most web developers go one level of abstraction further and use a framework like Prototype or jQuery so they can program in a ‘JavaScript like’ way while not having to worry about cross browser comparability issues.
I often use JavaScript for quick data crunching where the presentation of the results are visually complex. I just make a .htm file on my desktop and instantly I have a useful and simple programming environment that is very good at rendering. BUT if someone asks me to do any JavaScript for a web site then I just say I don’t know anything about JavaScript at all.
I hope an prey though that this implementation has removed case sensitivity! That’s my pet peeve with JavaScript.
A hardware solution to a software problem, just to sell some things.
The smart thing for this would have been to make some sort of Java to C translator that can work with any development board.
But honestly, if you are a web developer skilled in Java, learning to program in C is not the difficult part. You will still be faced with all the hardware things you will have to know about the embedded platform, you know: pins, timers, PWM, ADC, UART etc. These will still take a lot more time than learning a bit of C(++)