Port of Espruino to Pi Zero - native - no Linux

Posted on
of 2
/ 2
  • With the release of the Pi Zero (raspberrypi.org/blog/raspber­ry-pi-zero/) with a retail price of $5 ... I can't help but feel that we are witnessing a significant change.

    How about we port Espruino to Pi Zero?

    But wait, you are going to say ... the Pi Zero is a Linux system which already has production quality free JavaScript environments ... it has Node.js and Nashorn ... just to name a few. Why port Espruino to Pi Zero?

    The answer is a twist ... my suggestion is not to port Espruino onto Pi Zero on top of Linux ... but instead port Espruino to run on Pi Zero natively. Specifically, Pi Zero would have a firmware image that boots from SD card directly into Espruino .... period. No Linux in sight ... just 1 GHz processor, 512MBytes of RAM, SD card FAT32 file system, GPIOs, UART, I2C, SPI, PWM and ADC ... all "just available". WiFi would be handled in the same way that non-WiFi enabled Espruino boards would be handled today. There would be no Video or USB support (in the first release) ....

    However, what it would do is appear to provide the most robust environment for only $5 at a performance level that would appear to be unbeatable in the current time frame.

    Does anyone see any merit in this? $5 for a 1GHZ, 512MByte, SD card based Espruino environment?

  • I'm not sure how much sense that would make - Espruino can already run on linux, and, assuming the hardware peripherals can be used that way on the Pi zero (I thought they could be used from Espruino on a Pi?), I'm not sure there's much to be gained from making it run natively...

    And to do it and not even have USB or video? What is the point of a Pi Zero without USB or video? It seems like the wrong tool for the job to me... I think it would make more sense to run Espruino there on top of linux so you can take advantage of all the work that's been done to make the video and USB and all that good stuff work on the Pi Zero, and use the Espruino for the low level stuff where you're interacting over the GPIO pins.

  • Neil, I think this is actually a pretty interesting idea! I think there are a number of options along a spectrum, actually, and I'm not sure which would end up being the most interesting:

    • espruino running on linux on a PiZ
    • espruino running on linux on a PiZ, with a kernel driver for the more time critical functions, e.g. digitalPulse, pinWatch, neopixelWrite, ...; make it easy to add functions to the kernel driver
    • espruino running on linux on a PiZ fully in the kernel
    • espruino running on linux on a dual-core processor (e.g. esp32?) using one core and linux on the other core
    • espruino running on the PiZ without linux
  • @DrAzzy ... I'm still thinking the notion through. The announcement this week of the Pi Zero has changed the landscape. I had been anticipating C.H.I.P. ($8) and Onion Omega ($19) to have been game changers and didn't see a $5 Pi coming.

    Let us take a step back. Up until now, we had low end processors such as the Arduino and ESP8266 and also the dedicated (but pricier) dedicated Espruino boards. I am now going to take the Arduino out of the story since it doesn't have the ooomh to run Espruino.

    Now if we take the Pico as the gold standard for a platform for running Espruino ... we end up with a device that runs at 84MHz with 96KByte of RAM. It has no video and no USB output and retails at about $25. If we see value in that device ... what more value would we have in an equivalent device which has 1GHz processor speed, 512MB of RAM and GBytes of SD storage ... for a base price of $5.

    If we choose to use the Pi Zero as is, then the question becomes one of "What value is Espruino?". My thinking goes as follows ...

    I want to write applications. When I write applications, I have a choice of programming languages each suited to different purposes. If my purpose leads me to JavaScript ... the question becomes "which" JavaScript run-time environment should I choose?

    As far as I can see my choices are:

    • node.js
    • Nashorn
    • pijs.io
    • others?

    Over the last month, I've been eagerly awaiting my Onion Omega but @tve has been cautioning me that because it runs Linux, I may not be happy with what I find. I have no experience running Linux on small embedded systems so I took his cautions as very worthy of consideration. I have a Pi 2 Model B ... but since that is a quad core monster and also comes in at $35, I put that aside as "not applicable" to our comparisons.

    Without having had any experience nor read any empirical evidence, my "gut" (and it is only my gut) says that running an existing JavaScript runtime on the Pi Zero will be more than satisfactory for my personal needs. However, if the "cost" of running Linux interferes with what I or others may want to do ... then we eliminate Linux ... and run Espurino on the metal.... and that brings us to this post and the thought experiment.

    I see a flow chart here ...

    #1 run JavaScript as-is on Pi Zero on Linux and all is well - stop
    #2 run Espruino (JavaScript) on Pi Zero with no Linux and all is well - stop

    The question in front of us is one that hobbyists in combined electronics/computing like myself will see revealed over the next 6-12 months.... and that is where do we focus our tinkering? Historically it was Arduino because it was so easy and so cheap. Then came the Pi ... but that was really a computer and for some reason the price north of $20 caused us to pause ... we got all excited again about the ESP8266 ... not necessarily because it just had WiFi ... but because it gave us 80MHz processor and 40K of usable RAM for about $5. Now we have another turn of the crank and we have 1GHz processor with 512MB for $5. GULP!! Orders of magnitude improvement.

    I can imagine and understand folks saying ... ahhh ... but what about power consumption ... and other dimensions ... and those are all valid ... no question. But in some dimensions ... those that relate to CPU cycles and available RAM and price ... it seems we have just witnessed a dramatic leap forward that will take quite a while to beat.

    The reason I waffle down this path ... which appears unrelated to our Espruino discussions ... is that if (just IFF) my suppositions hold any merit, then all eyes will transition to Pi Zero ... likely away from Arduino and likely away from ESP8266/ESP32 ... for the hobbyist community (which is where I play). And if eyes transition to Pi Zero ... then maybe (just maybe) a first class ridiculously efficient JavaScript engine running natively on the Pi Zero might have some value ... and again ... that assumes the Node.js with all ITS eco-system doesn't already fill that niche on the Pi Zero on Linux today.

  • Two possibly relevant projects: WiringPi (wiringpi.com/) and BoneScript (beagleboard.org/Support/BoneScrip­t).

  • Espruino currently supports WiringPi so you get fast IO, and when running as sudo you get proper IRQs when a pin changes state! it's actually surprising how much hardware access you can get under Linux when running with root priviledges - you can peek and poke registers like you could on a proper microcontroller.

    The thing it's lacking is a utility timer for accurate digitalPulse. As @tve says, this could be a kernel module (in fact that might not even be needed - we just need to find a spare timer peripheral on the Pi and I think we can do it all from user mode with root privileges).

    From my point of view, trying to run on Pi without Linux is just crazy. There are millions (billions?) of lines of code in Linux, and you're basically reimplementing what others have done before, just worse.

    You can compile the Linux kernel with a 'realtime' flag so you can get proper accurate timing out of it if needed.

    IMO, a cut-down Linux disk image that'd run off a ~256MB card, and that booted straight up with Espruino could be really good - and would actually be pretty achievable. You'd get proper USB with WiFi, Ethernet support on the Model B, the dispay, and all that good stuff... and people using it could just jump right into JavaScript without having to worry about Linux.

  • ... to add to this, there are a bunch of (probably more exciting) cheap OpenWRT Linux+WiFi modules out there. A firmware image for them that booted right up into Espruino would be really exciting too.

  • IMO, a cut-down Linux disk image that'd run off a ~256MB card, and that booted straight up with Espruino could be really good

    Dumb question: what's the advantage over node.js or BoneScript at that point?

  • what's the advantage over node.js or BoneScript at that point?

    It'd just be the digitalPulse and accurate pulse measurement with setWatch.

    Also the way you could just point the Web IDE at the board's IP address, connect, and use all the existing Espruino hardware-centric stuff (in fact you could just serve the Web IDE off of the Pi).

    Basically it'd be more beginner-friendly than node (IMO)

  • Will the $5 PI come to the end user market for this price ?
    There is some noise, the market will only see a bundle with HDMI/USB cable for $12 - $16.
    Which would still be a good price.

  • Some people (Pimonori?) were selling at the £4/$5 price before they ran out.

    I wonder if there's any profit margin in there, but I think some companies will be willing to sell almost at cost because people do generally spend extra when they buy something like that.

    I do wonder about this focus on ultra-cheap boards though. I'm not sure this race to the bottom is really that helpful in the long run...

  • Hi, just a few arguments to this discussion:
    a- the global bill amounts to 25 - 30 euros! (box+sd+power supply+wifi dongle)
    b- running a rpi for month or years imply a bit of hardening on the linux side or you'll get sd wear: i have done than since 2 years now and finally openssl bugs imply reboots every 2 or 3 months
    c- power consumption is definitly not iot friendly: stm32L4 seems very interesting from this side (nA somewhere)
    d- no adc or dac on pi0
    e- single uart
    f- android tablets are getting as low as 30 euros

  • Hi, just some observations from the peanut gallery:

    I believe a great starting point would be Gordon's suggestion of a Raspian/Debian (hopefully jessie-based) image that booted directly into espruino. If it had a kernel driver for time accuracy, and maybe a template for adding other drivers, it would be a very simple step for the rpi community. Even more important, I, for one, would pay for that (say the cost of a pico) assuming it had been optimized (or maybe cleaned up a bit is a better term) for espruino. BTW, I now run node on my rpi model Bs.

    I think it would be most attractive if it runs on any of the various berries and could use the espruino modules that already exist. An RT implementation might go a long way towards making it distinctive, but that could perhaps be phased in later if there were enough interest. A full development system (ie using the WebIDE from a browser) would be the rpi philosophy, though I must admit I do not find my rpi model Bs fast enough to use for Arduino development (yes they work; I just need faster turn-around when I am coding).

    One last comment: I think the rpi has demonstrated that it is not necessary to "hide" linux to make the system attractive. Programming is the primary application of the rpi, so an easy entry point, and lots of examples, help and support from the community for learning clearly works. From my perspective, community is one of the strong points of the rpi and espruino as well.

    If you are looking for a non-hardware method to support espruino, maybe adding this kind of platform makes sense. At the very least, it will not require the upfront investment that a new hardware board demands.

    Sorry if this is viewed as "highjacking" the topic since it does not deal specifically with the rpiZ. Under 10 dollar hardware seems to be the trend, but for me it mostly means that hardware costs become an ever smaller factor in the development cost with a new platform.

  • Thanks! I don't think it's really highjacking the thread much :) Support for all types of Pi would be a major bonus for the Linux-based release.

    though I must admit I do not find my rpi model Bs fast enough to use for Arduino development

    I think with Espruino it'd be pretty speedy. After all, all the work gets done in the web browser, which would be running on a proper PC :)

    I think the rpi has demonstrated that it is not necessary to "hide" linux to make the system attractive.

    True, but if I'm honest I think the real thing that has 'launched' the Pi is the massive community around it. You can just google what you want to do and then copy/paste the commands :)

    ... also quite a lot of people use the GUI! :)

    Carambola existed some time before the Pi (I think?), was cheaper and had Flash, WiFi and Ethernet on board, but I think it failed to become popular mainly because of the way people were thrown headfirst into Linux.

    Somehow the Pi just got it right...

  • Would it be possible with someone who knows how, to couple a RTOS with the Espruino firmware for the raspberry pi?

  • Just a link to start this port...

  • Yes, potentially you could use FreeRTOS or something similar. Almost immediately you'll have people asking why they can't use USB devices on it though :)

    Best bet would be to compile a linux kernel with the realtime options set - although if Espruino could use a hardware timer on the Pi, it might be a realtime kernel isn't needed at all.

  • @d0773d ... for FreeRTOS, see this existing Github Espruino issue .. github.com/espruino/Espruino/iss­ues/699

    The ESP32 which ... as we understand it ... will be an ESP8266 with a lot more RAM and CPU power ... will very likely use RTOS as its base. The ESP8266 today has an Espressif RTOS base that ... strangely ... appears that it may already need LESS RAM than the non-OS-SDK today. Not only that, it provides a blocking sockets based TCP/IP API. One of the side effects of that is that the networking portion of the Espruino port to EPS8266 could be replaced with the standard sockets networking code base today.

    I have a Raspberry Pi 2 at my disposal and I'm going to start an investigation on the state of play of JavaScript programming with electronics integration on a standard Raspbian Linux base. I'll be writing that up for the broad community but as a side effect, we'll maybe get a sense on whether or not Espruino offers something that would warrant any form of port to native hardware. For example, we'll see if SPI, I2C, PWM and all the other items where we need exact timing come across without issue.

    Ive also got a thought in my mind at the notion of an Espruino "shim" layer for existing JavaScript engines. For example ... if one took Nashorn as a JavaScript engine (for example) and then implemented the Espruino specific JavaScript APIs (relatively simple) ... would one then be able to harvest the large set of component integration libraries already available for Espruino on a non-Espruino JavaScript engine running on Pi Zero linux?

  • @Kolban sounds like a plan :-)

  • Just to add, not sure if this is recent or not, but there's now a 'lite' Linux image on raspberrypi.org/downloads/ra­spbian/

    Or just did a quick google and there's this: minibianpi.wordpress.com/about/

    200mb download, and will run on a 512mb card - could be very interesting to stick Espruino on there.

  • Another minimal one I spotted this morning is dietpi.com/ - UK-based developer. Needs a 1GB card but compares very favourably to standard distro: docs.google.com/spreadsheets/d/1­mDHGZC-H6tU6_O8kuLTG8d4A8Nt7lV1Q7MXTR_6q­w30/edit#gid=0

  • For espruino, I think this may be the ticket: tinycorelinux.net/
    Everything compiled into a tiny image...

  • Wow, yes - although it depends what you're after. There's something to be said for having a proper writable filesystem with apt-get, which might be more of a faff with tinycorelinux.

    There's also a bug open on GitHub with a package for OpenWRT, which I need to submit. It'd be very nice to be able to get into any OpenWRT router/board, install espruino, and set it up as some kind of service.

  • The Tessel2 is also OpenWRT based. Running espruino on it would be fun.

  • :) Yeah... It wouldn't compare very well to Node.js though! (IMO - I haven't tried!)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Port of Espruino to Pi Zero - native - no Linux

Posted by Avatar for Kolban @Kolban