arduino.js: Arduino <-> JavaScript API exper

Hi Arduino folks,

I build web things for fun (and work), so the browser is my environment of choice - and given a recently-renewed electronics interest sparked by the idea of music-driven lighting for a Hallowe’en party, I ended up writing a JavaScript API that wraps the Flash AS3Glue library, effectively making the same functionality available to JavaScript. I couldn’t think of creative names, so I went with “arduino.js”, the name of the script that defines the API. :stuck_out_tongue:

This makes it a bit easier for web developer types to talk to an Arduino from JavaScript, still using a socket connection from the browser and thus without having to rely on an Apache or similar server processes running on the same machine etc. (In my case, I developed and tested this library with an Arduino Uno.)

Online example, docs etc.:
http://www.schillmania.com/projects/arduino-js

A brief video showing JS reading pots and controlling sound pan/volume in the browser, LEDs responding (albeit poorly, a quick hack :D) to music:
Imgur

And on Github, of course:

The set-up is a bit “Rube Goldberg-esque” as it’s JS <-> Flash <-> Socket/serial proxy <-> Arduino (running Standard Firmata), but it does work pretty well on the PC and Mac from what I’ve found.

Many thanks go to Erik Sjodin and Bjoern Hartmann who worked on AS3glue, and Kasper Kamperman and Saxion who made the AS3glue “example script” I based my implementation off of.

My “TODO” list includes looking at using the upcoming WebSocket features in HTML5 to communicate to the socket/serial proxy, and seeing if the flash layer can be made redundant. Related projects like socket.io which use JS and/or flash sockets may ultimately be the way to go for this approach.

WebSockets are a tad bleeding-edge right now (Firefox 4, iOS 4.2 etc.), and I suspect the WebSocket security model may require the “hosting” web page and the serial/socks proxy to be running off the same host (eg. 127.0.0.1), but this remains to be explored. Until if/when I (or someone else) ever figure those bits out, I think the AS3glue guys have done a nice job putting together a library that works well with Firmata on the Arduino.

In closing, I made this originally as a hack for myself, but thought I should put this out there in the event that other folks might find it useful. If you check it out and find it to be so (or not), do let me know; In any event, I welcome forks on GitHub, improvements and so on.

(Oops, title of this thread should end in “experiment” - editing didn’t seem to fix it after the fact. :P)