8 ms·
Espruino: JavaScript for Microcontrollers
- deleted 6y ago[deleted]
- deleted 6y ago[deleted]
- djblue 6y agohttps://github.com/mfikes/esprit https://github.com/mfikes/esprit targets espruino from clojurescript.
- johnchristopher 6y agoI have been wondering for years if I should buy some for hobbyist projects. I hope some HN reader can share a bit of their experiences.
- adevx 6y agoI've had a lot of fun using Espruino on the ESP8266 platform for various sensor applications. The biggest hurdle was keeping things simple. It's easy to get creative with JavaScript resulting in memory overflows and hard to debug issues. I eventually switched to Node.js on the Raspberry PI as my use case did not require low power / small form factor.
- pomatic 6y agoPlaying with the bangle.js espruino watch has been great fun. Nice hardware (much nicer than the esp32 based lilygo), and there's a coolness factor in programming your own watch to work exactly as you please.
- tleb_ 6y agoWhat issues did you have with the Lilygo? A watch with an integrated ESP32 sounds nice to my ears.
- francelinho 6y agoI think it's pretty interesting but the hardware seems to be veery limited. It's like a light version of Arduino stuff.
- jarmitage 6y agoIt supports a variety of platforms including the latest ESP32s which are fairly capable. Anything higher than that and you are talking about an SBC at which point you can use any language you like.
- hungryforcodes 6y agoNo, it's really much closer to a light version of NodeJS.
- jarmitage 6y agoI’m working with Espruino at the moment. Being able to access an embedded JS REPL over pretty much any protocol opens up all kinds of weird new programming experiences. I’ll leave what those might be to your imagination!
- dbrgn 6y agoThat's also the feature I love when using MicroPython. Having a REPL on the microcontroller itself, that can be accessed through serial-over-bluetooth? Awesome.
- petre 6y agoNodeMCU also has a Lua REPL but you need an USB wire. Itcs very cool, I'm currently playing with it. There is also some Lua OTA example in the firmware.
- Rochus 6y agoIf it's about the REPL then you could also have a look at Forth. It seems that in Espurino you have to pay attention to quite a lot of things to achieve a decent performance: http://www.espruino.com/Performance http://www.espruino.com/Performance
- Rebelgecko 6y agoI haven't seen the puck.js before but I really like that form factor. Are there any similar boards out there with the same sensors that also have wifi?
- tleb_ 6y agoYou might want to look into what https://m5stack.com/ https://m5stack.com/ does. They deliver ESP32s under nice form factors. The chip can run Espruino apparently: http://www.espruino.com/FAQ#is-espruino-related-to-esp8266-esp32-espressif- http://www.espruino.com/FAQ#is-espruino-related-to-esp8266-e...
- nosianu 6y agoThere also are low.js and Moddable: https://www.neonious.com/lowjs/ https://www.neonious.com/lowjs/ https://www.moddable.com/ https://www.moddable.com/ Low.js interprets the actual JS code stored on the embedded system which already contains the runtime. Moddable compiles JS to a byte code on the PC and builds an image to transfer to the embedded chip. The XS runtime of Moddable probably is closer to a full development pipeline, for people used to low-level embedded development. Low.js was more high-level, when I tried it you did not need to know anything about embedded, just send JS code to the embedded system with low.js on it. Moddable required full knowledge of C and embedded development. Moddable directly supports almost all of ES 2018. Low.js uses Duktape with their own stuff added and last time I checked required transpilation of the JS code to ES5.
- dazhbog 6y agoModdable and Espruino have a slightly more restrictive license for when u want to maybe monetize your project. Duktape and Jerryscript are way bigger open-source projects (on github at least). I used almost all of the interpreters to do a hello world on a microcontroller. They all work great! I found Duk to have a slightly cleaner API for bindings, for example writing to the serial port from JS land. https://github.com/svaarala/duktape https://github.com/svaarala/duktape https://github.com/jerryscript-project/jerryscript https://github.com/jerryscript-project/jerryscript
- throwbackThurs 6y agoJavaScript seems like the wrong choice here for a number of reasons. I would never use this for a commercial real-time application.
- galacticdessert 6y agoAny thoughts on the development experience of this versus the Elixir based Nerves project, putting aside obvious platform differences (i.e. the BEAM being concurrent and resilient by design vs JS having a ton of libraries, etc.)?
- rhabarba 6y agoWouldn’t microcontrollers better run with efficient and low-level languages?
- nicoburns 6y agoSure. But they're powerful enough that they can run higher-level languages these days, and it lowers the barrier to entry for people wanting to do hardware projects which is pretty cool.
- mhaberl 6y agoIn short: yes. BUT maybe it does not matter that much for some projects and a lot of people can write some logic in js a lot faster than in C (or C++ or Rust or..). Also, there are a lot of people who know only js and would like to "play" with some LED, fetching room temperatures, opening closing doors etc - this is a nice way to start. There are a lot more info about performance here: https://www.espruino.com/Performance https://www.espruino.com/Performance
- rhabarba 6y agoIn my opinion, life would - in the long term - be easier for these people if they were forced to learn C, C++ or Rust for their projects. But it’s been a while since I was a beginner myself, so there might be some bias here.
- qayxc 6y agoC, C++ and Rust are big barrier to most hobby programmers. Python, JavaScript, and other high-level languages are way more accessible and are an order of magnitude faster to get started with. Why waste weeks on learning C when that time could just as well be spent actually getting things done? I also don't see how C - and especially Rust - would make embedded development any easier than using a scripting language. Tooling is often worse, skills cannot be transferred from and to other common areas (mobile, web) and development times are provably longer. Unless your goal is to become a professional and create commercial products in the IoT/embedded space, I doubt learning and using C or C++ would be easier in any way.
- lbriner 6y agoCan someone with a low enough level of programming knowledge do anything in Javascript that is not already really easy in C? Sure, some things like interrupts and PWM control take a bit more work in C (although most uCs have libraries to encapsulate this) but if someone is that noob, are they really programming interrupts and PWM?
- rusticpenn 6y agoIts about accessibility for developers (js developers here).
- fulafel 6y agoYes, write programs without security vulnetabilities related to parsing untrusted inputs.
- petra 6y agoEspruino claims to do automatic power management.
- swiley 6y agoString manipulation and dynamic memory allocation are kind of awful in C (this coming from someone that's written a web browser in the language.) I'm not sure javascript would be my first choice of a replacement (really scheme is pretty amazing, and more general than C even. With a tiny amount of work you can even avoid the garbage collector and get pretty much every advantage C had with a more minimalist, general, and expressive language) but it's very popular and has most "normal" things that c lacks. Arguably these aren't thins you should be doing on a "micro controller" (IMO you're generally best off sticking to state machines and avoiding dynamic memory allocation.)
- netmonk 6y agoTo answer those comments suggesting that low level language would be more fitted, im going to report my own exprerience. Two years ago, i went to FOSDEM where i met Gordon the creator of Espruino. I was curious about those littles devices and decided to buy one. Back at home, i started to play with my little device (pixl.js) and i was very enthousiast to use Chrome interface to start coding little program in Javascript, uploaded instantly via bluetooth on the device. It was fun, it was entertaining, and after a few keystrokes i was able to monitor room temperature, and display it on the lcd screen (which is totally useless i admit). But the more i played with it, the more i became curious of MCU ecosystem, given the fact that im also a mechanical keyboard enthousiast, where teensy and stm32u2 have a central place in this community (esp. when you want to build your own keyboard). So little by little, my Espruino experience gave me confidence to continue the travel, and after two years, i migrated mostly over ESP32 and RISCV mcu, coding in C, using vscode/platform.io, clone tones of github repo, trying to understand all the hardware concept, such as bus, serial, spi, i2c, timer, scheduling, packet radio with lora (running my own ttn gw, or controlling drone with opensource project such as ExpressLRS). Espruino opens to me a new fertile world of MCU, helped me to step up the entry barrier and last year at FOSDEM, i meet again Gordon and thank him warmly for all of this. (signed: a +20 years linux sysadmin, who always wanted to code a little)
- Fnoord 6y ago> [...] i was able to monitor room temperature, and display it on the lcd screen (which is totally useless i admit). How is that useless? We've been using such a device for a long time in society (replacing the mercury ones). Sure, nowadays with smarthome you can do it on a smartphone as well. In my household we use a Honeywell for this (non-smart) and we have a smart device under it which shows the current weather and the forecast. Furthermore, I bought an Enviro+ [1] plus a RPi Zero a while ago, but I still gotta implement/install it. [1] https://opencircuit.nl/Product/Enviro-plus-for-Raspberry-Pi https://opencircuit.nl/Product/Enviro-plus-for-Raspberry-Pi
- MivLives 6y agoI've been looking into this recently. The one complaint I've seen about the Enviro is that the pi's CPU throws off the temperature.
- traverseda 6y agoThere are a lot of micropython boards available, not sure why I'd choose this over any of the many boards that work with micropython. Their "bangle.js" smart watch does look pretty nice though. A lot better than the TTGO smart watches.
- gfwilliams 6y agoHey everyone! I'm the creator of this. Glad to see a few of you have tried it and enjoyed it. Any questions, just let me know below and I'll do my best to answer. Just to answer some of the stuff below: Yes, you could write something faster and smaller in C. However chances are you'd spend a lot more time doing it, eg. https://github.com/classycodeoss/nrf52-ibeacon/blob/master/main.c https://github.com/classycodeoss/nrf52-ibeacon/blob/master/m... vs http://www.espruino.com/iBeacon http://www.espruino.com/iBeacon Most battery powered devices spend most of their time asleep. If your device spends 1ms awake every minute instead of 0.01ms then honestly in most cases that's not a big deal, because the power consumption of everything else in the system is 100x that. Low.js/Moddable/Jerryscript/etc are bigger, faster more complete JS engines that provide a more Node.js-style experience, but generally for more powerful devices. With Espruino we're saying if you're willing to make a few small tweaks to the way you write code then you can use amazingly low power devices: 0.003mA sleep for nRF52 vs. 80-500mA for Raspberry Pi or 0.8mA for ESP32 (with RAM retention)
- pjmlp 6y agoGood work, stuff like Espruino and MicroPython are the modern version of 8 bit BASIC. As I regularly mention, most microcontrollers are much more powerful than 8 and 16 bit home computers back in the day. Good luck for your endeavors.
- ralphc 6y agoI haven't used any of these but recently I went down a rabbit hole of reading about prototype-based vs. class-based OOP, which took me to NewtonScript. It went prototype-based (inspired by Self, the common ancestor of NewtonScript and JavaScript) and because of this, many "classes" could have default data and functions point back into the ROM, meaning it was possible to have hand-held GUI apps and OS with 128KB of RAM. Does Espruino take advantage of this technique to save on RAM, and does using JavaScript's prototype-based OOP make it more suitable than Python for low-memory situations?
- wortelefant 6y agoI bought an espruino once and built some basic LED lights setup. I switched to Arduino (Arduino as in arduous) however, for the larger ecosystem of libraries. It was easier to learn basic C than to redo Fastled library in javascript. For everything that does not require a library, I liked espruino a lot.