Iwas an early convert to Forth after having worked at JPL on inter-planetary spacecraft where Forth was used for testing purposes at Rolm Corporation on Forth-based PBX control and test applications, and at Sun Microsystems where Forth was used as the boot environment on many Sun workstations. Then as now,
Forth is an excellent choice for programming small
computer systems where direct control of the hardware, of
inputs and outputs (I/O), and/or a small memory footprint
are required. In this article, I hope to convenience you of
this assertion and to pique your interest enough to try it
out for yourself. As luck would have it, the Arduino Uno is
the perfect vehicle for trying Forth.
What is Forth Anyway?
Forth is a stack-based procedural programming
language invented by Charles H. Moore around 1968.
Moore used Forth for controlling space telescopes at Kitt
Peak Observatory in Arizona. At that time, programming
tools for small computer systems were rather crude and
computer memory was very expensive. C compilers were
not yet widely available, BASIC was still fully interpreted and
therefore very slow, and Fortran compilers were very
expensive. Programming during this period usually meant
assembler language or — worse yet — machine language.
Forth offered a higher level of programming that increased
productivity while still offering low level access to the
hardware if required by an application.
Forth source code is line-oriented and can be entered
interactively or stored in text files, and loaded in bulk. A line
of Forth source consists of a series of tokens (words and
numbers) separated by space/blank characters. The Forth
interpreter reads in the tokens and either executes them
interactively or — if in compile mode — compiles them for
The Forth word is a language element that can be used
interactively or within a program. Source code for a
particular word is called its “definition.” Primitive Forth
words have their definitions coded in the CPU’s native
assembler language, whereas non-primitive words have
their definitions coded in Forth. A Forth program is run by
executing the highest level word which defines the
The Forth word “:” (colon) puts the interpreter into
Today, it seems that everything for microcontrollers is written in
some flavor of C. However, C isn't necessarily the most efficient
language to use for controlling servos and sensors. There are
alternatives, including Forth — perhaps the earliest language of
robotics. Forth has a lot going for it, especially if you're into rapid
prototyping of microcontrollers. It's extensible, memory efficient,
and gives you direct access to the underlying hardware.
SERVO 02.2014 53
Post comments on this article and find any
associated files and/or downloads at
By Craig A. Lindley