Espruino
Espruino is an interactive Javascript interpreter for microcontrollers. You can interact with it in a 'minicom' or 'screen' terminal on the serial port, directly communicate with it from the Raspbian commandline, or upload .js files and Espruino 'modules' with the commandline tool 'esp-cli'.
Espruino is written by Gordon Williams. Find more info about Espruino here: www.espruino.com
Espruino is fully event-based. Which is exactly what you want when programming microcontrollers. Once you have Espruino running on the ARMinARM board, the code you write for it looks like this:
var on = false;
function toggle() {
on = !on;
digitalWrite(LED, on);
}
var interval = setInterval(toggle, 250);
Upload Espruino
The easiest way to get Espruino running on your ARMinARM board, is to upload the precompiled Espruino binary from the 'setup' menu. That automatically downloads a fairly recent version for the ARMinARM board and uploads it.
Compile from source
To compile and upload the latest Espruino firmware from source, select 'Update/Install Espruino source code' from the 'setup' menu. That updates the (upstream) git repository and builds the .bin file automatically.
Upload the resulting file with the 'arminarm' tool (replace '1v71' for the version that was compiled).
cd src/Espruino
ls
arminarm flash espruino_1v71_ARMinARM.bin
Using Espruino
After Espruino uploaded to the ARMinARM board, you can talk to Espruino with 'minicom' or 'screen'.
screen /dev/ttyAMA0 9600
Short (very short) interactive demo session:
_____ _
| __|___ ___ ___ _ _|_|___ ___
| __|_ -| . | _| | | | | . |
|_____|___| _|_| |___|_|_|_|___|
|_| http://espruino.com
1v71 Copyright 2014 G.Williams
>3+2
=5
>digitalWrite(LED,1);
=undefined
>digitalWrite(LED,0);
=undefined
>print(analogRead(A1));
0.65821423666742959568409787607379257678985595703125
=undefined
>
<ctrl>+<a> <d> to quit 'screen'
espruino_cmd
You also have the option of communicating with Espruino directly from the commandline in Raspbian. There's good info about that here: www.espruino.com/Interfacing
The 'espruino_cmd.py' file that's mentioned on that page is installed as 'espruino_cmd' on your system when you installed the toolchain. It can be found in the arminarm/src/tools directory, and ends up in /opt/arminarm/tools. Make sure you copy it there if you decide to make changes to it.
$ espruino_cmd 'echo(0)'
echo(0)
$ espruino_cmd 'print(analogRead(A1))'
0.57593652246
$ espruino_cmd 'analogWrite(LED, 0.3)'
$ espruino_cmd 'digitalWrite(LED, 1)'
$ espruino_cmd 'print(digitalRead(BTN1))'
0
$ espruino_cmd 'print(digitalRead(BTN1))'
1
$ espruino_cmd 'echo(1)'
=undefined
>
$
Instant blinky? Try this:
$ espruino_cmd 'setInterval("digitalWrite(LED,a=!a)",500);'
esp-cli
The 'esp-cli' tool is written by Gamaiel Zavala. It's a command line tool to interact with Espruino. You can upload .js files to Espruino on the ARMinARM board, and load Espruino 'modules'.
Install it from the 'setup' menu. To run esp-cli, type:
esp
You'll get into an interactive esp-cli session
pi@raspberrypi ~ $ esp
Connecting to Espruino compatible device on /dev/ttyAMA0...
>loadBoardInfo: trying to load board info for ARMinARM.json
loading board info for ARMinARM.json
>.help
.break Sometimes you get stuck, this gets you out
.clear Alias for .break
.exit Exit the repl
.help Show repl options
.load Load JS from a file into the REPL session
.module Add a module for require
.save Save all evaluated commands in this REPL session to a file
.version Display version information
>.version
CLI: 0.0.2
>.load blinky.js
>var on = false;
>function toggle() {
... on = !on;
... digitalWrite(B0, on);
... digitalWrite(B1, !on);
... }
>var interval = setInterval(toggle, 500);
>.exit
Disconnecting...
Please read the README.md file in the src/esp-cli directory for more information.