The Pin Dance

Don’t get me wrong, I love Circuit Python. Sure, I could get stuff done in the ugly stepchild language that is Arduino, but the niggling details, the mediocre IDE, none of it was my friend. And truth to tell, it’s not often I need the full speed of even an ATTiny.


Lately this has been my board of choice. Cheap and powerful. But all those little colored blocks mean something

CircuitPython, in its quest for ease of use, sometimes does drive me completely around the bend. Particularly about the lengths its developers go to in avoiding interrupts. They’re right: interrupts are inelegant, interrupt code breaks way too easily, writing it just leaves you with a different set of problems, etcetera. I know that. And in theory I admire the tools they’ve developed to make interrupt routines unnecessary: countio, which right now just counts falling edges on a pin but soon will do all the things regular digital inputs do; pulseio, which gives you a Wow! bleeping list of the on and off times of the pins you’re watching. And the keyboard functions that tell you what switches you’ve got pressed. That’s almost all of what you might sensibly want interrupts for when you’re programming in an interpreted language.

Except. The gotchas. For example, pulseio counts in microseconds and only handles unsigned two-bye integers. So if whatever you’re watching go on and off does it slower than 16 times a second, that’s too darn bad.

Or the RP2040 and its PWM channels. For reasons that are no doubt obvious to the developers, you can only make countio objects on pins assigned to PWM port B. There are 8 of them, so that really shouldn’t be a problem, but wait. Ports A and B (as far as I’ve been able to figure out) share timer channels 0-7. So if you have a counter object on a pin that talks to timer channel 3 (on port B, natch), then woe unto you if you try to make some other PWM object (motor driver, servo control, tone out, dimmable LED, whatever) attached to the pin that talks to timer channel 3 on port A.

You can either make a matrix and cross out the pins you can’t use as you start assigning counter objects and PWM outputs, or you can just pick a number, see if an error message comes back and pick again. Or (if I were building new widgets on a slightly more frequent basis) it might even be worthwhile to create a tool where you tell it what inputs and outputs you need, and it hands back a list of plausible pin assignments. (Did I mention that my eyes are getting old and I really don’t like changing wires from one pin to another once I’ve got them set…)

It’s not a big deal, really, and mostly the problem is expectations. Python is supposed to be a language about orthogonality and abundance, not this-operation-only-uses-that-resource. If it were Arduino coding, I wouldn’t be surprised by arcane restrictions, but now I’m spoiled, and it’s hard to go backward.

(Ok, one latest debacle finally got me to post this). And then there’s my other favorite board, the Cytron Maker Pi 2040, which has a motor driver and servo drivers and a bunch of cute connectors. And no complete listing of what all the pins do. There’s a fuzzy silkscreen on the back for some of the pins, and a better silkscreen on the front that at least tells you what GPIO each special-purpose pin is connected to. Then you can either check table 1.4.3 in the Raspberry Pi datasheet, or consult the pictures of Raspberry Pi Pico board that tell you which functions go with which GPIO. Not sure which is more cumbersome.

Posted in possibly useful, probably boring, things that don't work | Tagged , | Leave a comment

In praise of cattle

The 16-year-old, who wants a career somewhere in IT, introduced me a while back to the distinction between pets and cattle. When something goes wrong with your pet, you nurse it back to health. When something goes wrong with one of your herd, you segregate it from the rest, hand the problem off to someone else (maybe future you) and get back to your work.

In the past few years, the tiny school I work at has gotten a couple of substantial donations from offices that were ditching their old desktop PCs. When all those machines came in, I wondered briefly whether there were more than we really needed. Then came the pandemic, with assigned desks (no moving between classrooms) assigned computers for each student (sanitized between uses), and ethernet drops to every seat. Suddenly too many machines was just barely enough.

This year, things are a bit better (we even finally got fiber to replace our DSL), and I’ve been concentrating on rational management of all our computers using FOG to put identical images on every PC — with accounts for every student, since any kid or teach might use any machine at any given time. Having “too many” machines has saved me repeatedly.

One of the little lunchbox units told me all its settings were gone — a sign that its little coin cell had finally died — and I didn’t have to spend an hour disassembling the damn thing (the manual says to take off the processor fan ducting and heat sink to make room for access to the battery holder, but if you’re in a hurry, you can reach underneath with a flat-bladed screwdriver to pop the battery out and then turn the machine upsidedown and shake it. Then winkle the replacement battery in with insulated tweezers). I just put it aside with another couple units that need new batteries and swapped in a working machine.

Same thing when a couple other boxes developed finicky network controllers — they performed fine once booted, but wouldn’t download a new boot image because the controller insisted there was no ethernet cable plugged in. Not interested in diagnosing that one, just swapped them out for other boxes of exactly the same model and vintage that worked. (And maybe we can pass the prima donnas on to someone who doesn’t have a dozen-odd identical machines to manage.)

Meanwhile the weekend before I spent a couple hours disassembling my personal laptop and going after the fan and heat exchanger with Q tips and forced air. It’s a pet.

And yet another note of thanks to National Life and The Vermont Family Network.

Posted in probably boring | Tagged | Leave a comment

Pedal Assist: Not What I Thought It Was

It’s been a few years since I started wanting an e-bike, but for a long time I was put off by physics. We live at the top of a steep hill, and I’m fat and out of shape. So all those sprightly 250-watt bikes and front-wheel kits simply weren’t going to cut it.

This spring, I saw someone in the neighborhood on a Radpower utility bike (750 watts) and asked them if it could go up our hill. They said it could. And what the heck, 14-day free return policy.

So I ordered, waited a few months for delivery (while enduring a constant stream of email trying to get me to buy one of their other bikes) and ended up with this:

RadRunner Plus

750 watts, 5 levels of pedal assist plus throttle, 300 pounds of payload, front and rear hydraulic brakes.

The throttle part is easy: you turn it and the bike goes. I’ve started using it to get going, because 70 pounds of bike is hard to start moving, especially when the pedal assist doesn’t kick in for those crucial first few seconds.

Pedal assist isn’t what I thought it would be — which may be a good thing. I have a frightening annual bill from Adafruit, so of course I’d imagined some complicated system with strain gauges and accelerometers (and probably a 3-axis gyroscope for good measure) that would sense just how fast and how hard I was pedaling, and then dole out a precisely calibrated extra kick to deliver just the right enhanced riding experience.

Nuh-uh. That would be the automatic transmission version. What this bike has, as far as I can tell, is much simpler: When the pedals are moving (well, a couple seconds after they start until a couple seconds after they stop) the motor is on. It delivers whatever level of assist you’ve chosen with the arrow buttons on the handlebar, from about 35 watts at level 1 to about 740 watts at level 5. The engineering for that is much less baroque.

(The simple engineering also means that the amount of assist will depend on your battery level — expect about 100 watts less of assist at the top end when your battery is just about done. Oh, and the battery-level meter will report based on how much assist you’re using: level 1 typically shows a bar or two more than level 5.)

I’m getting used to it. The lowest level is like regular bicycling, only as if I were young and in shape.

The higher levels are sort of like a pushbutton alternative to regular gears, at least around where I live. On a conventional bike, for this rider, going up a slope means downshifting until the bike is moving at a fast walking pace while I pedal madly until I reach the top or run out of breath and have to walk the bike up. On the Radrunner, going up a slope means kicking the pedal assist up a notch, maybe two. If it’s a serious slope, I can downshift a gear or two and slow down while the electric motor continues to do its thing. I still have to work, but it’s not a losing battle. The top level of assist even gets me up the hill by our house — the one that neighbors without 4WD sometimes park at the bottom of in the winter

The pedaling part of pedal assist is still a bit new for me — if I’m zipping along on the flat and the bike seems to be freewheeling, it feels natural to stop pedaling, as you would on a conventional bike. But when I do, two seconds later the electrics kick out, and the whole thing sags down the behemoth it is. So I have to learn to keep my legs lazily moving.

And although I’d expected electrical assistance to make the physical job of riding a bike easier, the psychological effect may turn out almost as important. I can ride anywhere in my small town (or maybe even to the next village over) without worrying about whether I’ll have enough endurance to ride back. I can also ride on roads without worrying about being mowed down by even the slowest-moving cars. Now, if I can just figure out how to keep riding during the winter…

A few other things I’ve learned:

  1. It’s also loud. Not so loud that people can hear you coming, but between the motor and the fat tires loud enough that the conventional cycling experience of being able to hear nothing but the wind in your hair is gone.
  2. Unless you work at going slowly, you will go faster than you would on an unassisted bike. No real surprise there, but old intuitions about overtaking pedestrians and other bikes have to be adjusted. (Oh, and kudos for the built-in bell).
  3. This bike doesn’t really like to turn sharply. Which mostly isn’t a problem.
  4. There’s a lot of space between the frame and the interior of the front wheel (and rear wheel too. You will need a bigger bike lock.
  5. Say goodbye to range anxiety. No, the battery has a limited capacity, but unless you’re way fitter than I am, that capacity is likely greater than yours. I always had to gauge rides on a conventional bike by whether I would be able to ride back after riding out, but pedal assist and throttle. (20km and 135 meters of climb are less than 40% of battery — a real cyclist on a serious ride would laugh at that, but a real cyclist on a serious ride is not who the Radpower utility models are aimed at.)
  6. Check your tire pressure. Those armored exteriors are stiff, and will defeat your conventional-tire intuition about squeezing a tire to see if it needs air. The difference in rolling resistance between underinflated and properly is about one gear or one level of pedal assist.

Posted in going places, possibly useful | Tagged | Leave a comment

Osmotic Bubbles

Who knew? Our fancy toilet has been leaking for a while, and at long last I decided to do something about it. Which involved disassembling a bunch of toilet-body parts (remember, fancy), turning off the water and extracting the flush mechanism.

At the bottom of which was a silicone gasket covered in little blisters. After suitable searches and an order for a replacement part, I stumbled across a review by someone who had had a similarly disfigured gasket (and blamed it for their leaks).

Down to my spouse’s sewing supplies for a pin, which I used to puncture every blister and squeeze out the water. More gymnastics getting the flush valve back in and reassembling everything (pro tip: cats should not be allowed to help). Then back to the search engines: why should an ostensibly waterproof gasket develop pockets full of water, even after 15 years of submersion?

Turns out that if there are water-soluble compounds inside an insoluble material that is even infinitesimally permeable, osmotic pressure over the years will force in enough water to dilute the soluble material and open up tiny bubbles. Chemistry!

So why are there water-soluble compounds inside my silicone gasket? Some kind of weird manufacturing flaw? Only sort of. The page I landed on about osmotic bubbles called out soluble metal salts in particular. Anyone remember what silicone uses to catalyze curing? Got in in one. Tin, Platinum, Bismuth… So unless the manufacturer is really careful (and thrifty) there will always be a little bit of excess soluble stuff inside the finished product.

There is one alternative explanation that scares me a bit, though: apparently thermal gradients can also drive water into semi-permeable materials. So maybe every time we might have sorta kinda let the water freeze inside the outside-wall supply lines we were creating a gradient that has now done the terrible damage of costing me $8 every 15 years for a new flapper gasket.

Posted in probably boring | Leave a comment

Thank you, Electronics Goldmine

I admit it, I have an addiction to things that call themselves bargains. Down in the basement are multiple cubic feet of random electronic and mechanical components that looked like a good idea or might be useful someday or just seemed like too good a deal to pass up. 25 Magnets with holes in them. 100 trim pots that almost fit breadboard spacing. 500 sets of 3 green LED in some kind of indicator mounting…

Some of these things I have found a use for, like the hall-effect sensors or the optical interrupters. Others I probably never will, like the 20-watt 10-ohm resistors. But last week my addiction did me proud.

After about 15 years of use, the good kitchen thermometer stopped working. You know, the kind where you poke the tiny tip into meat or bread or sugar syrup and get an instant, accurate reading. The kind that takes a weird battery size that no one used to stock. It just didn’t work any more. Didn’t turn on, even with a fresh battery.

So what the heck, I pulled off the stickers over the screws and opened it up, and found that it occasionally did work when you pushed on the body just right. There’s a sweet cam-and-microswitch arrangement that turns the thermometer on when you rotate the probe away from the body. Oh, and the microswitch had green corrosion coming out of its case. Hmm.

Yep, when I shorted the contacts, the thermometer turned on just fine. But how to repair or replace the switch?

Oh, wait. A tray of 100 of the smallest microswitches you ever saw for $5. So tempting that I forgot about the first tray I bought and got another one a year later. And be careful opening it up, or they go everywhere. Clipped the leads on the old, dead switch so they stood up from the circuit board. Butted the leads on a microswitch against those. Soldered, bent the switch actuator out a bit to meet the cam. Done.

Every now and then all that crap in the basement comes in handy. And if this switch corrodes, I’ve got another 190 where it came from…

Posted in possibly useful, probably boring | Leave a comment

Ok, this is actually useful

And it only took me 9 years to notice. It’s an openscad script for making keyboard feet. Thank you.

Not such a big deal at home, but at a school with donated computers of interesting provenance and a couple dozen energetic kids this might turn out to be really useful. After I get enough different measurements for various keyboard models, I might even post a revision where you just tell the script which keyboard you have and it sets all the dimensions.

Posted in possibly useful | Tagged , , | Leave a comment

Possibly the creepiest Christmas ornament of 2020

Zapped on my glowforge, slightly modified from a design by IconPai at the Noun Project.

Every year I take the bottom however many inches have to come off our tree to make it fit the living room ceiling and slice some disks on the miter saw.  Then I zap them into ornaments.  The wood is green as it gets,  so the ornaments usually warp all to heck and get tossed with the tree,  but it’s fun while it lasts.

This one might be a little too Masque of the Red Death tho.

Posted in Uncategorized | Tagged , | Leave a comment

Something actually useful

Our dishwasher is getting to be a certain age. And the plastic parts are showing it. Especially after one of the youth tripped over a cat and onto the bottom rack. When the wheels fall off they have a really unpleasant tendency to lodge against the heating element and melt/char. It stinks up the whole interior.

pegSo I fired up Openscad and my cheap plastic vernier calipers. First, a peg to hold the remaining wheels in place after the old pegs failed. I am kinda proud of the divot that lets the peg bend inwards, because it’s straightforward openscad code (possibly even amenable to turning into a module) rather than something with polygons (I hate polygons). Less proud of the overhang at the top of the peg, which would have been steeper. But with the cheap plastic calipers I wasn’t really sure of my measurement.


For the wheel, I just combined measurements of the existing wheel with the peg design, and presto! The result is a one-piece part that probably would have been hard for the manufacturer to injection-mold cheaply. carousel_dwinplace Speaking of cheaply, the cost estimator on my octoprint installation figured the price of 4 pegs — made out of recycled PETG from the late, semi-lamented Makergeeks — as something like 48 cents. Even factoring in the 20 minutes of design time, I think I may have beaten the $36.98 for an OEM replacement (you can only buy the whole carriage) online.

(And if your dishwasher is suffering similarly, you can check the files at Youmagine.)

Posted in possibly useful | Tagged , | Leave a comment

Posted without comment

No, that’s not a trick of perspective
Posted in things that don't work, Uncategorized | Leave a comment

Failing to fail

I’ve been working on and off with Blinkinlabs’ BlinkyTape and pixels, which means also with their nice little app PatternPaint, which lets you create little light shows to download to their LED strands without all the annoying number-fiddling that is LED images on Arduino.

But when you have an LED strip with controller built in you have a few obvious potential problems. First, each of those LEDs can draw up to 50 milliamps when cranked up full, so about 3 amps for a 60-chip tape. Put the wrong pattern on there, and good luck talking to the controller chip over a standard USB port while it’s trying to draw all that current. Second, you need a really reliable USB protocol that can handle transmitting and receiving data while the microcontroller is running flat out handling the pretty blinky part. Third, some computers’ USB drivers and hardware are rock solid, others (many macs, for instance) are garbage.

So start by splicing extra power connectors onto the back of the blinky tape (extra points for avoiding ground loops) . Then find out that the usb connection still works only a few percent of the time, for various reasons including serial-driver bugs in the version of the Qt framework it’s built with. Here’s where it gets interesting, in the sense of the curse:

The latest version of PatternPaint is supposed to have improvements to the USB stack, including a fixed serial driver and a protocol that is more willing to retry when things go wrong. But the appImage of that latest release segfaults when run on all of the machines I have access to.

Yes, you read that right. The format that’s supposed to have all the bits and pieces its app depends on nicely built in to a custom file system leads to an executable that segfaults. (But not on all machines, because it wouldn’t have passed its release testing.) So it turns out that appimages do rely on a bunch of libraries in the underlying operating system, and in the couple of years since PatternPaint was actively under development some of those libraries have gone away or moved or been altered in some incompatible way.

So it’s time to start building from source. Download a current version of Qt and fire up the compilation script. No luck. Apparently the dependencies on a previous version were real. (or not, as we will later see) The version specified by the Blinkinlabs instructions isn’t even on the list of recently-obsolete versions you can download, but it is in the Qt archives.

Still no luck. But a few searches on the error messages tell me that some libraries that used to be present by default in Debian/Ubuntu are no longer present in recent versions, hence also not in the debian-derived BunsenLabs OS that I’m using here (because it’s what we’ve got at the school where I hope to deploy this insanity at some point.) Download the right version of mesa-dev and jasper, and try again. Still a failure. Turns out I’m supposed to have installed linuxdeployqt in the same directory as I’m compiling from.

So now everything chugs through endless pages of messages, and success is announced! I even get the request to post my appimage so that everyone else can use it. But no. right after that there’s an error message that tar cannot stat something for some reason and the whole process has failed. And the only way to figure it out is to start digging into the guts of the linuxdeployqt appimage or its source.

I’m about to declare defeat — or at least post an issue — when I decide to look into the build directory and see if I can at least figure out what tar was trying to package up. There’s a PattenrPaint.blah.blah.tar that’s empty — sad! — and there’s a file called PatternPaint.2.4.1.blahblah.appimage.

What the heck. Yes, I click on it and it’s a perfectly good appimage. Doesn’t segfault, brings up the splash screen. Talks to blinkytape on machines where the previous version wouldn’t. I have what I need, I just have this really uncomfortable feeling that that final error message is really supposed to mean something and I should find out what.

Posted in probably boring, things that don't work | Tagged , , | Leave a comment