Jumping the Hardware Divide

April 23, 2014

You might ask why I prefer this to Arduino. It is an easy path to move to a more powerful setup.

In a world of square and round holes, I’m an octagonal peg. That is, I’m not exactly a software guy nor am I exactly a hardware guy. I suspect a lot of people who do embedded development feel the same way. When I work with hardware guys, I find that a lot of them dabble in software to some degree. The number of pure software guys that I see who try their hand at hardware is somewhat smaller.

I have noticed that number is, however, on the rise. The Basic Stamp was one of the first “easy” embedded platforms, and these days the Arduino is all the rage. Both of these offer an easy way to build embedded systems. An inexpensive board incorporates everything you need to program the device using a common PC. These boards are somewhat anemic, though, featuring relatively small amounts of memory and limited 8-bit instructions sets.

On the other end of the spectrum are boards like the Raspberry Pi, the Beagle Bone, and a host of imitators. These boards are more like early model PCs (actually, many of them far exceed my first PCs). These often use Linux and are really more miniaturized PCs than what I think of as classic, small embedded systems.

I’ve been interested lately in what can fill the gap between these two extremes. Even more than that, how can people who want to build their own hardware get past the “buy a module” stage? I think I’ve found a pretty good answer.

I’ve written before about using 32-bit ARM processors, typically using some inexpensive development board. These are great, except for two things. First, the boards aren’t really suitable for any sort of production. But they are better to prototype with because the CPUs are in tiny surface mount chips. I don’t mind prototyping with surface mount, but for someone starting out (or a student) it can be daunting. The other problem is the toolchain.

If you buy one of the commercial environments, that’s not a big problem. A lot of the boards come with some trial or limited software and if that meets your needs, that’s probably fine. If that software doesn’t run on your operating system, or if you don’t want a limit on what you can do, you need to set up your own tools. That isn’t as hard as it used to be, but it is still a barrier. Each CPU has slightly different start up needs, and getting a good build environment set up isn’t trivial for the neophyte.

I’m not saying any of these things are impossible, of course. But if you are trying to get started from some environment like the Arduino, it is definitely an obstacle. However, a few things have changed that makes getting started with ARM more on par with the Arduino.

The trick is the NXP LPC1114FN28. This is an ARM Cortex M0 CPU with 32K or program storage, 4K of RAM, and an internal clock that can drive the chip at 48MHz (the chip can run at 50MHz with an external clock). The internal clock, the fact that it is in a 28-pin DIP package, and the inclusion of serial bootloader makes the chip ideal for prototyping. They cost about $3, which doesn’t hurt either.

If you are familiar with a solderless breadboard, it is as easy as plugging the chip in, providing a 3.3V regulated power supply, and connecting a TTL-level USB to serial cable to the chip’s serial port. You could also use an old-fashioned serial port if you have a TTL level converter. Either way, those items are common and cheap these days.

The only other thing you need is a way to pull the bootloader pin low on reset so you can load software on the device. If you want to go first class, you can put a button or a jumper on the reset and the bootloader pin. If you don’t, you can just use a piece of wire on the breadboard to short the pins to ground.

For tools, there are plenty of choices, and I’ll talk about some of them next time. For a starter, though, there’s the online Mbed compiler shown in the figure below. You can use this online IDE to compile C++ programs using the very nice Mbed libraries.

The Mbed libraries take care of the startup, multiplexing, and other tasks that beginner ARM programmers usually find daunting. Here’s a simple Mbed program to generate PWM on an output pin:


#include "mbed.h"
 
PwmOut led(LED1);
 
int main() {
    while(1) {
        for(float p = 0.0f; p < 1.0f; p += 0.1f) {
            led = p;
            wait(0.1);
        }
    }
}

There are Mbed objects to cover common operations available on the CPU. For example, here’s how you’d read an analog input port:


AnalogIn ainput(p19);
float v;
   . . .
        v=ainput;

You might ask why I prefer this to Arduino. The CPU has more power, of course. A 32-bit processor running at 48MHz is a good bit of horsepower. However, it is more than just that. Granted, the online IDE and the Mbed libraries make things simple like the Arduino. But, it is an easy path to move to a more powerful setup. The LPCXpresso suite, for example, works well and interfaces with several inexpensive debugging probes (in the $20 range) so you can do single stepping, breakpoints, and the like. On top of that, if you want to do something serious, there are plenty of upgrade paths to larger processors (although not on a solderless breadboard).

Next time, I’ll show you how my development environment is wired. It is simple enough for a first embedded hardware project. If you honestly don’t want to wire up anything, you can get a similar processor (with more memory) already on a board for way under $15. The board has an integrated touch sensor, a three-color LED, and a three-axis accelerometer. It also has built-in USB so you don’t need any additional cables.

The board is a lot of fun, but honestly, you’ll learn more building up your first board from scratch. It isn’t hard and it will make it easier in the future to integrate your design with a finished product.