Close

Espruino HackChat Transcript

A event log for Espruino Hack Chat

Javascript for microcontrollers is here! Wondering how that works? Know tons about this? This is the chat to discuss it.

jordan-bunkerJordan Bunker 08/25/2017 at 21:160 Comments

Shayna Welcome @Gordon Williams :) We'll likely get rolling around :05 mins after so everyone has a chance to enter the room + get settled.

Gordon Williams Ok, great - thanks!

Boian Mitov Hello @Gordon Williams :-)

Arsenijs Hi @Gordon Williams !

Shayna In the meantime -- if any of you have questions, the discussion doc is here: https://docs.google.com/spreadsheets/d/17i8Vg_fKYdfL2MBg523vcmtmqw8Bu4ot0i4ro5Xl-us/edit#gid=0

Gordon Williams Hi! :)

jipe_rey Hi everyone

Shayna Hello!

ayushijha2012 Hey :)

todbot hi!

Gordon Williams It's nice to see some good tech questions in the Hack Chat Spreadsheet :)

Shayna Welcome to today's Hack Chat, y'all. @Gordon Williams is joining us to discuss Espruino & microcontroller programming with JavaScript :)

Gordon Williams Hello!

Shayna Thank you for joining us today @Gordon Williams :)

Gordon Williams So, I guess I should do some kind of intro?

Shayna That would be terrific!

Radomir Dopieralski yes, please

Gordon Williams Cool. So I've been making stuff (software and hardware) as a hobby since I was a kid, but after a KickStarter campaign I did 4 years ago I've been working basically full-time on the Open Source (OSSW and OSHW) Espruino JS interpreter. I'm not VC funded or anything - all my work on the hardware, software, and all the support was paid for either by KickStarters, or people buying Espruino boards.

Gordon Williams That's it really - I've made a few different boards that run the interpreter, and I just got a book of projects for it published - but it's amazing how it can turn into a full-time thing

Shayna Awesome

todbot yay an Espruino book! Can't wait to see it

Shayna Ready to take some questions?

Gordon Williams Absolutely, yes!

Shayna Terrific. For those who've just joined, you can enter your questions for @Gordon Williams here: https://docs.google.com/spreadsheets/d/17i8Vg_fKYdfL2MBg523vcmtmqw8Bu4ot0i4ro5Xl-us/edit#gid=0

Shayna First Q is from @todbot ! "Is Espruino on Cortex-M0 possible? (e.g. SAMD21)"

Gordon Williams Yes, totally! The main Espruino boards are Cortex M3 and M4 based, but I ported it to the BBC micro:bit a while back, and it runs pretty well on there.

todbot micro:bit is NRF51822, correct?

Gordon Williams It's a bit constrained because after the Bluetooth stack you only have 6kB RAM for the interpreter, but it's usable for simple stuff. The SAMD21 should be a lot better - it's 256kB flash, 32kB RAM?

Gordon Williams And yes, it is NRF51822 - and M0

todbot yes, something like that. it's a current favorite

Gordon Williams Espruino's pretty portable - the gotcha is implementing the hardware API... There's a really simple abstraction layer though

todbot That's cool. I can only barely imagine JavaScript on a $2 microcontroller like the SAMD21 or NRF51822.

Shayna Next up, MIchal Mühlpachr asks: "What do think about an mJS approach?" ( https://github.com/cesanta/mjs )

Gordon Williams I think this touches on another question later, but as well as hardware SPI/I2C there's software - so all you have to implement is serial and GPIO and you're basically sorted for simple stuff

Gordon Williams Thanks! Targeting cheap stuff was always my plan... I've just had to be swayed a bit by what I can do that also allows me to feed myself :)

Gordon Williams Cool - so mJS is interesting. I'm a huge fan of someone coming up with some standard for 'embedded JS'

Gordon Williams Espruino doesn't implement everything - there's some horrible stuff in there, and even more insane things keep getting added all the time

Radomir Dopieralski there is a new samd21-based trinket board now :)

Gordon Williams (in the JS spec :) ) - but personally I think mJS is maybe a bit too limited

Gordon Williams I know. There's also a Flora nRF51822 board which you can flash with Espruino - I just don't think anyone's done it yet ;)

Shayna From @PaulG : "Do you plan to create an Espruino LoRa (node not a gateway) or Espruino ESP32?"

Gordon Williams I like mJS's wrapperless function execution approach too - but I'm biased since Espruino was doing it ages ago :)

Gordon Williams There are hundreds of functions implemented in the interpreter - so having packing/unpacking code in there for each function really eats up code space

Gordon Williams For LoRa - honestly I think there's a lot of hype around it at the moment. I had to implement a LoRa gateway for a contract recently and honestly the whole thing felt a bit iffy - like the main software that everyone uses has code comments at the top saying 'this is an example only, don't use it in production'

Gordon Williams If I had infinite time I'd like to, but right now I don't have plans since you could probably buy a LoRa module and glue it onto an Espruino for less than I could sell one for (with certification and all that)

Gordon Williams I really like ESP32, but unfortunately - much like ESP8266 - I just can't sell boards with it on. Chinese copies are so cheap everyone would just use those

Gordon Williams Maybe I'll be able to come up with some other way to support myself from it (a service or something) but until then I'm a bit stuck really

jipe_rey BTW, here is some very basic instructions on how to make LoRa with Espruino : https://github.com/yerpj/TTN_with_Espruino/blob/master/QuickStart.md

Radomir Dopieralski we really need a business model for something that is expensive to make initially and then cheap to copy

Shayna And @Patrick Van Oosterwijck 's next question was: "How is the ESP32 port coming along?"

Todd Hey @Gordon Williams I'm joining late but I was an early backer of your original kickstarter and have been an Espruino fan ever since

todbot @Radomir Dopieralski ++ to that idea. it's tough for OSHW projects

Gordon Williams That LoRa link is awesome - I think you posted it on the forum @jipe_rey but I don't think it was as detailed then? I really ought to link that from the Espruino site

Gordon Williams @Todd that's awesome - thanks!

jipe_rey @Gordon Williams No problem if you want to. Even if there is some lacking in there, it is still useful to begin.

Gordon Williams And yes - personally I think the whole OSSW on OSHW business model needs some work. OSHW works really well for everyone - so does OSSW. But the two together feels a bit iffy

Gordon Williams I had a small rant about it at MakerCon.de and I got asked to write a bit of an article for Make: magazine a few issues back. I'd really like it if people could get together and figure something out

Radomir Dopieralski kickstarter model seemed promising

Radomir Dopieralski and turned into marketing hype

Shayna A few Q's from @Boian Mitov , starting with : "What is the advantage of using an interpreter compared to the Arduino Wire API for example?"

todbot Kickstarter can work if you can have periodic projects. Maybe Patreon instead for ongoing funds?

Gordon Williams Yeah - but if I develop my firmware in the open, it's trivial for someone to copy it and produce boards even before I've managed to send stuff I'm happy with to backers :(

Gordon Williams @todbot yes, Patreon seems like a good bet. Look at Gina and Octoprint for a massive success story there

Todd The Espruino kickstarter was what 4 years ago and it's lack of hype and just plain ol' techie honesty is what really turned me on to it. It was my first time backing anything.

Paul Stoffregen That's roughly what happened with Arduino with Leonardo - they put out a public beta and Sparkfun, Adafruit and others shipped clones before they managed to work all the bugs out and ship their own Leonardo boards

Radomir Dopieralski it would be nice if the companies that use this stuff would give something back

Gordon Williams And I do have a Patreon page, which is doing pretty well - but as far as I can tell it's a good 80% KickStarter backers or actual contributors - and I feel really bad about that because those folks are the ones that have always supported me. I really wanted a few more of the people using ESP8266/etc to be helping out (although there are a few - just not too many)

todbot maybe put a "hey join my patreon" in the firmware login screen? :) only half-joking

Gordon Williams Yeah. You seem to have done really well with that though @Paul Stoffregen - have you had any issues with clones? I haven't come across any

Shayna Are you okay for time, @Gordon Williams ?

Gordon Williams Yes, totally - are we running over? Maybe if I get through some of the questions and then we chat about the other stuff?

Patrick Van Oosterwijck Hey @Shayna dont go on to the next question i didnt receive an answer to mine yet :)

Gordon Williams It's coming ;)

Shayna No problem @Patrick Van Oosterwijck :)

Boian Mitov @Paul Stoffregen stuff is so impressively designed, and low priced that it is difficult imagining someone getting it done better ;-)

Shayna (That would be, "How is the ESP32 port coming along?" )

Gordon Williams Oh right - we missed the interpreter one though? I'll just answer that quick

Shayna @Patrick Van Oosterwijck and then @Boian Mitov 's intepreter question right after :)

Gordon Williams Personally I'd say it's the debugging... Not so much line by line debug (you can do that) but the ability to step through issuing commands one at a time. I haven't used a Bus Pirate, but I get the impression it can be a bit like that - but when you're done you just take the commands you sent, stick them in a function, and you're sorted.

Gordon Williams Whoops. sorry :) Ok, I'll do ESP32 in a bit.

Gordon Williams Basically often when I'm making stuff I have no idea if something is broken in the hardware or the software - often it'll just be a bad connection, so being able to actually interact with the device running the software really removes some uncertainty

Gordon Williams So ESP32 - if I'm honest, I haven't been involved in that much (apart from top answer a few questions) - some guys in the community have been amazing there. It does work though - it runs JS, will do Sockets, HTTP (client and server), Websockets, MQTT, and even TLS/HTTPS

Radomir Dopieralski I love to use the REPL in micropython for exploring new sensors/displays

Gordon Williams So it's looking pretty good really

Radomir Dopieralski reading the datasheet and trying things live

Gordon Williams @Radomir Dopieralski yes, that's exactly it.

Gordon Williams As I understand it micro python has the repl, but then mainly it executes code from what's basically a Python file at boot.

Gordon Williams Espruino can do that, but by default, saving to flash memory is more like hibernating... So you can get it working the way you want, then `save()`.

Todd I've used Espruino on the original ESP and it's fine, no problems. The network stack has limitations, not surprisingly.

Shayna Ready to move on to the next?

Patrick Van Oosterwijck Thanks!

Gordon Williams When you get used to it it's quite fun. @Todd, yes, ESP8266 is looking good. I actually have an issue open on GitHub at the moment to tweak some compiler/linker options that should free up a lot of RAM

Gordon Williams @Shayna yes, sorry!

Todd "free up a lot of RAM" sweet!

Shayna No worries! Thanks for being able to stick with us a little longer, too.

Shayna So in addition to the question on interpreters, @Boian Mitov also asks: "Can it handle interrupts from modules?"

Gordon Williams I'm not quite sure what you mean by modules - but yes. Changes in pin states can generate an IRQ that's then timestamped and queued, and then executed by JS in the main thread. However if you specify a 'native function' - so something that's not JS (you can do inline assembler or 'compiled' JS) then you can actually run that in the IRQ itself

Gordon Williams Also Serial, USB and some other stuff is all handled by IRQs behind the scenes - it's just arranged so that you don't have to worry about any of the concurrency issues

Gordon Williams For SPI/I2C there are some global objects like SPI1/2 for specific hardware peripherals, but you can instantiate your own 'software' peripherals that you can use in the same way... So you maybe have an LCD driver that takes an SPI object - you can either give that a proper hardware peripheral, or the software one... It doesn't really matter

Shayna Also from @Boian Mitov : "How are interfaces like SPI, I2C etc. handled?"

Shayna :)

Gordon Williams Ahh, sorry - I just pre-empted that :p

Shayna No worries!

Shayna Next up from @jipe_rey : "What about embedding Espruino in a freertos thread? Make sense? Planned?"

Paul Stoffregen @Gordon Williams - Yup, we have problems with clones.

Paul Stoffregen The cloners are shameless, they'll do anything to make a sale if they can deflect all the dev & support costs to someone else

todbot ("psst, can I interest you in my new low-cost Teenspruino")

Gordon Williams @Paul Stoffregen argh, sorry - I think it's inevitable though. I've tried to be quite pushy about it on the forums, but it still does happen - although luckily not to such a major extent. There are clones but the main ones have been good at providing their own support

Gordon Williams If it makes you feel any better I own only legit Teensys, and haven't come across clones (unless the OSHPark ones are? :s)

Gordon Williams With FreeRTOS: It's definitely possible. Isn't ESP32 freertos based? If so it's done already. However Espruino is sort of an OS all by itself, so you have a few queues and buffers that are left in that end up being useless

Radomir Dopieralski well, there are pro micro clones which do compete with teensy 2.0

Gordon Williams At some point those queues could be ripped out to make it more efficient, but I guess if your have FreeRTOS you probably have slightly more RAM anyway, so it's not such a big deal.

Paul Stoffregen let's talk of boards & clones & business models later - not looking to get this conversation off-topic...

Gordon Williams :) Totally, yes. Maybe a new Hack Chat topic for later :)

Shayna :)

Radomir Dopieralski that would be awesome

Shayna Thanks for sticking with us for some additional time, too

Paul Stoffregen and I'm curious about your work, though I must confess I have very little Python experience

Shayna From @Radomir Dopieralski : "How does it currently compare to NodeMCU and MicroPython? (In terms of speed, free memory, supported peripherals, libraries, etc.)"

Arsenijs + for clone chat afterwards

Gordon Williams If I'm honest I have very little experience of NodeMCU, so I can't really comment on that. I'll try and do each in turn

Shayna Next up, @azathoth-org asks "In terms of callbacks, how deep can it go? What kind of stack depth limits are there?"

Gordon Williams Speed: Micro Python is faster. It's designed for MCUs with more memory, so makes different trade-offs. Plus, Damien is awesome. However Espruino does offer 'compiled' JS where as long as you're doing pretty basic JS code you can stick "compiled" at the top of a function and the IDE will take it, turn it into C++, and push it through GCC. If all you're doing is integers it's faster than any interpreter - because it's not - it's GCC

Radomir Dopieralski nice

Gordon Williams Free memory: I don't know about NodeMCU, but Espruino's pretty good. For instance on the micro:bit I can get proper Bluetooth in there and run in the remaining 6kB RAM - Micro Python just can't manage that (it does run, but not with Bluetooth)

Arsenijs That's great to hear! MicroPython doesn't actually offer compiling the code by itself or by means of an IDE - you're supposed to write the optimized code yourself, and the docs are kinda lacking in that regard.

Gordon Williams It's designed for very constrained devices, but that means speed isn't a priority. I figured if you wanted raw speed you probably wouldn't be using JS :)

Radomir Dopieralski@Arsenijs there are @native and @viper decorators that compile the code

Radomir Dopieralski@Arsenijs and you can write functions in assembly

Arsenijs@Radomir Dopieralski You still have to rewrite the code for @viper and @native, AFAIK

Gordon Williams For Peripherals, I think Espruino's pretty good. It handles SPI, I2C, OneWire(in software), ADCs, DACS, etc. But then micro python does too? I think the difference is that *the API is the same across all platforms* - I don't think micro python is quite as good that way

Gordon Williams Also, you can peek and poke if you need to do something properly low-level.

Radomir Dopieralski yeah, there has been some problems with that

Radomir Dopieralski have*

Paul Stoffregen what does Espruino have for USB support?

Gordon Williams libraries - same thing. There are a bunch, and I try and keep a curated set on the Espruino site that are reasonably well documented with examples: http://www.espruino.com/Modules

Shayna Apologies for jumping the gun on your callbacks question, @azathoth-org ;)

Radomir Dopieralski curated list of libraries -- great idea!

Gordon Williams I quite like the idea of having one place where you can go and find *one* module that does what you want - but you can also grab whatever you want from online as well. You can even reference by URL in your code and it'll drag it in

Gordon Williams@Paul Stoffregen yes - it's not super low-level, but it'll do USB HID and VCP.

Arsenijs Yeah, I recall MicroPython had to figure out the whole "different boards, different features, different peripherals" thing and how to integrate it well enough =)

Radomir Dopieralski@Arsenijs it's better with circuitpython

Paul Stoffregen supporting a wide range of hardware is really tough work

Gordon Williams :) Yeah, it's actually a nightmare trying to get contributors to do stuff like that - nobody wants to do the boring job of refactoring other people's code

Shayna Still good on time, @Gordon Williams ?

Radomir Dopieralski cat herding

Shayna Hehe

Gordon Williams Yep, I'm good for time :)

Shayna Great

Gordon Williams I'll try and answer the callbacks question - Espruino's stack depth isn't that great. Because it executes from source it tends to use more stack when it executes.

Boian Mitov @Paul Stoffregen "supporting a wide range of hardware is really tough work" tell me about it... :-D I try to support almost every single platform with Visuino... Adding ST Electronics now...

Gordon Williams However, the way you write JS is generally using callbacks, which don't require recursion. In that case it's basically infinite - just as much free memory as you have available.

Arsenijs Didn't circuitPython fork after the problem was solved? Also, Adafruit does have their own libraries for GPIOs, and their own ways to handle them, so I'm guessing they'd want to do things their own way - but I do recall feeling like there were more abstraction layers than I felt comfortable with having.

Radomir Dopieralski @Arsenijs let's talk about that later

Gordon Williams Next question I guess?

Arsenijs Right, sorry

Shayna Next up from @todbot : "npm-like package manager for Espruino? (Does the question even make sense for embedded?)"

Gordon Williams Right - yes, that's been kind of a long-running thing. At the moment, for the curated list of modules, the IDE just downloads from an un-version-controlled list

Gordon Williams and that's ok 99% of the time, because I curate them and try and make sure that they're always as backwards compatible as possible

Gordon Williams If someone submits something that randomly changes all the names of functions and breaks everyone's code, I won't merge it

Arsenijs Oh, so you basically have your own repo(s) and you only merge after reviews?

Gordon Williams But yeah, that really doesn't scale. The real answer there is 'just use NPM' - I think i'd be nuts to try and make my own

Shayna From our very own @Jordan Bunker : "Do you think having interpreted languages on microcontroller is changing the way people make things? If so, how?"

Gordon Williams @Arsenijs yep, it's just https://github.com/espruino/EspruinoDocs - the URL is configurable in the IDE so nothing stops people from using another provider.

Gordon Williams NPM support itself is a bit iffy, because NPM modules are generally huge and have lots of dependencies - so it only really makes sense if you can do 'tree shaking'... And that has been done with http://thingssdk.com/ - I just wish they'd contributed back to Espruino rather than trying to make their own thing

Gordon Williams Yes, I think having interpreted languages is really helping. I think for one it's allowing more people to get into embedded electronics - it's really frustrating having something just 'not work'.

Radomir Dopieralski "you want to run fast — run alone, you want to run far — run together" — old African proverb

Gordon Williams Also different people - now if you know JS or Python you can go embedded without having the extra hurdle of having to use C and get a dev environment set up

Radomir Dopieralski you still need to learn about stuff like timers or i2c

Gordon Williams @Radomir Dopieralski nice - I like that :)

Shayna Also from @Jordan Bunker : "Where do you see the future of Javascript (or other interpreted languages) on microcontrollers going? Does it scale into industry?"

Gordon Williams @Radomir Dopieralski yes and no... For simple stuff - maybe an OLED like http://www.espruino.com/SSD1306 - you can just use a module. Connect SDA and SDA and so on, and you don't need to know what I2C actually does until you try interfacing to something yourself. Hopefully it's a shallower learning curve

Gordon Williams Yes, I think it really does scale in industry. It sounds crazy, but so much industrial control software is still written in BASIC

Gordon Williams People may not like JS, but I think that with all the analysis tools available now it's still going to be more reliable and easier to develop than proper old-style BASIC

jipe_rey having interpreter language is a HUGE plus for rapid prototyping. Furthermore, for someone with no programming skills, it is the best way to dig into led-blinking stuff. I already succeeded in converting HW-only guys (5 colleagues) into SW world, just by showing them how easy it was to control the physical world with a few lines of script.

Keep going, Gordon, what you are doing is really changing the way things get automated and interracted!

Shayna We're nearly ready to wrap up the sheet -- so after this one last Q from @Todd , we can revisit anything 'off-topic' from earlier in the discussion, @Gordon Williams 's schedule willing. :)

PaulG @jipe_rey ditto

Shayna And from @Todd : "What about Webassembly on Espruino?"

Gordon Williams @jipe_rey Thanks!

Gordon Williams Nice one to end on :) So there was another standard for this - which I forget the name of - which was 100% human readable JS, where each line was an assembly instruction like `mem

Gordon Williams `mem[x] += 5`

Todd asm.js?

Gordon Williams Ahh - thanks. yes, that's it :) And that's what got me started on the "compiled" JS option - I thought rather than restrict it to just asm.js I'd make it handle as much normal code as I could do easily

Gordon Williams So after that I haven't really looked into WebAssembly too hard, but it does seem like it could be implemented.

Todd I didn't even know about this until you mentioned it, https://www.espruino.com/Compilation

Gordon Williams :) Yeah, I should push it a bit more really. It's only the STM32-based boards that have it at the moment

Todd Once you implement Wasm in it, one can basically compile anything to Wasm, so we can go back to programming in BASIC like it was intended! ;)

Gordon Williams Right now, Web Assembly could be implemented in the IDE as preprocessing step, but it would make a lot of sense to stick it in the interpreter itself. I guess it depends if there is call for it - right now I'm not sure anyone is using it on it's own - it's usually people using emscripten to compile whole C programs to JS

Gordon Williams Oh you can do that now... I'm sure there's a BASIC->JS compiler. There's definitely one for Pascal :)

Todd right, it's a compilation target, mostly for C/++

Todd yeah, there's a BASIC->JS compiler.... I even tried it once, I just had to ;)

Shayna Thank you for joining us today @Gordon Williams ! And thanks for the great questions, everyone.

Gordon Williams Thanks! I enjoyed that - those were great!

jipe_rey @Gordon Williams thank you !

Radomir Dopieralski thanks!

Gordon Williams Just quick - because I should mention it a bit - the book I did is this one :) https://www.amazon.com/gp/product/1680451898

Shayna Excellent!

PaulG My god, compilation, never knew that one either, thx @Todd - and thanks @Gordon Williams .

Radomir Dopieralski @Arsenijs so about circuitpython, they made their own modules for peripherals precisely to insulate themselves from the micropython changing stuff willy-nilly and inconsistently

Gordon Williams It uses JS, but it's about making very simple machines to fun stuff

Discussions