Espruino For You Sir

As a once-dedicated C programmer (I learned with the K&R book) I originally dismissed Javascript as an interpreted toy (great for websites of course), that is until I started playing with Node-Red.

At that point, after much struggle, I started to get reasonably good with it and once I got used to the string handling, C by comparison started to feel annoyingly awkward when dealing with strings and objects, despite it’s vastly superior speed.

Some time ago I looked at Espruino in a bored moment – saw that it was very much under-developed – didn’t even handle WIFI at the time – a bit pointless on an ESP8266 –  and dismissed it.

Fast forward to this week.  I had set in place some copying of files from here to Spain which, according to FTP was going to take an hour. I could not tell you why but suddenly I got the urge to go see what was happening with Espruino.

So – I believe the model here is that they developed JavaScript for a range of devices – including the ESP8266 and their funding comes from selling the boards and from contributions. I can’t help with boards right now as I have some of my own but I could not resist grabbing the code and sticking it into one of my ESP12 boards to see how they’re coming along. 

Regular readers will know that I like to revisit projects, most of the time great ideas unless they really take off, end up in the bin but just sometimes they go on to be something better.

So off I went to the site. As I’m using their software for free – here’s a push for them – take a look here  – maybe it is worth looking at one of their boards?  Anyway, I grabbed their general ESP code – and using the horrible ESPTOOL but the much prettier ESP8266FLASHER.EXE  I blew the modules into my 4MB ESP-12-E module.  I grabbed the code and followed instructions on this page.

Programming Espruino

Node the bulk of the code at 0x1000 – don’t make the mistake I made of making that 0x10000 – it won’t work and will cause hours of fun. All 4 files are in their download along with instructions.

I grabbed their web IDE (Espruino IDE) to test the code at 115K baud…. my own serial terminal does as well but theirs is prettier. For the life of my I could not get it to start up properly in their IDE – but in my terminal, on hitting reset on the ESP8266 I got this.

_____                 _

|   __|___ ___ ___ _ _|_|___ ___

|   __|_ -| . |  _| | | |   | . |

|_____|___|  _|_| |___|_|_|_|___|


1v91 Copyright 2016 G.Williams

Espruino is Open Source. Our work is supported

only by sales of official boards and donations:

Flash map 4MB:512/512, manuf 0xe0 chip 0x4016


Now I have to say two things – for a complete beginner I found the documentation totally confusing – making reference to LED1 which doesn’t exist and other things – but it turns out you have to read again more carefully. Secondly when I went onto their forums totally confused – two guys came in immediately and helped me.

Once I had the board responding which ultimately did not take a lot of effort – I went back to their IDE and the board was then responsive – I still don’t know why this is – but just so you know if it happens to you – you can talk to the thing with a serial terminal.

Here’s the first issue I encountered…


Espruino Web IDE

Every time I hit enter – the interpreter would come back with undefined. I could not fathom this out until someone pointed out that the interpreter always returns either a value – or if no value is defined, undefined…. kind of makes sense though not what you’d expect from, say, a BASIC interpreter.  Once I’d gotten to grips with this I got more ambitious.


The answer to that was “=3” – seems fair enough.

If I reset the board however I could get nothing out of their IDE – I went back to my simple serial terminal – no problem.

My next problem was following examples – one example referred to flashing a light called LED1 – turns out this doesn’t exist in their ESP8266 implementation but the ports can be expressed as numbers where 0 is GPIO0.

var  on = false;
setInterval(function() {
  on = !on;
}, 200);

I entered the above – perfectly valid JavaScript – and blow me – it WORKED!

Of course – on resetting this would be lost unless you typed “save()” or “reset()” to clear everything out. Running that timer command with different values WITHOUT hitting reset would result in multiple timers.

So – reset – then run that code then save… and the flashing light survives power off!

Espruino does not sadly handle hardware PWM – a shame as Espressif HAVE implemented this at quite reasonable resolution (14 bits) but then their implementation is not perfect – turn it off and that timer keeps on ticking anyway – making a mess of other high speed events like SPI. So maybe that’s why they implemented software PWM – which, well, works!

Some things you should know – they’ve not implemented use of GPIO16 and space is limited at least at first glance – 12K for program storage (including OTA they only seem to use 1 Meg so that does leave nearly 3MB available on an ESP12)… you’ll find the limitations here – but to be fair many of those are ESP8266 limitations – no DAC for example – well of course there isn’t – the ESP8266 doesn’t HAVE a DAC. So the list of limitations is not as bad as it seems by any means. I’ve no idea why they did not implement GPIO16 as a simple output – I use it all the time.

What they DO have are libraries for a good number of peripherals so you might well want to take a look.

Speed? Well, they use the ESP8266 at 160Mhz by default (and that’s fine – I don’t know why we normally stick with 80Mhz given that the extra speed doesn’t take much more power) and claim that for general I/O the unit should be fast enough for general purpose use.

I used example code to connect to my WIFI – no problem – but when I tried to MQTT – I came unstuck  -their source library for MQTT simply would not load successfully.

I read that you had to put the REQUIRE into the right hand side of their IDE to load the module –  I did that and it worked but I really would like to understand how to load the module WITHOUT their IDE – as mentioned above I’m not too happy about it’s behaviour from power up.

So – armed with the MQTT library it was as simple as…

  host: “”,
  username: “admin”,
  password: “mypass”


mqtt.on(‘publish’, function (pub) {
    console.log(“topic: “+pub.topic);
    console.log(“message: “+pub.message);

I fired many messages at it from an MQTT publisher and sure enough  – they came in.  If one can get both WIFI and MQTT running on this interpreter and if it stays up reliably then maybe here’s yet another way to write code for the ESP8266.

To test, I disconnected the WIFI access point – and reconnected – a message came up to say MQTT was disconnected.. but on re-applying power to the WIFI access point… nothing.   When I ran the MQTT code again it connected (indicating that the WIFI connection automatically reconnected itself). What is needed now is a check for broken connection and indefinite MQTT reconnect and resubscribe attempts until it is back in running order.  If anyone has done this already – please do let us know.

Lots of modules…

I can see this 12k storage for code being a REAL bottleneck – I do hope that gets sorted…


19 thoughts on “Espruino For You Sir

  1. I thought the same until I used App inventor for Android but actually it worked really well even though it has its limitations in what you can do.

    1. Hi – I am the author of this. I was quite excited to see the article – and then I saw the words ESP8266 and my heart sunk.

      > the boards are simply way too expensive

      Espruino Pico costs around £20 inc VAT – way less if you order in quantity, so very comparable with Arduino for example. It’s not unreasonable, and they cost more because a huge amount of effort goes in to the software, testing, and support – and that has to be paid for somehow.

      The ESP8266 port is a community port, and is really very impressive. But that does mean that nobody does the boring stuff – like good documentation, polishing, and to a certain extent, testing. The ESP8266 port is not an accurate reflection of Espruino as a whole.

      The official boards I sell are significantly easier to get started with, much better documented (all boards have a LED1, hence the fact that official documentation references it), more stable, and have loads more RAM, flash storage, and hardware peripherals.

      Please try not to confuse the two different types of device. Open Source should be a good thing – but it seems in many cases people are getting a bad opinion of Espruino as a whole because of problems that don’t even exist in the official boards!

      1. I thought I’d pass this one through as it is important people see both sides of the coin. I still think £20 is expensive and compared to which Arduino? You can get an Arduino mini for sub £2 from China – however – as someone who has done a lot of software in my time I know how much effort is involved – so people – if you want to take a look at Espruino Pico – here’s your justification. It also confirms my thoughts that the ESP8266 version still has some way to go.

        1. Thanks! If you take a look at then the Pico is significantly cheaper than most official Arduino boards, and those boards are made in vast quantities.

          It’s expensive compared with the Chinese knock-offs, but then everything is! Just the bare MCU on the Espruino Pico would cost you £5.45 from Farnell, and as you say you could buy two fake Arduino boards for that. It makes it almost impossible to compete.

          I wouldn’t write the ESP8266 port off though – a lot of people are using it and it’s pretty stable. It seems a lot of the issues you faced are because of documentation more than anything else.

    1. Whenever I’ve seen one of these drag and drop efforts over the years, it has been limiting. Having said that Node-Red is drag and drop and it is far from limiting.

      1. I’ve watched a few of the videos, it looks well done so I’m trying the 30 day trial but struggling to get a completed download of the installation file at the moment.

  2. The ESP8266 build of Espruino is not as polished as the official boards. The creator of Espruino (Gordon Williams) has sunk a lot of effort into them and the user experience is excellent so I’d definitely recommend an official board if you’d like things to “just work”.

    Modules need to be loaded by the IDE as it needs to fetch them from the internet and minimize them to load them onto the microcontroller. It wouldn’t be too hard to get the board to fetch the js file off the internet and then load it into memory if you needed to. Given that you need to open some serial terminal application or another on your computer to talk to the espruino anyway, is there any reason not to just use the ide?

    Btw, have you tried connecting to the board and programming in JavaScript over Wi-Fi?

    1. Hi Steven

      With the greatest respect to the author – the boards are simply way too expensive and we have our own anyway. ESP8266 boards complete with regulator and usb fitting etc are typically under £3. If the software is any good I’d rather pay a donation.

      Ok, understand about minimising – that’s one question answered. I mentioned difficulty I had with the IDE – on boot the boards do not seem to communicate with the IDE – yet reset them in a serial terminal – send a command or two then move to the IDE – and they are fine – I’ve no idea why. I have only just got the WIFI working on them – so not tried programming over WIFI yet. That will come 🙂

      This is just a novelty at this time – I have my own code for the ESPs written in C and VERY comprehensive and reliable.. but I noted that Espruino seems to support a wide range of peripherals so the next thing is to try those out – after I have WIFI and MQTT running on power up and have tested it to see how well it handles power cuts and Internet/router failures.

      1. I understand completely, I’ve got my own board designs that I prefer to run things on so I mostly donate instead of buy. It’s just worth noting that some of the issues or missing features you’re experiencing are due to the ESP8266 build itself rather than Espruino.

        Not sure about the reset issue, never experienced it myself or seen mention of it in the forum. Give programming over telnet a go, you might not experience that issue.

        My favorite thing about programming Espruino boards is that it’s so easy and fast to dabble. You won’t miss the old “add print statement, rebuild and reprogram, watch for print statement” debugging.

    1. Created an account just to support this: I discovered MongooseOS just last week and am very impressed. Not only is MQTT, file management plus OTA built-in (including replacing any file on the ESP8266 or 32) but also flashing OTA with proper fallback to the previous fw in case something goes wrong.
      Can be programmed in JavaScript or C.
      Important to know that the Windows 10 CMD console has some issues with sending RPC JSON data to the device (they are working on that) but Linux console works flawlessly.
      To begin, just watch some demo videos they provide and you soon see the amazing thing they have created (sorry for gushing, still giddy from how easy it CAN be to deal with ESP8266 🙂 )
      IN the forum I read something about an Arduino wrapper, have not yet tested that though.

      1. Ok, you’ve talked me into it – I’ve put it in my diary for the back end of next week to take a look. If it looks wonderful you can be sure I’ll do a writeup.

        My MQTT first attempt with Espruino has been sitting there all day working without crashing so that’s a good start.. it will take some time to plan out a way to firstly set it up so it is bulletproof – and then test to see if it can be broken – until then this remains for me a plaything.

          1. Yup, that is on my list to try when I get to my destination and unpack everything, start of next week. I’ll return to the subject – if it can be shown that the WIFI/MQTT connection is rock solid then certainly I could see a use for this in talking to various peripherals. I have a fascination for Javascript and Node.JS and so it may be that given the size limits for storing programs it is little more than a fantasy but it is certainly worth a little time to investigate.

Comments are closed.