Sometimes I need to be able to take photographs of very small things, and the so-called macro mode on my point-and-shoot camera just won’t cut it. And it never hurts to have an inspection scope on hand for tiny soldering jobs, either, though I prefer a simple jeweler’s loupe in one eye for most tasks. So I sent just over $40 off to my close friend Alibaba, and a few weeks later was the proud owner of a halfway usable inspection scope that records stills or video to an SD card.
Unfortunately, it’s only halfway useable because of chintzy interface design and a wobbly mount. So I spent an afternoon, took the microscope apart, and got it under microcontroller control, complete with WiFi and a scripting language. Much better! Now I can make microscope time-lapses, but much more importantly I can take blur-free photos without touching the wiggly rig. It was a fun hack, so I thought I’d share. Read on!
In the last two articles on Forth, I’ve ranted about how it’s beautiful but strange, and then gotten you set up on a basic system and blinked some LEDs. And while I’ve pointed you at the multitasker, we haven’t made much real use of it yet. Getting started on a Forth system like this is about half the battle. Working inside the microcontroller is different from compiling for the microcontroller, and figuring out the workflow, how to approach problems, and where the useful resources are isn’t necessarily obvious. Plus, there’s some wonderful features of Mecrisp-Stellaris Forth that you might not notice until you’ve hacked on the system for a while.
Ideally, you’d peek over the shoulder of someone doing their thing, and you’d see some of how they work. That’s the aim of this piece. If you’ve already flashed in our version of Mecrisp-Stellaris-plus-Embello, you’re ready to follow along. If not, go back and do your homework real quick. We’ll still be here when you’re done. A lot of this article will be very specific to the Mecrisp-Stellaris flavor of Forth, but given that it runs on tons of ARM chips out there, this isn’t a bad place to be.
[Dan], admirably rose to the occasion when his son wanted a new toy. Being a dedicated father — and instead of buying something new — he took the opportunity to abscond to his workbench to convert a Wiimote Nunchuck into a fully wireless controller for his son’s old r/c car — itself, gutted and rebuilt some years earlier.
Unpacking the nunchuck and corralling the I2C wires was simply done. From there, he combined a bit of code, an Arduino pro mini, and two 1K Ohm resistors to make use of an Aurel RTX-MID transceiver that had been lying around. Waste not, want not.
A TI Stellaris Launchpad is the smarts of the car itself, in concordance with a TB6612FNG motor controller. The two Solarbotics GM9 motors with some 3D printed gears give the car some much needed gusto.
Let’s start right off with a controversial claim: Forth is the hacker’s programming language. Coding in Forth is a little bit like writing assembly language, interactively, for a strange CPU architecture that doesn’t exist. Forth is a virtual machine, an interpreted command-line, and a compiler all in one. And all of this is simple enough that it’s easily capable of running in a few kilobytes of memory. When your Forth code is right, it reads just like a natural-language sentence but getting there involves a bit of puzzle solving.
Forth is what you’d get if Python slept with Assembly Language: interactive, expressive, and without syntactical baggage, but still very close to the metal. Is it a high-level language or a low-level language? Yes! Or rather, it’s the shortest path from one to the other. You can, and must, peek and poke directly into memory in Forth, but you can also build up a body of higher-level code fast enough that you won’t mind. In my opinion, this combination of live coding and proximity to the hardware makes Forth great for exploring new microcontrollers or working them into your projects. It’s a fun language to write a hardware abstraction layer in. Continue reading “Forth: The Hacker’s Language”→