uC issues
Toolchains
Designed for industry
Often non-free/crippleware
Badly documented
Bad multiplatform support
vendor-dependent HAL
Debugging often hard or impossible without extra hardware
Silicon Erratas
Arduino
Arduino makes things better
But who hasn't used Serial.write(...) and Serial.read() for debugging?
Bad Multitasking
Not really low power
Scripting
If running in uC then no toolchain to install
Easy to inspect and change while running
Rapid development
Source code is on the device itself
Friendly - no segfaultsQuick to tweak
Instant - more fun!
Why JavaScript?
A little bit like C,simple syntax
Loads of people know it already
Huge amount of learning material
With browers and node.js,you can run JS end to end
JSON built-in
Event-based model
Events on Hardware
Matches real world interaction
A lot like interrupts - without any pain
Low overhead cooperative multi-tasking
Easy to combine different functionality
Plays well with REPLs
Power Saving - interpreter knows when it can go to sleep,and how deeply
Power Saving
Many projects benefit from battery power or even energy harvesting
Navie LED flash on a 700mAh Li-lon battery:
Raspberry Pi : 1-2 hours
Arduino : 1-2 days
Espruino : ~6months
It's not easy. To wake up once a minute:
Start Low Speed Oscillator + Wait
Set up RTC
Set up Alarm
Set up interrupts
Turn off peripherals
Enter sleep mode
Re-initialise peripherals
In Espruino:
setInterval(function(){ ... },60000)
Why not use a desktop JavaScript engine?
Speed RAM NV Storage Power Draw
Typical Desktop 2500MHz*4 4000000kBytes 1000000MBytes ~50W
Typical ARM Mic 72MHz*1 8kBytes 0.125MBytes ~0.001W
~1000000 times less RAM
~10000000 times less storage
So add more RAM...
More parts:more expensive, bigger, 10-100x more power draw
Tessel(32Mb RAM, no OS)
Raspberry Pi(512Mb + node.js)
BeagleBone(256Mb + node.js)
OpenWRT(~32Mb)
And many others...
On-chip RAM
On PC - read all RAM in ~1sec
On uC - read all RAM in ~0.001sec
Less of everything, but 1000x more CPU power per byte.
Espruino Software
Purpose Built JaveScript interpreter for uCs
Open Source, C
No operating System
Can run in less than 8KB RAM
Program using Terminal app
Multi-line editing, command history in chip
Serial or USB CDC
Not just JavaScript
Built-in libraries:
Use require('...') to get drivers for new devicesStandard String/Array/etc
Maths(includeing FFT)
Waveform IO
HTTP(CC3300 and WIZnet W5500)
Graphics (w.Bitmap and Vector fonts)