Tuesday, 17 January 2017

Embedded development is faster with a REPL

In my previous post I mentioned that I was frustrated by the slow pace of Arduino-style development and that I was looking at using a language with a REPL (Read-Evaluate-Print loop).

A REPL is just a fancy name for an interactive environment. You can type an expression and have the computer evaluate it; the computer display the result immediately. (If you've ever used Python interactively you'll know exactly what I mean).

Why REPLs are great

REPLs give you immediate feedback. If you've done something right, you get an immediate reward. If you've made a mistake, you get to fix it while everything is still fresh in your mind. I find it makes for much faster progress, particularly if I am using hardware or software I haven't used before.

They also give you a chance to do some stunning demos. Here's a video of two Dyabots dancing, courtesy of Morten Kromberg (CXO of Dyalog).

A tale of two REPLs 

C3Pi and Dyabot have two computers on board; a Pi to do the overall control, and a smaller, simpler micro-controller to handle motor control and related tasks. We could do that from the Pi but there are issues with real-time software on the Pi. We also  want to make sure that if the software on the Pi stops running the robot stops moving.

Ideally I'd like to program both the Pi and the micro-controller using interactive languages with REPLs. I'd also like to use languages that I know well that are widely used and well supported.

Spoilt for choice

There are plenty of REPL-based languages on the Pi. C3Pi and Dyabot use Python and APL, but those are just two of many alternatives.

There are fewer choices on the Arduino and the Teensy.

The Arduino IDE uses a subset of C/C++ with no REPL available. Development follows the usual cycle: edit, compile, upload, test.

I find that frustratingly slow.

If you want an interactive language with a REPL, there are versions of FORTH available on the Arduino but it has too little RAM for comfortable FORTH development. The Teensy is well suited to FORTH but the user base seems very small.

I've done some experiments with Mecrisp FORTH on a couple of low-cost ARM systems, and the results have been quite encouraging, but my FORTH is fairly rusty and the user community seems very small.

This week-end I realised there was a very promising alternative. I'm evaluating it at the moment.

It's cheap, it's easy to connect to the Pi, it has good GPIO and other interfaces, and I can program it in Python. Best of all it has a huge user base and great support from multiple vendors.

Tomorrow I'll post more details and tell you what I've established so far.

Meanwhile, I'm curious. What would hardware and software would you use as an intermediary between the Pi and the outside world? Leave a comment and let me know.