You communicate with uLisp using the serial interface, built in to all Arduino boards. You can either use the Serial Monitor, included in the Arduino IDE, or one of a range of alternative serial terminal programs available for the Mac or PC. You could also communicate remotely to an Arduino running uLisp using a suitable serial wireless interface.
For information about alternative terminal programs available on different platforms see Sparkfun's Serial Terminal Basics article.
Using the Serial Monitor
The simplest way to communicate with uLisp is to use the Serial Monitor, which is built in to the Arduino IDE.
After uploading uLisp to the Arduino:
- Open the Serial Monitor by choosing Serial Monitor from the Tools menu, or click the serial monitor icon to the right of the Arduino window.
The Serial Monitor window will show the uLisp prompt, prefixed by the amount of free memory:
- Make sure that the line ending is set to Carriage return and the baud rate is set to 9600 baud.
As an example we'll define the following function sq to square the number given as its argument:
(defun sq (x) (* x x))
Type it into the field at the top of the Serial Monitor window:
- Press Return or click the Send button to enter it.
Your input will be echoed in the serial monitor window, followed by the result from uLisp:
Now we can use the function we've defined to find the square of 47:
As a final example, try running the following equivalent of the Arduino Blink program:
(defun b () (pinmode 13 t) (loop (digitalwrite 13 t) (delay 1000) (digitalwrite 13 nil) (delay 1000)))
- Select the program above, copy it, then paste it into the Serial Monitor entry field, and press Return.
The window will look a bit messy because of the spaces used to format the program, but if all is well you should see the new uLisp prompt.
- Run the blink program by entering:
The LED next to pin 13 on the Arduino board should flash.
To exit from the program:
- Enter a "~" into the Serial Monitor entry field, and press Return.
The program will stop with the message:
Of course you could alternatively reset the Arduino, but that would lose the program definition from uLisp.
Using the Mac Terminal
On the Mac you can use the Terminal application, in Applications/Utilities, to provide a serial terminal. First you need to find out the name of the USB port the Arduino is connected to.
- At the Terminal prompt type:
This will display a list of the serial devices:
- Locate the one that corresponds to the USB port; in this case /dev/tty.usbmodem1411.
- Give the command:
screen /dev/tty.usbmodem1411 9600
where the second parameter is whatever you found from the previous command, and 9600 specifies the baud rate.
The screen serial terminal should run and show the uLisp prompt:
- Enter commands at the uLisp prompt; for example:
Note that commands are entered as soon as you type the final closing bracket.
To exit from screen:
- Type ctrl-A ctrl-\ and answer y to the prompt.
It's a good idea to write your programs in a separate text editor window, and then copy and paste them into the serial monitor or terminal. That way you have a permanent copy of your uLisp project which you can easily edit or save.