
I've written a JavaScript interpreter which runs on a VERY cheap board, the STM32VLDISCOVERY. It's currently £8 from Farnell and it's got bags of IO: http://uk.farnell.com/stmicroelectronic ... dp/2118806
It's all 3.3v, so no problem connecting it with the Pi.
The interpreter is here:
http://www.pur3.co.uk/espruino/
Just follow the instructions there to put it onto the STM32VLDISCOVERY board, then use the instructions below. Most stuff in 'code' boxes needs to be copy and pasted to a terminal:
We need to stop the Raspberry PI trying to use its serial port:
Code: Select all
sudo nano /boot/cmdline.txt
Code: Select all
sudo nano /etc/inittab
Code: Select all
#Spawn a getty on Raspberry Pi serial line
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
Reboot:
Code: Select all
sudo shutdown -r now
Code: Select all
sudo apt-get install minicom
Code: Select all
sudo usermod -a -G dialout pi
Code: Select all
minicom -o -b 9600 -D /dev/ttyAMA0
Code: Select all
PI STM32
P1-04 5V
P1-06 GND
P1-08 PA10
P1-10 PA9
Note: On the Pi, P1-04/6/8/10 are 4 pins next to each other, down the long edge of the board. P1-02 is the pin right in the corner (don't use that one!) and P1-04 is the one next to it, P1-06 is the one after that, etc.
Now when you hit the black reset button on the STM32 board, you should see some text appear saying 'Espruino' in big letters. Sorted.
You can turn digital pins on and off using a command like digitalWrite(pin, value) - eg, writing digitalWrite("C9", 1); will turn the LED on.
Or copy and pasting the following will flash it 5 times every time you press the blue button:
Code: Select all
setWatch(function() {
if (!digitalRead("A0")) return;
var led=10;
var flasher = setInterval(function() {
led--;
digitalWrite("C9",led&1);
if (led<=0) clearInterval(flasher);
}, 200);
}, "A0", true);
To exit the terminal app, press Ctrl-A then X, then hit enter to confirm.
So now you might want to actually control some IO from a program.
Set up serial port:
Code: Select all
stty -F /dev/ttyAMA0 9600 -parenb -parodd cs8 hupcl -cstopb cread clocal -crtscts ignbrk raw min 0 time 5
Turn LED on:
Code: Select all
echo -ne 'digitalWrite("C9",1);\r' > /dev/ttyAMA0
Code: Select all
echo -ne 'digitalWrite("C9",0);\r' > /dev/ttyAMA0
Code: Select all
echo -ne 'digitalWrite("C9",1);setTimeout("digitalWrite(\"C9\",0);",1000);\r' > /dev/ttyAMA0
first - to set it up not to send any 'extra' data back:
Code: Select all
echo -ne 'echo(false);\r' > /dev/ttyAMA0
Code: Select all
echo -ne 'setTimeout("print(digitalRead(\"A0\"))",100);\r' > /dev/ttyAMA0;cat /dev/ttyAMA0
As you can run JavaScript while the Pi is off doing something else, you can also do stuff like this:
Every 10th of a second, read an analog value, and store it in a running average:
Code: Select all
echo -ne 'echo(false);var a=0;var n=0;setInterval("a+=analogRead(\"A0\");n++;",100);\r' > /dev/ttyAMA0
Code: Select all
echo -ne 'setTimeout("print(a/n);a=0;n=0;",100);\r' > /dev/ttyAMA0;cat /dev/ttyAMA0
So you could do it as a cron job, and read what the average has been over the last hour...
Anyway, hope that's interesting to someone - let me know what you think!
I'd like to find some way to get support for this so I can document it better, improve the interpreter and port it to more boards.