Close

Scamp - a Forth-based Embedded Computer

johncatsoulisjohncatsoulis wrote 11/22/2020 at 00:57 • 6 min read • Like

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.

The specs:

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


Update:

Scamp has received an update! The new Scamp3 is now available.

Scamp3 has more flexibility with I/Os, a dedicated SPI port on the main connector with inbuilt Forth support, two dedicated UARTs on the main connector with Forth support, and Forth support for the Digital Signal Modulator. 

Like

Discussions

johncatsoulis wrote 04/24/2021 at 00:12 point

Actually Ken, when I was looking for a name for this device I'd just watched a Youtube video on the SC/MP, and thought "yeah, that's a good name for it..." :) 

  Are you sure? yes | no

Ken Yap wrote 04/24/2021 at 02:00 point

Good to know the idea scampers on. 😃

  Are you sure? yes | no

Ken Yap wrote 04/24/2021 at 00:10 point

Remnded me of the older SCAMP, actually SC/MP: https://en.wikipedia.org/wiki/National_Semiconductor_SC/MP though I never had one so no nostalgia for it.

  Are you sure? yes | no