In love with Espruino…


I know, it has an awful name… still, after I discovered it a few days ago through their new kickstarter campaign I decided to give it a try. And I’m happy I did so, as it’s really an awesome product !

So what exactly is Espruino ? You can obviously go on their website and get all the details, but in a nutshell, it is a Javascript interpreter running on an Arm board.

I’m sure it has its own disadvantages, but the fact that it’s just interpreting scripts on the fly, makes it perfect for rapid prototyping: no need to compile and deploy the code onto a micro-controller, you just open a terminal and type commands that are executed directly on the board.

The Espruino Pico is obviously not out yet, but they already have the original board which I could have bought. Still, I decided to go a slightly cheaper way by buying the under-priced STM32F4-discovery board which is half the price and is also supported by their firmware. (I’ve also backed their campaign as the amount of work they’ve put into this open source project is impressive !)

So all I had to do to get this working was:

  1. download the Espruino firmware (which contains a special binary for this exact board. Please do check their list of supported board)
  2. download the STM32 ST-Link utility for Windwos (so that I can flash this firmware onto the board)
  3. download and install the ST-Link USB driver (same link as above) – in retrospective I think this wasn’t actually necessary
  4. download and install the STM32 Virtual Com port driver
  5. run the ST-LINK, select the espruino_1v70_stm32f4discovery.bin file and flash it onto the board

After these easy steps, you simply connect the micro USB port to your computer and connect the Espruino IDE (Chrome extension) to the newly created COM port.

So the above video shows a very basic example that uses the onboard accelerometre to drive 2 onboard LEDs and a RC servo. Pretty basic stuff, but it’s impressive how quickly this can be put together, and how much cleaner / higher level the code looks, even compared to Arduino (not to mention, low level C code as all the examples provided by the board manufacturer, etc. …)

function onInit() {
 // initialises the onboard Accelerometre. This should be called ONLY ONCE
 // OLD BOARDS http://www.espruino.com/datasheets/LIS302DL.pdf
 // my (NEW) Board http://www.st.com/web/en/resource/technical/document/datasheet/DM00040962.pdf
 // see http://forum.espruino.com/conversations/438/ for soe issues around the initialisation bit
 SPI1.setup({sck:A5, miso:A6, mosi:A7});
 // 100 Hz output data rate
 SPI1.send([0x20,0b01100111], E3);
}

function getAcc() {
 var accx = SPI1.send([0xA9,0], E3)[1];
 var accy = SPI1.send([0xAB,0], E3)[1];
 var accz = SPI1.send([0xAD,0], E3)[1];
 // range is roughly [-67..67]
 if (accx > 127) accx -= 256;
 if (accy > 127) accy -= 256;
 if (accz > 127) accz -= 256;
 
 return [accx, accy, accz];
}

function setServo(pin, pos) {
 // pos is between 0 and 1 but the range is between 0.6ms to 2.4ms
 pos = E.clip(pos, 0, 1) * 1.8;
 analogWrite(pin, (0.6 + pos) / 10.0, {freq:100});
}
 

onInit();
var oldPos = 0.0;

setInterval(function(){
 // make the range to be 0..1
 pos = (getAcc()[0] + 67) / 134.0;
 
 // update servo position. Only if the position has changed, to avoid jitter
 if(Math.abs(pos - oldPos) > 0.01){
 oldPos = pos;
 setServo(B9, pos);
 }
 
 // update the LEDs
 analogWrite(LED2, E.clip((0.5 - pos) * 2, 0, 1), {freq:100});
 analogWrite(LED3, E.clip((pos - 0.5) * 2, 0, 1), {freq:100});
}, 100);

The really powerful thing throughout this test and what makes this board really different, is that I was able to play with individual commands live on the board and see them executed on the fly.

Oh, did I mention their Google Chrome based IDE ? Really simply and intuitive and quick to install…

4 Responses to In love with Espruino…

  1. Just thought you might like to know that you can also control the Espruino via an OTG-USB port using DroidScript (Javascript IDE for Android). https://androidscript.wordpress.com

    • trandi says:

      Thank you, this is quite relevant ! Tomorrow I’m receiving my new Android phone, and that’s going to be one of the first apps to install.
      However I’m not sure I understand why I need DroidScript to control my Espruino. Can’t I just connect the Espruino to my Android device and open a browser, as I do from the PC ?

  2. ytaibt says:

    Thanks for the tip! Just ordered one. Looks like they’ve done a very thorough job on all aspects of this project.

    On Tue Nov 04 2014 at 3:43:11 PM Robotics / Electronics / Physical

    • trandi says:

      No problem, I’m glad you like it too…
      It probably won’t replace a “good old” Aruino or Attiny programmed in C++, but I can see so many usages and makes prototyping soooo much easier…

      I get the same feeling as when I moved from Java to Scala, this strange feeling of loving programming again ! 🙂

      Dan

Leave a comment