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.
This page describes how to use the Serial Monitor, built in to the Arduino IDE. For information about using uLisp with a serial terminal see Using uLisp from a terminal.
Using the Serial Monitor
The Serial Monitor, which is built in to the Arduino IDE, provides the simplest way to interface with uLisp.
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 Newline and the baud rate is set to 9600 baud.
You can now either type commands into the field at the top of the Serial Monitor window, or copy and paste an entire uLisp program. Press Return or click the Send button to submit it to uLisp.
Defining a function
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:
Changing a function
To change the definition of a function simply enter a new definition for the same function. For example, we can make sq return the cube of a number; enter:
(defun sq (x) (* x x x))
This will replace the previous definition, and automatically free up the memory it used.
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.
Because the formatting of a Lisp function doesn't affect its meaning you can copy and paste whole Lisp programs into the Serial Monitor entry field.
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.
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.
There's also a simple program editor you can use to edit function definitions: see Using the program editor.