The story behind this little machine goes back a couple of years. I had wanted to quickly test out a motor control idea, and grabbed an Arduino and a little H-bridge board, and sat down to write some code. The code wasn't hard, and the development process, while not long, took much more time than it should have. I'd spent more time dealing with the IDE and the tools, than in actually being creative. The overhead was much greater than it should have been. It was mildly frustrating, and I pondered how doing "embedded stuff" wasn't as much fun as it used to be. That made me think back to my favourite embedded systems I'd worked with in the past, and what made them nice to use. Consistently, they were all Forth-based machines I'd used in the 80s and 90s.
So what exactly is Forth?
Forth is a compiler, an interpreter, a debugger and, in a fashion, an operating system too. Forth is an extensible, highly-interactive, stack-based language. It is extremely efficient and extremely versatile.
Forth is very interactive. You can type commands in, and interact directly with hardware at a register level. The functionality of the language makes it ideal for debugging both system hardware and software. Forth is typically coded directly in assembly language both for speed of operation and to take advantage of the characteristics of the machine. That makes it very fast. Forth is unlike any other conventional programming language.
Commands (known as words in Forth) get an immediate response. This, coupled with Forth’s ability to talk directly to hardware, makes it an excellent environment for embedded system applications.
Forth words are the equivalent of functions in C, Python or Java, or subroutines in assembly language. Forth allows the execution of any word in isolation from the command line. Thus, words can be independently tested and verified outside of the main application. So rather than writing a single, large program, small segments of code are written and tested independently (and interactively). These words are then combined to create new words, eventually ending up with a single word that is the whole application. This new word is also available to the developer, and in this way the language both grows and becomes richer as the developer works with it. In addition, the words used to create the new word are still available and can be run as programs in their own right, or used to create other new words. Forth is both versatile and powerful.
So why is Forth not widely used? It's very powerful, and the development process is much faster. But, you can't write sloppy code with Forth. It's not forgiving. You really have to think about what you're trying to do. This isn't a bad thing, because invariably you will come up with a solution is that is tighter and more robust.
Hardware for Forth
With fond memories of Forth in mind, I looked around at what off-the-shelf, forth-based embedded systems might be available now. Answer ... none. There are several varieties of Forth kicking around, as source code. And these can be ported to various dev boards or other embedded systems. But there was still effort involved in getting Forth running. Granted, it's not hard (well, mostly). For someone just wanting to try Forth in an embedded context, or someone completely new to embedded systems, this presented a barrier to entry. Why can't you just buy a Forth-based machine off the shelf and start using it? To me it seemed an obvious thing.
I decided to design and produce a small embedded machine with Forth preinstalled. I selected FlashForth, written by Mikael Nordman, as the Forth environment. The first hardware version was in a DIP form factor, similar to an Arduino.
I quickly came to the conclusion that the breadboard wasn't always necessary, and so the form factor of the machine changed. By using a single inline connector on the underside of the PCB, modules or devices could be wired in directly.
The addition of a pin strip allows it to be inserted into a breadboard. Alternatively, it can be mounted into another PCB as a Forth-based compute engine.
The current version is known as a Scamp, and has been available for the last 12 months. The basic FlashForth implementation has been extended to include direct support for digital input and output, analog input, PWM and I2C support. From the prompt, you can type an I2C packet to a peripheral, and get an immediate response. I2C development has never been faster.
The Scamp is based on the PIC24FJ64GB202 processor, which is a 16-bit processor with a rich mix of peripherals and a USB interface. To use a Scamp, you don't need to install any IDEs, compilers or development tools. Everything runs directly on the Scamp, and all you need is a host computer with a USB interface and some terminal software.
Scamps have been used in schools and universities for research or teaching. It's used in home projects by hobbyists. Companies have used Scamps in product development to rapidly prototype and debug their own hardware.
The designed has evolved into the Scamp2, with an onboard temperature sensor and a bank of 17 status LEDs (sixteen red and one amber). It's available under my Udamonic brand. Use it standalone, or with external I/O modules, or interfaced to a breadboard design.
- 32 MHz 16-bit PIC24 processor with 16 MIPS performance
- 64K flash memory (of which FlashForth takes up approximately 23K)
- Flash memory has a 20-year lifetime; 20,000 write-cycle endurance
- 8K of RAM
- USB v2.0 port, with USB console support (no driver required)
- Scamp2 has 17 ultra bright status LEDs, user controllable (1 amber and 16 red), with forth support
- Onboard temperature sensor with forth support
- General-purpose I/O lines, with software-configurable pullups, with forth support
- High-current sink/source (18 mA / 18 mA) on all I/O pins
- 10/12-bit multichannel Analog-to-Digital Converter with forth support
- I2C Interface with forth words in dictionary
- 3x SPI interfaces, remappable to different pins
- Multiple 16/32 bit counter/timers
- 6 Channel 16-bit PWM generation with forth support
- Up to 2 UARTs, remappable to I/O pins, capable of supporting RS-232C, RS-485 and IrDA with forth support
- Hardware Random Number Generator with forth support
- FlashForth preloaded, with additional words for Scamp peripherals
- PIC24 also has 32-bit CRC Engine, Digital Signal Modulator and Cryptography Engine
- Software development takes place on the Scamp, no IDE or compiler suite required!
- Fully assembled and ready to use! Just connect to any host computer.
Scamps require a Micro B USB cable for power and communications, available as an option when ordering. A breadboard header is an optional extra.
If you would like to try a Scamp for yourself, it's available on Tindie.