Wet Soil: Starting with Microcontrollers

Published: 2020-06-06
Tagged: essay hacking

Sometime in March, two or three weeks into the pandemic, I ordered an Arduino starter kit. When it arrived a few days later, I found it full of colorful little parts and cables. The flimsy, bulging plastic box presented itself to me the same way an empty page does to an author or a lump of clay to a sculptor. I became intoxicated on the promise of unrealized potential.

But I had no idea how to start. In the kit, there was a small card with a website address. I clicked around there and found a zip file with tutorials, but my luck ran out on the next step: installing the IDE. The Ubuntu repositories contained an older version without useful features such as a built-in Arduino package manager. A newer one was available through flatpack. But this was a dead end too. Flatpack has security features that, even after 30 minutes of furious fiddling, "secured" the IDE from talking with the Arduino through USB. In the end, I downloaded the tarball from the official Arduino website. This challenge prepared me for the next one: the tutorials. They were confusing, as if written and rewritten by multiple people. One sentence expressed excitement while the next was as dry as old newspapers. Some fragments didn't make sense at all. Thankfully, the example C code and schematics were enough to figure out what do and what to expect. The tiny computer, working hard over a few days, blinked LEDs, displayed digits, and read sensor outputs. Each time something worked like it was supposed to, or whenever a problem yielded to debugging, my brain rewarded me with happy chemicals. This was merely a warm-up though.

Microcontrollers marry the virtual with the physical. It's this that makes them exciting. Normally, in software, you're pushing around bits and bytes to solve a problem with the flow of information. But with a handful of electronic components and a chip, you can read sensors, move motors, make sounds, pump water, send notifications, power lights, and display images. And it all behaves like code! It's logical, deterministic, and really a bunch of ready-to-use parts. You type up a few bits of code that glue everything together and trickle some power into it and watch the gizmo come alive!

The first serious project I undertook was to build a little gadget to measure the soil moisture of a plant and the temperature and relative humidity of the air around it. To actually b e useful, it had to present the readings to the operators: my wife and me. The kit I bought included a small screen that I could use for that purpose. That's great and all, but if I was going to be serious then I had to collect this data for ongoing analysis of what makes the plant optimally happy. The unexamined life isn't worth living, right? The plant was located near a Raspberry Pi 3B+ that was tasked with measuring the uptime of my blog. It pinged it and stored the results in a timeseries database. Coincidence? After reading about UART, I cooked up a few lines of Go that periodically read incoming data from the RPi's serial port and wrote it to the database. Currently, I have almost a month's worth of soil moisture, temperature, and relative humidity data to ponder.

Arduino setup: sensors and RPi3 connection The project: a soil moisture sensor and a temperature/humidity sensor connected to an arduino, itself connect to the RPi3B+ via UART

Slowly, I realized that building small gizmos like this is pleasant. Relaxing, even. Years of programming, using Linux, and lots (lots!) of debugging insulate me from frustration. Figuring out most problems takes a few minutes in these simple projects. For example, uploading a new program to the Arduino results in an error. Something about the serial connection. What changed since the last time? I hooked it up to the Raspberry Pi using UART. That's a type of serial connection. Maybe two serial connections confuse the Arduino's circuits? An educated guess: let's unhook the UART wires... yep, that worked, problem solved. Following this process until you get a working device is very calming. In fact, on certain evenings I put on some music and have at it until I wash away the troubles of the day.

My tinkering quickly exhausted the possibilities of the kit, but eBay offers an amazing variety of parts at low prices. Warehouses from all over the country have been pushing small envelopes of sensors, screens, and basic components into the postal system, which later pops them out on my doorstep. When I rip them open and peer inside at the itty-bitty parts, I see a challenge: what are you gonna build next?

Comments

There aren't any comments here.

Add new comment

A code cave is a series of null bytes in a process's memory.

Programming, exploring, tinkering, philosophizing.

All views expressed are my own.