Out: Hot rods. In: Robots.Publication date: 4 May 2010
Originally published, in a smaller version, 2009 in Atomic: Maximum Power Computing
Last modified 19-Mar-2016.
Back when the integrated circuit was young, it was a selling point to say that a gadget contained a "silicon chip". Nowadays, we're surprised if a car or telephone or microwave oven doesn't have a CPU.
The downside of this is that if something goes wrong with modern devices, you often can't fix them without buying a whole new circuit board, which for unusual or several-years-old appliances may be ridiculously expensive. (Don't even ask about cars.)
The upside, though, is that even as the repairability and hackability of common household devices has been falling, the accessibility of computerised control systems for home hobbyists has been going up. This has opened up whole new vistas for the part-time hardware hacker.
The CPUs in cars and appliances are usually integrated into a "microcontroller" (µC, for short), a tiny little computer built into one chip. The simplest microcontrollers have the brainpower of a personal computer from 1980, but often rather less memory, because the programs they have to run are usually tiny. You don't need a million lines of code to run a dishwasher.
Several modern microcontrollers, though, have the CPU power of a PC from 1990, or even 2000. And it's not terribly hard to hook them up to, say, a Flash memory card, if you need bulk storage.
The µCs in these projects are "single-board microcontrollers", little circuit boards that contain a µC and supporting components. They don't do anything you couldn't do with the bare microcontroller and extra bits you bought yourself, but they make development a lot easier. They let you easily connect input and output devices, a power supply, and a data cable to load a program onto the µC from a "real" computer.
Yes, you do have to do some actual programming to make a microcontroller do stuff. But there are several easy-to-learn languages that work with one or more flavour of µC. The good old "BASIC Stamp" - first sold in the early 1990s, and still available, along with umpteen clones - has a BASIC interpreter in ROM. There are several other languages specially made to be highly accessible to new coders, and which work well with µCs; look, for instance, at the development suite that comes with the deservedly-ubiquitous Arduino and its clones, the related "Processing", and the Parallax Propeller's "Spin". (See also "Fritzing", which aims to simplify turning your hacked-up µC project into an actual product.)
And you can even get point-and-click graphical-flowchart programming interfaces for microcontrollers, like for instance the dirt cheap PICAXE. If you're not even comfortable with an electronics-prototyping "breadboard", let alone soldering, check out Lego's "Mindstorms" gear! The basic Mindstorms programming interface is point-and-click, but that's all you need for a lot of tasks, and there are numerous more powerful languages that work with Mindstorms controllers too. Third-party companies even make add-on sensors (and compatible parts made of metal!). So Lego is now a surprisingly capable robotics prototyping system.
It's been possible to do this sort of thing since the early personal-computer days - people hooked up many odd devices to their Apple II or Commodore 64, often via the serial or parallel port. (Parallel ports weren't standard equipment for a lot of early home computers, by the way; you can now get a couple of terabytes of hard disk space for the price of a lousy parallel-port card for an Apple II.)
The difference between doing it with a desktop computer then and doing it with a microcontroller now, besides better entry-level programming languages, is that a computer able to do this stuff in the early 80s was really expensive (even without a parallel port...). But single-board µCs are very cheap. And can, you know, fit in a cigarette packet and run from a 9V battery.
Look at the fancy "Duemilanove" board that's currently the top of the "Arduino" line, for instance. It'll cost you less than forty Australian dollars; less than $30, in the States. And another $40 will buy you more than enough loose transistors and switches and resistors and LEDs and motors and buzzers and wire for lots of educational experimenting.
And this is a high-powered µC board, that can do a lot more than most people need. If all you want is an ordinary single-board microcontroller, you can pay considerably less. Or a little more, for a "development board" with a lot of fiddly stuff already done for you. Oh, and then there's Atmel's AVR Butterfly, which has a joystick, speaker, clock, flash RAM, temperature and voltage sensors, and a little LCD screen, for twenty US dollars.
The microcontroller world also doesn't move as fast as PC technology, but better, cheaper µCs are still coming along all the time.
These things are so cheap, and so accessible, that people are even using them for tasks that obviously do not actually require a general-purpose stored-program computer with multiple inputs and outputs. There are lots of electronics projects - think of a "sun tracker" to aim a solar panel, say - that clearly only actually need a few logic gates. Such projects can quite easily be assembled out of simple components, with just a few transistors and/or relays and perhaps a couple of mechanical linkages.
But when you can buy a real computer with thousands, or millions, of transistors for pocket change, why not?
Your tabletop physical Pong machine could be controlled by pinball-machine components from 1950... or by an ATmega168. See also the even-more-conceptually-simple, also-microcontroller-equipped, robotic crawling pumpkin.
It's actually reached the point where microcontrollers are the first port of call for anybody who wants to make something with a bit of logic in it. Nobody's figured out an excuse to put a microcontroller in a Tweenbot yet, but it's clearly only a matter of time.
I mean, let's say you want to make a little two-wheeled "inverted pendulum" balancing robot, for instance. You can do that with a pretty simple analogue circuit. (That site is fantastic, by the way.) Heck, you can almost do it with one switch.
Or you can use a microcontroller, as many people have. (There are, of course, numerous Lego versions. Lego parts even sneak into many of the non-Lego ones. It makes the occasional Fischertechnik version a pleasant change.)
Now, once you've got a computer-controlled balancing doodad, it's much easier to tune its behaviour, and unexpectedly complex tuning issues are to be expected for real-world applications like, say, a full-sized Segway clone. That second page has a lengthy explanation of the large number of problems you have to solve in order to make a balancing scooter that won't, when faced with any of a large number of common real-world situations, whip your face into the ground before you can get past the "f" at the start of the word you're trying to say. For systems that actually need a complex sensor and control setup, a microcontroller lets you handle all of the connect-this-to-that issues without creating a terrifying analogue rats' nest.
Sure, most of the capacity of the µCs in just about all of these projects is wasted. Many of them could have been made in days of yore, out of switches and latching relays and springs and cams. And in the early personal-computer days, the idea of using a whole dedicated general-purpose computer to do sensing and control tasks in small hobby devices was outrageous. But nowadays microcontroller boards are cheap, and you can just use a little program to create very complex control systems.
If you don't find this new Age of the Microcontroller Hobbyist rather exciting, I contend that your imagination may be defective. We are now, unexpectedly, living in an age when children can no longer get a proper chemistry set, but can make autonomous robots.
I'm immensely excited to see what those kids make when they grow up.
(And also a little afraid.)