MICROCONTROLLERS
Keep it simple, stupid (KISS) is advice I live by.
We live in an age of immense computing power. Every day we carry in our pockets devices that would once have been considered supercomputers.
But if your passion lies in understanding technology — pulling it apart and hacking it — then there's much to be said for the smaller, cheaper, simpler end of the computing spectrum. And by that I mean microcontrollers.
Complete package
A microcontroller is a complete computer on a single chip. It has a processor (sometimes more than one), memory, storage and input/ouput (I/O) capabilities. Once programmed, it stores its code in non-volatile memory so that, when powered up, it jumps straight into performing its task.
They are everywhere. If you drive a modern car you're constantly accompanied by countless microcontrollers. They are in ovens, dishwashers, lightbulbs, fridges, alarm clocks, christmas tree lights — pretty much anything electronic that does more than simply switch on and off and isn't a full-blown computer.
And some microcontrollers are so powerful now that you can emulate entire computers of yesteryear on them. The justly popular ESP range even gives you built-in wifi.
But even within the microcontroller domain, I'm drawn towards the more basic devices — specifically AVR's 8-bit ATMEGA and ATTINY devices. And I'm not alone. The Arduino achieved its huge popularity using the ATMEGA328 microcontroller (although the range has moved on to more complex and capable chips since).
So what's the attraction?
Down to the basics
Even if you're writing code for microcontrollers in a relatively high-level language like C (and I say 'relatively' because we all know C is really just assembly language in a pretty frock), coding AVR microcontrollers encourages you deal more directly with the architecture, such as understanding registers.
You can get an Arduino and use its fine integrated development environment (IDE) and dazzling array of libraries. But I would strongly encourage you to dig deeper, learn to access the hardware more directly. Perhaps even delve into assembly language.
Digging deep into the machine
I lost my computing virginity to a Sinclair ZX Spectrum but quickly graduated to the much more capable BBC Micro. This had a powerful Basic — one that I personally think was never bettered on 8-bit machines and even on any 16-bit computers. But the venerable old Beeb also made it easy to try your hand at assembly. You could include 6502 assembly code inside Basic programs, to handle just the bits of the program that needed to go fast.
The Raspberry Pi is widely regarded as the spiritual descendent of the BBC Micro — not least because Eben Upton conceived it that way. It's no coincidence that both machines originally came out in 'A' and 'B' models. And the appeal to the Beeb's heritage is not without justification. Like the Beeb, the Raspberry Pi has encouraged many people — and especially children — to get their coding hands dirty.
However, with its Arm processor and Linux operating system (and yes, I know other OSes are available), the Raspberry Pi doesn't have the same accessibility as the old 8-bit machines.
But 8-bit microcontrollers do. Indeed, my experiences with them vividly brought back my time learning about computers in the early 1980s. And my love of these chips is not without a nostalgic dimension.
Native state
When you're toiling away with the AVR in its native state, without the benefit of the Arduino IDE's abstractions, you find you have to do a lot more work just to enable features you take for granted on the Arduino. And yet, being forced to confront registers, interrupts, timers and other low-level stuff also instils a sense of power and possibility. And in burrowing so deeply into the inner workings of the microprocessor, you learn there's so much more you can do — and that you can often do it a lot faster than you can in the conventional Arduino world, let alone the Linux environment.
And so, in the coming weeks and months, I'll be posting a number of articles on Machina Speculatrix about programming AVR chips, initially in C but we'll also be dipping our toes into AVR assembly. And we'll be learning about technologies such as SPI, I2C, serial communications and more.
You can find all the AVR-related articles here.
I've created a GitHub repo for supporting files to accompany this AVR series of articles. You can find it here: https://github.com/mspeculatrix/AVR_8bit_Basics/
Steve Mansfield-Devine is a freelance writer and photographer. You can find photography portfolio at Zolachrome, buy his books and e-books, or follow him on Bluesky or Mastodon.
You can also buy Steve a coffee. He'd like that.