Shell Programming with Txtzyme

By: WardCunningham

2010-06-07 14:02:40

An interpreter need not be more than a case statement with a loop around it. I've written just such an interpreter for Teensy starting with a variation of Paul's USB Serial example. I'm finding it very handy. If I need a 1.5 millisecond pulse I would type:

echo 1o1500u0o >/dev/cu.usbmodem

This example uses three single letter commands, each proceeded by a sequence of digits that loads data that any command can use or modify. Here is what the commands above mean:

1o -- output high on the selected pin (LED pin by default)
1500u -- delay for 1500 microseconds
0o -- output low to finish the pulse


Other commands include:

200m -- delay 200 milliseconds
4a -- select pin 4 of port A
i -- input from the selected pin
p -- print data that the host can read
100{} -- repeat commands within braces 100 times

Putting these all together we get a program that samples pin A4 at 5 Hz and writes what it finds to standard out:

echo 4a100{ip200m} >/dev/cu.usbmodem
cat /dev/cu.usbmodem

I've put the project up on GitHub. Look for Txtzyme which means "text that catalyzes action". My fork there will be accumulating operations I find handy in my sensor network and, of course, as a utility device on my workbench.

Followup Posts

Back to archive index