Your leaking thatched hut during the restoration of a pre-Enlightenment state.


Hello, my name is Judas Gutenberg and this is my blaag (pronounced as you would the vomit noise "hyroop-bleuach").


decay & ruin
Biosphere II
dead malls
Irving housing

got that wrong

appropriate tech
Arduino μcontrollers
Backwoods Home
Fractal antenna

fun social media stuff

(nobody does!)

Like my brownhouse:
   retraining my reward system
Wednesday, April 3 2024
This morning as I was waking up, I could hear the opening track of Beyoncé's new album, Cowboy Carter, playing from Gretchen's phone. It was an interesting song with a wild mix of influences, though I don't know if I was in the best state to be hearing it.

It rained all day, bottling me up in the house. But I had a project to work on, so it didn't much matter. For the past few days after being dismayed by my excessive drinking last weekend, I've been penalizing myself by only allowing myself to take caffeine as a drug. This means no kratom, no diphenhydramine, no cannabis, and, most importantly, no alcohol. I feel like I need to retrain my reward system to find more pleasure in activities and not to so impatiently expect the quick and easy reward of substances. With that in mind, today I hoped to add an important feature to the remote control system I've been working on. For starters, I wanted to write some code to turn any Arduino into a generic I2C slave. I've written code in the past to make Arduinos behave as I2C and even serial slaves, starting with my solar controller and continuing with my Raspberry-Pi-based weather station. But that code tended not to be generic enough for the application I wanted to use it for, which was to add digital pins to the NodeMCU serving as the remote control controller up at the cabin. I wanted to be able to turn any Arduino into what is essentially an I2C-based port expander.
First, though, I had to find an appropriate cheap Arduino to use as a slave. After looking through my substantial collection of tiny microcontroller boards, I decided the perfect Arduino for this was an Arduino Pro Mini. These cheap, tiny boards come with little more than a surface-mount Atmega328, a crystal, a reset button, and a place to solder on pin headers. Importantly, they lack a USB connector and so must be programmed with a serial adapter plugged into the Rx and Tx pins. But I figured once I had the code right, it would just be a module for me to use and there would be no need for a USB connection.
After some tinkering and trial and error, I managed to get code to flash to the Mini. Better still, the Arduino IDE I was using (version 1.8.16) seemed to preserve separate settings for both the serial port and the board type in separate windows. This allowed me to work on master-side code in one window, flash it to the NodeMCU, and then work on the slave-side code and flash it to the Mini without having to explicitly change the settings back and forth (something I seem to remember having to do in the past).
Before too long, I had code that would allow me to set any controllable pins on the slave to whatever values I wanted from the master. This included setting them to analog values on the pins that support PWM. Once I had that working, I decided that an even more useful slave would be able to have its controllable pins turned into inputs, and I added a feature allowing me to read electronic values from any pins on the slave from the master. This included analog values from pins that supported it. By the end of the day, I had exactly the code I'd wanted to write, and it was only about 100 lines long.

Towards the end of the afternoon, I made a cup of rice in the rice cooker without any real idea of what to make with it. So when Gretchen got home, she cooked up a slurry of kale, tomatoes, and crumbled tofu and added a can of Goya-brand black bean soup. It made for a surprisingly good stew to be poured over rice. Unfortunately, though, a single cup of rice wasn't quite enough.

For linking purposes this article's URL is:

previous | next