<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="/feeds.xsl" type="text/xsl"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:base="https://chameth.com/">
    <title>Chameth.com - posts like building-a-new-computer, debugging-beyond-the-debugger, further-adventures-in-3d-printing</title>
    <subtitle>Personal homepage of Chris Smith</subtitle>
    <link href="https://chameth.com/feeds/posts/like/building-a-new-computer,debugging-beyond-the-debugger,further-adventures-in-3d-printing/" rel="self"/>
    <link href="https://chameth.com/"/>
    <icon>https://chameth.com/favicon.png</icon>
    <updated>2025-07-30T00:00:00Z</updated>
    <id>https://chameth.com/</id>
    <author>
        <name>Chris Smith</name>
    </author>
    <entry>
        <title>Fixing a loud PSU fan without dying</title>
        <link href="https://chameth.com/fixing-a-loud-psu-fan-without-dying/"/>
        <updated>2025-07-30T00:00:00Z</updated>
        <id>https://chameth.com/fixing-a-loud-psu-fan-without-dying/</id>
        <content xml:lang="en" type="html">&lt;p&gt;Three months after I &lt;a href=&#34;https://chameth.com/building-a-new-computer/&#34;&gt;built my new computer&lt;/a&gt;, it
started annoying me. There would occasionally be a noise that sounded like
a fan was catching on a cable, but there weren’t any loose cables to be a
problem. Over the course of a few weeks, the sound got progressively worse
to the extent that I didn’t want to use the computer without headphones on.
I measured the sound at 63 dB, which is about the sound of someone talking.
That may not sound terrible, but it’s a constant, nasty noise coming from
something that sits about 40cm from my head.&lt;/p&gt;
&lt;p&gt;After some investigating&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a class=&#34;footnote-ref&#34; href=&#34;#fn:1&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;, I identified the PSU fan as the culprit. I have
a Cooler Master V750 SFX, which is not super high-end, but wasn’t cheap, either.
It shouldn’t be developing issues after three months. Thankfully, it comes with
a ten-year warranty, so it should be easy to get sorted, right?&lt;/p&gt;
&lt;h3 id=&#34;warranty-woes&#34;&gt;Warranty woes&lt;/h3&gt;
&lt;p&gt;I looked at Cooler Master’s warranty, and for issues within the first two years
you have to deal with the retailer. That would be Amazon in my case. So I looked
at Amazon’s information on warranty issues. Their policy is that if it’s more
than 30 days since purchase, you have to send it off to a third-party repair
center and wait for them to diagnose and try to repair it. Here’s the kicker:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Usually repairs take up to 20 business days (including delivery time), but
could take slightly longer&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I use the computer for work, have upcoming LAN parties to go to, and generally
can’t do without it for an entire month. That’s assuming they reproduce
the issue: the PSU fan only turns on when it reaches a certain temperature,
so if you just plug it in briefly it won’t exhibit any symptoms.&lt;/p&gt;
&lt;!--more--&gt;
&lt;p&gt;If I was going to do a warranty return, I’d need to buy a new PSU first to
use while this one was away. If I’m spending £100+ on a PSU, then I’d be getting
a better one that doesn’t have known issues with the fans. So when the Cooler
Master eventually got returned I’d have no use for it. What a waste.&lt;/p&gt;
&lt;p&gt;So the warranty is about as much use as a chocolate teapot. Good to know, I
guess. If I wanted decent service, I should have probably used a real retailer,
not Amazon. Lesson learnt.&lt;/p&gt;
&lt;h3 id=&#34;doing-some-research&#34;&gt;Doing some research&lt;/h3&gt;
&lt;p&gt;If the warranty is useless to me, maybe I should just void it and try to fix it
myself. I did some research online. Most of the results went like this:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;if you’re not a trained professional you should not be opening up your PSU
at all. There’s a lot of current that goes through it which will seriously
hurt/main/kill you&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;or&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;it’s time consuming and potentially dangerous&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;or some other variety of doom and gloom. There were some actually useful results
sprinkled in, though. &lt;a href=&#34;https://smallformfactor.net/forum/threads/cooler-master-v850-sfx-psu-fan-swap.17294/&#34;&gt;A post on the smallformfactor.net forums&lt;/a&gt;
details someone swapping out the fan on the 850W version of the same power
supply because it was too noisy. It looks like the fan connector in the PSU
is a two-pin connector, and they just used an off-the-shelf adapter to convert
the standard four-pin case fan connector. It sounded a bit annoying to make
it all fit, though.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://old.reddit.com/r/sffpc/comments/1h97sz6/cooler_master_v850_sfx_noctua_fan_swap/&#34;&gt;A similar post on reddit&lt;/a&gt;
showed basically the same upgrade, but identified the connector as a 2.54mm
JST-XH. They crimped their own connector on, which feels a lot better than
using a bulky connector. I do have a crimping set for JST connectors, but I
absolutely hate doing them because they’re so fiddly and annoying. I’m not sure
if I trust one of my crimps inside a power supply, either.&lt;/p&gt;
&lt;p&gt;Looking at the pictures in those posts, I identified the fan as an Ong Hua
&lt;code&gt;HA9215VH12FD-F00&lt;/code&gt;. I searched to see if I could see any specifications for it.
I couldn’t. But what I did get back as my first result was another Reddit post,
this one titled &lt;a href=&#34;https://old.reddit.com/r/sffpc/comments/1b4j6vr/getting_rid_of_a_ha9215sh12fdf00_fan_from_your_psu/&#34;&gt;“Getting rid of a HA9215SH12FD-F00 fan from your PSU”&lt;/a&gt;.
It says something about the quality of a component when the first result
is a post about getting rid of it because it’s annoying&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a class=&#34;footnote-ref&#34; href=&#34;#fn:2&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;
&lt;p&gt;All of these mods seemed easy enough, and I’m reasonably confident in my ability
to both discharge and avoid touching capacitors, so I probably wouldn’t die.
I ordered a Noctua NF-A9x14 fan and some pre-made JST-XH connectors and waited
for them to arrive.&lt;/p&gt;
&lt;h3 id=&#34;upgrade-time&#34;&gt;Upgrade time&lt;/h3&gt;
&lt;aside class=&#34;warning&#34;&gt;
  &lt;div&gt;
    &lt;h5&gt;Warning&lt;/h5&gt;
    &lt;p&gt;Like the Reddit keyboard warriors said, the stuff inside PSUs is dangerous.
Try not to kill yourself or release the magic smoke if you do this.
I’m not taking responsibility for your actions!&lt;/p&gt;
  &lt;/div&gt;
&lt;/aside&gt;
&lt;p&gt;The replacement parts arrived one evening, so when I turned the computer off
for the night I unplugged it from the mains, held the power button down for
a while, and left it overnight for good measure. The next morning I popped
open the case, disconnected and removed the PSU, gleefully tore the
“warranty void if removed” sticker off, and opened it up.&lt;/p&gt;
&lt;p&gt;Removing the fan was simple: unplug the JST connector and undo the screws
holding it to the outer panel. I confirmed that my JST connectors were the
right size, then started surgery on the Noctua fan. I carefully removed the
heatshrink, cut off the normal fan connector, and separated out the four wires.
A quick check of their &lt;a href=&#34;https://faqs.noctua.at/en/support/solutions/articles/101000081757-what-pin-configuration-do-noctua-fans-use-&#34;&gt;FAQ&lt;/a&gt;
confirmed the wiring colours: black was ground, yellow +12V, and blue and
green used for speed control (which we’re not using in this instance). I clipped
the blue and green wires off near the hub so they wouldn’t be in the way, then
cut the yellow and black wires down to length, and attached the JST connector
with a solder seal:&lt;/p&gt;
&lt;figure class=&#34;image full&#34;&gt;
  &lt;picture&gt;
      &lt;source srcset=&#34;https://chameth.com/fixing-a-loud-psu-fan-without-dying/fans.avif&#34; type=&#34;image/avif&#34;/&gt;
      &lt;source srcset=&#34;https://chameth.com/fixing-a-loud-psu-fan-without-dying/fans.webp&#34; type=&#34;image/webp&#34;/&gt;
      &lt;img src=&#34;https://chameth.com/fixing-a-loud-psu-fan-without-dying/fans.jpg&#34; alt=&#34;Two fans side by side on a mouse mat: a black fan with a short power connector, and a beige-and-brown fan with transparent solder seals over the joins in its power connector. The mouse mat has a shiny patch near the solder seals.&#34; loading=&#34;lazy&#34; width=&#34;1600&#34; height=&#34;887&#34;/&gt;
  &lt;/picture&gt;
  &lt;figcaption&gt;&lt;p&gt;Old fan, new fan, burnt mouse mat&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;In the process I discovered my mouse mat doesn’t like being hit with a heat gun.
Whoops. The solder seals are great: the solder in the center melts to form an
electrical connection, the parts at the end grip the cable to provide mechanical
strength, and the whole thing acts like heatshrink and keeps the connection
insulated. A lot less fiddly than crimping JST connectors, and a lot smaller
and cheaper than an adapter.&lt;/p&gt;
&lt;p&gt;I installed the fan and reassembled the PSU. Then undid it all and tried again,
as apparently the face the fan mounts to isn’t quite symmetrical and I’d
installed the fan upside down. Connected everything back up, plugged the
computer in, booted it up, and… nothing. The PSU doesn’t actually power the fan
until it hits a certain temperature. I figured putting it under load would
probably heat it up, so ran a graphics benchmark a few times. Eventually the
fan spun up. Huzzah.&lt;/p&gt;
&lt;figure class=&#34;image full&#34;&gt;
  &lt;picture&gt;
      &lt;source srcset=&#34;https://chameth.com/fixing-a-loud-psu-fan-without-dying/installed.avif&#34; type=&#34;image/avif&#34;/&gt;
      &lt;source srcset=&#34;https://chameth.com/fixing-a-loud-psu-fan-without-dying/installed.webp&#34; type=&#34;image/webp&#34;/&gt;
      &lt;img src=&#34;https://chameth.com/fixing-a-loud-psu-fan-without-dying/installed.jpg&#34; alt=&#34;Computer with the side panel removed, with a Noctua fan visibly spinning inside the PSU, next to another Noctua fan spinning above the CPU.&#34; loading=&#34;lazy&#34; width=&#34;1280&#34; height=&#34;720&#34;/&gt;
  &lt;/picture&gt;
  &lt;figcaption&gt;&lt;p&gt;Soon the entire computer will be beige and brown&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h3 id=&#34;peace-at-last&#34;&gt;Peace at last&lt;/h3&gt;
&lt;p&gt;I measured the sound of the new fan: 43 dB. That’s a decrease of 20 dB. Due
to the weird logarithmic properties of the dB scale that no one understands,
that means it sounds about 4 times quieter to human ears. Big improvement!&lt;/p&gt;
&lt;p&gt;It’s worth pointing out this isn’t a straight one-to-one upgrade. I don’t know
the specs of the old fan in terms of airflow, and I’m just assuming that the
Noctua will be good enough by virtue of being a decent fan. They also behave
slightly differently as the power ramps up: the stock fan starts spinning
at a lower voltage than the Noctua, which needs around 7V to get started
properly&lt;sup id=&#34;fnref:3&#34;&gt;&lt;a class=&#34;footnote-ref&#34; href=&#34;#fn:3&#34; role=&#34;doc-noteref&#34;&gt;3&lt;/a&gt;&lt;/sup&gt;. I don’t think this will be an issue, as it’s effectively just
putting a small step at the lower end of the fan curve. It might shorten the
overall lifespan of the PSU, but from my point of view it failed after four
months, so any extra time is a bonus.&lt;/p&gt;
&lt;p&gt;I recorded some before/after audio, so you can hear the difference. I think
there’s some amount of volume normalisation going on, so it’s not quite as
stark a difference as in person, but it’s still noticeable.&lt;/p&gt;
&lt;figure class=&#34;full&#34;&gt;
  &lt;audio src=&#34;https://chameth.com/fixing-a-loud-psu-fan-without-dying/before.mp3&#34; alt=&#34;Audio sample from the old fan&#34; controls=&#34;&#34;&gt;&lt;/audio&gt;
  &lt;figcaption&gt;Audio sample from the old fan&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;figure class=&#34;full&#34;&gt;
  &lt;audio src=&#34;https://chameth.com/fixing-a-loud-psu-fan-without-dying/after.mp3&#34; alt=&#34;Audio sample from the new fan&#34; controls=&#34;&#34;&gt;&lt;/audio&gt;
  &lt;figcaption&gt;Audio sample from the new fan&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;And if you couldn’t hear it, here’s a visual representation:&lt;/p&gt;
&lt;figure class=&#34;image full&#34;&gt;
  &lt;picture&gt;
      &lt;source srcset=&#34;https://chameth.com/fixing-a-loud-psu-fan-without-dying/comparison.avif&#34; type=&#34;image/avif&#34;/&gt;
      &lt;source srcset=&#34;https://chameth.com/fixing-a-loud-psu-fan-without-dying/comparison.webp&#34; type=&#34;image/webp&#34;/&gt;
      &lt;img src=&#34;https://chameth.com/fixing-a-loud-psu-fan-without-dying/comparison.png&#34; alt=&#34;Side-by-side comparison of the audio spectrum of the old fan and the new fan. The old fan makes a reasonable amount of noise across a lot of frequencies, the new one is concentrated at very low frequencies.&#34; loading=&#34;lazy&#34; width=&#34;1467&#34; height=&#34;728&#34;/&gt;
  &lt;/picture&gt;
  &lt;figcaption&gt;&lt;p&gt;Side-by-side comparison of the audio clips&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;The whole upgrade took about an hour (less time than writing this post about
it!), and I even managed to avoid killing myself.&lt;/p&gt;
&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr/&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34;&gt;
&lt;p&gt;Opening the case and sticking my ear near to various components. High-tech
stuff. &lt;a class=&#34;footnote-backref&#34; href=&#34;#fnref:1&#34; role=&#34;doc-backlink&#34;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34;&gt;
&lt;p&gt;On closer inspection it’s actually a slightly different model — there’s
an &lt;code&gt;S&lt;/code&gt; not a &lt;code&gt;V&lt;/code&gt; in the middle there — but I’m going to assume that doesn’t
change much on the quality/noise front. &lt;a class=&#34;footnote-backref&#34; href=&#34;#fnref:2&#34; role=&#34;doc-backlink&#34;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:3&#34;&gt;
&lt;p&gt;It then keeps spinning down to about 5V or so, it just needs enough power
to initially get started. &lt;a class=&#34;footnote-backref&#34; href=&#34;#fnref:3&#34; role=&#34;doc-backlink&#34;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</content>
    </entry>
    <entry>
        <title>Building a new Computer</title>
        <link href="https://chameth.com/building-a-new-computer/"/>
        <updated>2025-06-03T00:00:00Z</updated>
        <id>https://chameth.com/building-a-new-computer/</id>
        <content xml:lang="en" type="html">&lt;figure class=&#34;image right&#34;&gt;
  &lt;picture&gt;
      &lt;source srcset=&#34;https://chameth.com/building-a-new-computer/finished.avif&#34; type=&#34;image/avif&#34;/&gt;
      &lt;source srcset=&#34;https://chameth.com/building-a-new-computer/finished.webp&#34; type=&#34;image/webp&#34;/&gt;
      &lt;img src=&#34;https://chameth.com/building-a-new-computer/finished.jpg&#34; alt=&#34;A small form factor PC sat on a desk, with a pen propped up in front of it for scale. It&amp;#39;s about 1.5 pens tall. The case is silver, with a wooden panel at the bottom.&#34; loading=&#34;lazy&#34; width=&#34;375&#34; height=&#34;500&#34;/&gt;
  &lt;/picture&gt;
  &lt;figcaption&gt;&lt;p&gt;The finished PC. Cat pen for scale.&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;I recently&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a class=&#34;footnote-ref&#34; href=&#34;#fn:1&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt; built a new computer, after exclusively using a laptop for three
years. It’s also the first time I’ve departed from the usual combo of an Intel
CPU and Nvidia GPU.&lt;/p&gt;
&lt;p&gt;While the form factor of a laptop did make it amazingly handy for travelling
and attending LAN events, it was starting to show its age and there was
basically no sane upgrade path. The main problem was its 3060 mobile graphics
card, which was &lt;em&gt;okay&lt;/em&gt; for the first few years and then slowly descended into
&lt;em&gt;painful&lt;/em&gt;. At the time, the (fairly disappointing) 50-series had just been
released, but hadn’t yet made it into laptops. Nvidia had stopped production
on the 40-series beforehand, so there also weren’t any compelling options there,
either.&lt;/p&gt;
&lt;p&gt;That’s not to say there were no laptops at all that I could have upgraded to.
There were. Just not really any that ticked all of my perfectly normal boxes
like “run Linux”, “have at least 64GB of ram”, and “run modern games well”.
Having to upgrade the entire system just because the graphics card was
showing its age was a bit of a drag, too. So back to the land of desktop
computers I went!&lt;/p&gt;
&lt;p&gt;To try to preserve some of that convenience, I opted for a small form factor
(SFF) case. The computer and all the accessories can fit inside a
hand-luggage-sized flight case. More on that later, though.&lt;/p&gt;
&lt;h3 id=&#34;components-choices-and-cramming&#34;&gt;Components, Choices, and Cramming&lt;/h3&gt;
&lt;p&gt;So what, exactly, is in this computer? The case is a Fractal Design Terra,
which is a lovely little 10.4L case&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a class=&#34;footnote-ref&#34; href=&#34;#fn:2&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;. My last desktop PC was a normal-sized
Fractal Design case, which I liked a lot, and it seems like they’ve upped their
game since then. The Terra is both pleasant to look at (just look at that
wooden panel!), and a breeze to work in. The sides and top are fully and easily
removable, giving you great access to everything inside&lt;sup id=&#34;fnref:3&#34;&gt;&lt;a class=&#34;footnote-ref&#34; href=&#34;#fn:3&#34; role=&#34;doc-noteref&#34;&gt;3&lt;/a&gt;&lt;/sup&gt;. I expected an SFF
build to be fiddly, but the case made it feel about the same as a normal
full-sized build&lt;sup id=&#34;fnref:4&#34;&gt;&lt;a class=&#34;footnote-ref&#34; href=&#34;#fn:4&#34; role=&#34;doc-noteref&#34;&gt;4&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;
&lt;!--more--&gt;
&lt;figure class=&#34;image left&#34;&gt;
  &lt;picture&gt;
      &lt;source srcset=&#34;https://chameth.com/building-a-new-computer/build.avif&#34; type=&#34;image/avif&#34;/&gt;
      &lt;source srcset=&#34;https://chameth.com/building-a-new-computer/build.webp&#34; type=&#34;image/webp&#34;/&gt;
      &lt;img src=&#34;https://chameth.com/building-a-new-computer/build.jpg&#34; alt=&#34;The computer fully built, but with the sides and top of the case off, and wires protruding everywhere.&#34; loading=&#34;lazy&#34; width=&#34;500&#34; height=&#34;375&#34;/&gt;
  &lt;/picture&gt;
  &lt;figcaption&gt;&lt;p&gt;The case with sides and top off, and wires everywhere in desperate need of management.&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Another nice feature of the case is the movable spine. I think this is
relatively common in SFF cases, but it was new to me. You mount the graphics
card on one side of a metal divider, and everything else on the other. The
divider (or spine) can be moved side-to-side depending on what exactly you’re
putting in the case.&lt;/p&gt;
&lt;p&gt;As I mentioned earlier, this was my first departure from the Intel + Nvidia
bandwagon. Nvidia’s 50 series was underwhelming, and Intel managed to put out
a generation of chips that literally fried themselves. It seemed like a good
time to try out AMD’s offering! I went for the newly released Radeon RX 9070XT
graphics card, and a Ryzen 7 9800X3D processor&lt;sup id=&#34;fnref:5&#34;&gt;&lt;a class=&#34;footnote-ref&#34; href=&#34;#fn:5&#34; role=&#34;doc-noteref&#34;&gt;5&lt;/a&gt;&lt;/sup&gt;. The processor has a
Thermalright AXP90 X47 Full heatsink on top of it, with a Noctua NF-A9 fan
on top of that.&lt;/p&gt;
&lt;p&gt;The motherboard is a Gigabyte B850I Aorus Pro, and it hosts 2 32GB Corsair
Vengeance RAM modules, and a 2TB Crucial T705 NVMe drive. Powering it all is
a Cooler Master V750 SFX. The PSU is modular to reduce the number of wires that
need to be fitted in, but they’re still pretty big and bulky. I’m tempted by
custom cables but they’re rather pricey, and you can’t actually see inside
with the sides closed…&lt;/p&gt;
&lt;p&gt;With the diminutive size of the case and all the components crammed in,
there’s actually no room left over for case fans. The PSU, GPU and CPU all have
fans attached, but that’s it. There are stories online of people having heat
issues, but thankfully everything seems pretty happy in my setup. The components
all draw in air from the sides, and the hot air passively vents out the top. If
I keep the CPU under maximum load for a while then it starts to thermal throttle
slightly, but the only time I’ve actually managed that is when compiling a
kernel. Why was I compiling a kernel, you ask? Well, we’ll come to that.&lt;/p&gt;
&lt;h3 id=&#34;but-does-it-linux&#34;&gt;But does it Linux?&lt;/h3&gt;
&lt;p&gt;I didn’t go into this build &lt;em&gt;completely&lt;/em&gt; blind. I did a bit of reading and
chatting, and it sounded like AMD drivers were pretty good on Linux these
days. I didn’t check specifically if any of the components were supported.&lt;/p&gt;
&lt;p&gt;The 9070XT was released on the 6th of March. I built my PC on the 26th
of March. The first version of Mesa (the 3D graphics lib) that was generally
stable with 9070XT cards landed in Arch on the 20th of March. If I did the build
just one week earlier, I would’ve had a much less fun experience.&lt;/p&gt;
&lt;p&gt;It still wasn’t quite perfectly smooth, though. When playing games I’d
occasionally have issues. In some cases the screen just went blank and came
back after switching windows, but in others the graphics drivers couldn’t
recover and the PC needed rebooting. Fortunately the drivers are open source,
and they have a public &lt;a href=&#34;https://gitlab.freedesktop.org/drm/amd&#34;&gt;issue tracker&lt;/a&gt;
hosted by the Freedesktop project. Searching through the issues, I found they’d
already been reported (by another Arch user, of course), and there were various
suggestions for work-arounds, as well as lots of work trying to reproduce the
issue.&lt;/p&gt;
&lt;p&gt;Within a week, an AMD developer had posted a set of patches that might address
the issues, and asked people to test them. That’s fortunately pretty easy on
Arch: you just clone the repository containing the &lt;code&gt;PKGBUILD&lt;/code&gt; file, drop in
the patches, and update the checksums for them. Then you start compiling,
realise you didn’t tell it to use more than one CPU core, abort it, and start
again but this time running on all cylinders. Soon enough I was running a
patched 6.14 kernel and the problems stopped completely. Others reported
similar outcomes, and the patches worked their way into the kernel proper.&lt;/p&gt;
&lt;p&gt;I spent a few weeks having to compile a custom kernel every time I accidentally
updated it (I should’ve just stopped &lt;code&gt;pacman&lt;/code&gt; from touching the kernel for a
bit…), then one day the patches didn’t apply because they’d been merged
upstream. Since then everything has been perfect.&lt;/p&gt;
&lt;p&gt;A friend commented that “this wouldn’t happen with Nvidia”. They meant it
negatively, but I wholeheartedly agree! Maybe Nvidia have fewer launch bugs
than AMD, but you &lt;em&gt;absolutely&lt;/em&gt; wouldn’t be able to talk to their driver
engineers on a public bug tracker, and get access to test patches that fix
your issue. I’ll happily take a few bugs in exchange for a company that operates
openly in a way consistent with the rest of the Linux community.&lt;/p&gt;
&lt;h3 id=&#34;but-does-it-travel&#34;&gt;But does it travel?&lt;/h3&gt;
&lt;figure class=&#34;image right&#34;&gt;
  &lt;picture&gt;
      &lt;source srcset=&#34;https://chameth.com/building-a-new-computer/case.avif&#34; type=&#34;image/avif&#34;/&gt;
      &lt;source srcset=&#34;https://chameth.com/building-a-new-computer/case.webp&#34; type=&#34;image/webp&#34;/&gt;
      &lt;img src=&#34;https://chameth.com/building-a-new-computer/case.jpg&#34; alt=&#34;An open flight case, with the PC slotted in surrounded by foam. A keyboard sits below it, and various accessories on the side with 3D-printed supports.&#34; loading=&#34;lazy&#34; width=&#34;500&#34; height=&#34;375&#34;/&gt;
  &lt;/picture&gt;
  &lt;figcaption&gt;&lt;p&gt;Travel mode, engage!&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;So the computer works fine at home, but how do I get it to other places? I just
shoved a laptop in a backpack&lt;sup id=&#34;fnref:6&#34;&gt;&lt;a class=&#34;footnote-ref&#34; href=&#34;#fn:6&#34; role=&#34;doc-noteref&#34;&gt;6&lt;/a&gt;&lt;/sup&gt;, but you can’t quite do that with a PC even
one this size. I’d seen a few people at LANs who packed everything in flight
cases, but they always seemed a bit unwieldy. Doing some research, though, I
found that I’d just be able to squeeze everything into a flight case sized to
be taken onto a plane as cabin baggage.&lt;/p&gt;
&lt;p&gt;Peli (or Pelican in the US) are the most well known maker of flight cases, but
I chose to go with Nanuk instead. Spec-wise they’re fairly similar. Nanuk are
a bit cheaper. The killer difference for me, though, is that Nanuk publish
STEP files of their cases. As someone with a 3D printer, giving me CAD models
of things so that I can easily mod them is definitely a way to win my favour.&lt;/p&gt;
&lt;p&gt;After lots of measuring and thinking and modelling I came up with an arrangement
where everything could fit snugly into the case. The case has cutouts for the
wheels and handles, which constrain what can go where. I ended up wanting the
computer at the handle-end of the case to make best use of space, but that means
it needs something to take its weight when the case is vertical. The solution
was, of course, 3D printing.&lt;/p&gt;
&lt;p&gt;Using the STEP files from Nanuk I designed an insert that spans across the
case, with screw holes that line up with the ones in the flight case. I wasn’t
sure it would be able to take the weight like that, so I also added in some
supports in the other direction (running down to the bottom of the case, if it’s
stood up). I ended up printing it in three parts, and it came out perfectly first
time. I can’t emphasise how nice it is having CAD models instead of having to
measure and guess at things.&lt;/p&gt;
&lt;p&gt;With the support in place, I focused on cushioning the computer. I opted for
10mm thick EVA foam as it’s easy to obtain and work with, and doesn’t take up too much
room. I used contact adhesive to glue the foam directly to the case and the
3D printed divider. There’s a piece that goes between the computer and the
keyboard, so I printed some little 3D supports to hold that more firmly in
place, and stuck those in with contact adhesive as well.&lt;/p&gt;
&lt;p&gt;So how does it all hold up? It’s been to one LAN event so far, and it’s great.
I think the flight case might actually be easier to carry than hefting a heavy
backpack: the handles are sturdy and comfortable, and it has chunky wheels for
pulling it around. It’s also actually easier to get everything set up when you
can see it all laid out in the flight case and pull out what you need, and then
the case can be tucked away out the way for the duration of the event.&lt;/p&gt;
&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr/&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34;&gt;
&lt;p&gt;Recently-ish. It may or may not have taken me a few months to get around
to writing this post. &lt;a class=&#34;footnote-backref&#34; href=&#34;#fnref:1&#34; role=&#34;doc-backlink&#34;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34;&gt;
&lt;p&gt;Using litres to measure computer cases always feels wrong. Those are
the units we use for water. Don’t put them near the computers! &lt;a class=&#34;footnote-backref&#34; href=&#34;#fnref:2&#34; role=&#34;doc-backlink&#34;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:3&#34;&gt;
&lt;p&gt;The case also has holes to put security screws in to stop all of these
nice easily removable parts from being removable. Very handy when you’re
leaving it unattended at a LAN. &lt;a class=&#34;footnote-backref&#34; href=&#34;#fnref:3&#34; role=&#34;doc-backlink&#34;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:4&#34;&gt;
&lt;p&gt;Which for me means it was good fun for about an hour, and then I got fed
up and just wanted it to be done already. &lt;a class=&#34;footnote-backref&#34; href=&#34;#fnref:4&#34; role=&#34;doc-backlink&#34;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:5&#34;&gt;
&lt;p&gt;Three months in and I still can’t remember these random strings of
numbers. Someone even explained the versioning scheme to me. &lt;a class=&#34;footnote-backref&#34; href=&#34;#fnref:5&#34; role=&#34;doc-backlink&#34;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:6&#34;&gt;
&lt;p&gt;Along with a portable monitor, mouse, keyboard, headset, mouse mat,
kensington lock, power supply, cables, and controller. It was a heavy bag. &lt;a class=&#34;footnote-backref&#34; href=&#34;#fnref:6&#34; role=&#34;doc-backlink&#34;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</content>
    </entry>
    <entry>
        <title>Home Automation Without the Megacorps</title>
        <link href="https://chameth.com/home-automation-without-megacorps/"/>
        <updated>2025-05-21T00:00:00Z</updated>
        <id>https://chameth.com/home-automation-without-megacorps/</id>
        <content xml:lang="en" type="html">&lt;p&gt;I first experimented with home automation in 2016, by picking up a Samsung
“SmartThings” hub. It was terrible. The UI to configure things was slow and
clunky, firmware updates were applied whether you wanted them or not, and
everything stopped working if their cloud services stopped. You were also locked
into whatever integrations they deigned to support, of course. After that broke
for the umpteenth time I scaled back and for years the closest I got to home
automation was a couple of Hue bulbs.&lt;/p&gt;
&lt;p&gt;Recently I’ve been building it out again, though. This time using off-the-shelf
components that interop using Zigbee, open-source software, and some code I
wrote myself. It’s great; it runs entirely locally and has had basically zero
downtime. The Zigbee ecosystem lets me integrate all sorts of things without
having to spend lots of money on “smart” alternatives. I think I’ve spent less
on this incarnation than I did on the original SmartThings hub all those years
ago (even without adjusting for inflation!).&lt;/p&gt;
&lt;h3 id=&#34;my-current-setup&#34;&gt;My current setup&lt;/h3&gt;
&lt;p&gt;I run everything on a Raspberry Pi 4, with a Sonoff USB Zigbee adapter based
on the CC2652P chipset&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a class=&#34;footnote-ref&#34; href=&#34;#fn:1&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;. Interfacing with the Zigbee stack is handled by
&lt;a href=&#34;https://www.zigbee2mqtt.io/&#34;&gt;zigbee2mqtt&lt;/a&gt; (z2m for short), an open-source project that
basically bridges your devices to an MQTT broker&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a class=&#34;footnote-ref&#34; href=&#34;#fn:2&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;. When a device reports some
data, it will send a new message over MQTT; when you want to make a device do
something you just post a message back. It’s incredibly lightweight, but
supports a huge array of devices out of the box. And as it’s just using MQTT,
it’s trivial to integrate with other software or build on top of.&lt;/p&gt;
&lt;!--more--&gt;
&lt;p&gt;I know a lot of people building out this kind of home automation use
&lt;a href=&#34;https://www.home-assistant.io/&#34;&gt;Home Assistant&lt;/a&gt;, but I don’t get on with it
terribly well. It felt incredibly sluggish, and the entire project is just a
bit… much. I want a binary or package or docker image I can just run, not an
entire operating system. That’s not how computers are meant to work! In contrast,
z2m is simple to set up, super light weight and responsive.&lt;/p&gt;
&lt;p&gt;Anyway. z2m exposes Zigbee devices over MQTT, so I wrote some code in Go to
connect to the MQTT broker, and listen to the messages. It’s grown a bit beyond
this now, and I’m skipping some boring bits like error handling and JSON
parsing, but at first I had something like:&lt;/p&gt;
&lt;pre class=&#34;chroma-chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;chroma-line&#34;&gt;&lt;span class=&#34;chroma-cl&#34;&gt;&lt;span class=&#34;chroma-k&#34;&gt;for&lt;/span&gt;&lt;span class=&#34;chroma-w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;chroma-p&#34;&gt;{&lt;/span&gt;&lt;span class=&#34;chroma-w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;chroma-line&#34;&gt;&lt;span class=&#34;chroma-cl&#34;&gt;&lt;span class=&#34;chroma-w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;chroma-nx&#34;&gt;message&lt;/span&gt;&lt;span class=&#34;chroma-p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;chroma-w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;chroma-nx&#34;&gt;topic&lt;/span&gt;&lt;span class=&#34;chroma-p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;chroma-w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;chroma-nx&#34;&gt;err&lt;/span&gt;&lt;span class=&#34;chroma-w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;chroma-o&#34;&gt;:=&lt;/span&gt;&lt;span class=&#34;chroma-w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;chroma-nx&#34;&gt;c&lt;/span&gt;&lt;span class=&#34;chroma-p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;chroma-nf&#34;&gt;ReadSlices&lt;/span&gt;&lt;span class=&#34;chroma-p&#34;&gt;()&lt;/span&gt;&lt;span class=&#34;chroma-w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;chroma-line&#34;&gt;&lt;span class=&#34;chroma-cl&#34;&gt;&lt;span class=&#34;chroma-w&#34;&gt;    
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;chroma-line&#34;&gt;&lt;span class=&#34;chroma-cl&#34;&gt;&lt;span class=&#34;chroma-w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;chroma-k&#34;&gt;if&lt;/span&gt;&lt;span class=&#34;chroma-w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;chroma-nb&#34;&gt;string&lt;/span&gt;&lt;span class=&#34;chroma-p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;chroma-nx&#34;&gt;topic&lt;/span&gt;&lt;span class=&#34;chroma-p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;chroma-w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;chroma-o&#34;&gt;==&lt;/span&gt;&lt;span class=&#34;chroma-w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;chroma-s&#34;&gt;&amp;#34;zigbee2mqtt/desk-button&amp;#34;&lt;/span&gt;&lt;span class=&#34;chroma-w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;chroma-p&#34;&gt;{&lt;/span&gt;&lt;span class=&#34;chroma-w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;chroma-line&#34;&gt;&lt;span class=&#34;chroma-cl&#34;&gt;&lt;span class=&#34;chroma-w&#34;&gt;        &lt;/span&gt;&lt;span class=&#34;chroma-k&#34;&gt;if&lt;/span&gt;&lt;span class=&#34;chroma-w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;chroma-nx&#34;&gt;strings&lt;/span&gt;&lt;span class=&#34;chroma-p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;chroma-nf&#34;&gt;Contains&lt;/span&gt;&lt;span class=&#34;chroma-p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;chroma-nx&#34;&gt;message&lt;/span&gt;&lt;span class=&#34;chroma-p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;chroma-w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;chroma-s&#34;&gt;&amp;#34;single&amp;#34;&lt;/span&gt;&lt;span class=&#34;chroma-p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;chroma-w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;chroma-p&#34;&gt;{&lt;/span&gt;&lt;span class=&#34;chroma-w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;chroma-line&#34;&gt;&lt;span class=&#34;chroma-cl&#34;&gt;&lt;span class=&#34;chroma-w&#34;&gt;            &lt;/span&gt;&lt;span class=&#34;chroma-nx&#34;&gt;c&lt;/span&gt;&lt;span class=&#34;chroma-p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;chroma-nf&#34;&gt;Publish&lt;/span&gt;&lt;span class=&#34;chroma-p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;chroma-kc&#34;&gt;nil&lt;/span&gt;&lt;span class=&#34;chroma-p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;chroma-w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;chroma-p&#34;&gt;[]&lt;/span&gt;&lt;span class=&#34;chroma-nb&#34;&gt;byte&lt;/span&gt;&lt;span class=&#34;chroma-p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;chroma-s&#34;&gt;&amp;#34;{\&amp;#34;state\&amp;#34;: \&amp;#34;TOGGLE\&amp;#34;}&amp;#34;&lt;/span&gt;&lt;span class=&#34;chroma-p&#34;&gt;),&lt;/span&gt;&lt;span class=&#34;chroma-w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;chroma-s&#34;&gt;&amp;#34;zigbee2mqtt/room-lights/set&amp;#34;&lt;/span&gt;&lt;span class=&#34;chroma-p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;chroma-w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;chroma-line&#34;&gt;&lt;span class=&#34;chroma-cl&#34;&gt;&lt;span class=&#34;chroma-w&#34;&gt;        &lt;/span&gt;&lt;span class=&#34;chroma-p&#34;&gt;}&lt;/span&gt;&lt;span class=&#34;chroma-w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;chroma-line&#34;&gt;&lt;span class=&#34;chroma-cl&#34;&gt;&lt;span class=&#34;chroma-w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;chroma-p&#34;&gt;}&lt;/span&gt;&lt;span class=&#34;chroma-w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;chroma-line&#34;&gt;&lt;span class=&#34;chroma-cl&#34;&gt;&lt;span class=&#34;chroma-p&#34;&gt;}&lt;/span&gt;&lt;span class=&#34;chroma-w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I think I actually made this harder to read by trying to simplify it here, but
hopefully you can follow that it was relatively straight forward to listen
for a particular action to happen (in this case me “single”-pressing on the
device called “desk-button”) and then make another device do something in
response (toggling the state of the “room-lights” device).&lt;/p&gt;
&lt;p&gt;So what actually are these devices? At present in z2m I have the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Some generic buttons&lt;/li&gt;
&lt;li&gt;An air quality sensor (USB powered), and a separate temperature sensor (battery powered)&lt;/li&gt;
&lt;li&gt;A light switch&lt;/li&gt;
&lt;li&gt;Some 240V relay modules, that I use to turn non-smart devices on and off&lt;/li&gt;
&lt;li&gt;Some USB relay modules, for the same purpose&lt;/li&gt;
&lt;li&gt;Some “smart” plugs that I mostly use to monitor power usage&lt;/li&gt;
&lt;li&gt;A motorised blind roller&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I think all of these are either Tuya or Moes branded, and were all sourced from
AliExpress. You can get the same things from Amazon or elsewhere, but they tend
to be 3-4x more expensive for the same product.&lt;/p&gt;
&lt;p&gt;One of the cool things about Zigbee devices is that the powered ones work
together to create a mesh network, so you don’t have to worry about network
repeaters or signal strength like you do with Wi-Fi networks. z2m even makes
a map showing the connections:&lt;/p&gt;
&lt;figure class=&#34;image full&#34;&gt;
  &lt;picture&gt;
      &lt;source srcset=&#34;https://chameth.com/home-automation-without-megacorps/zigbee-map.avif&#34; type=&#34;image/avif&#34;/&gt;
      &lt;source srcset=&#34;https://chameth.com/home-automation-without-megacorps/zigbee-map.webp&#34; type=&#34;image/webp&#34;/&gt;
      &lt;img src=&#34;https://chameth.com/home-automation-without-megacorps/zigbee-map.png&#34; alt=&#34;A &amp;#34;map&amp;#34; showing how Zigbee devices connect to one another&#34; loading=&#34;lazy&#34; width=&#34;1093&#34; height=&#34;651&#34;/&gt;
  &lt;/picture&gt;
  &lt;figcaption&gt;&lt;p&gt;The network map produced by z2m. You can see how all the powered devices form a mesh that the lower power ones can connect to.&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h3 id=&#34;some-interesting-automations&#34;&gt;Some interesting automations&lt;/h3&gt;
&lt;figure class=&#34;image right&#34;&gt;
  &lt;picture&gt;
      &lt;source srcset=&#34;https://chameth.com/home-automation-without-megacorps/relay.avif&#34; type=&#34;image/avif&#34;/&gt;
      &lt;source srcset=&#34;https://chameth.com/home-automation-without-megacorps/relay.webp&#34; type=&#34;image/webp&#34;/&gt;
      &lt;img src=&#34;https://chameth.com/home-automation-without-megacorps/relay.jpg&#34; alt=&#34;A Zigbee relay and some wago connectors wired up in a project box&#34; loading=&#34;lazy&#34; width=&#34;325&#34; height=&#34;500&#34;/&gt;
  &lt;/picture&gt;
  &lt;figcaption&gt;&lt;p&gt;A Zigbee relay spliced into the power cable for the fan&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;So what do I actually do with all of this? Some of it is just what I’ll call
“laziness automation”: I want to be able to turn on the lights without getting
up and walking to the light switch. So there’s a Zigbee button on my desk that
does it. Then there are some less manual automations: my blinds are
automatically closed at sunset&lt;sup id=&#34;fnref:3&#34;&gt;&lt;a class=&#34;footnote-ref&#34; href=&#34;#fn:3&#34; role=&#34;doc-noteref&#34;&gt;3&lt;/a&gt;&lt;/sup&gt;, for example. It feels a bit trivial, but it’s
surprisingly nice just not to have to think about that at all.&lt;/p&gt;
&lt;p&gt;Another nice quality of life automation is the light I have above my monitor.
It’s USB powered, and I now have it going through a Zigbee USB relay that lets
it be toggled on and off. Then I have a small agent running on my desktop that
turns the light on when the computer is unlocked, and off when it locks or
shuts down. I keep meaning to make a “film mode” that detects when I’m watching
a film, and turning all the lights and blinds down, but I haven’t got around
to it yet.&lt;/p&gt;
&lt;p&gt;The most complex automation is probably for a window fan. It’s not smart in
any way, so I cut the power cable and inserted a Zigbee relay. The whole thing
is housed in a little project box to keep it secure. The relay basically acts
as a switch: the live wire leading to the fan runs to the “normally open”&lt;sup id=&#34;fnref:4&#34;&gt;&lt;a class=&#34;footnote-ref&#34; href=&#34;#fn:4&#34; role=&#34;doc-noteref&#34;&gt;4&lt;/a&gt;&lt;/sup&gt;
contact, while the upstream power goes to “common”. When the relay is told to
turn the fan on, the two get connected and the fan gets power. Oh, it’s also
not actually a window fan, but I designed and 3D printed some adapters so that
it sits right in the window.&lt;/p&gt;
&lt;p&gt;So now we have a window fan that can be turned off and on automatically. But I don’t
want to have to press a button to do that. I’m lazy, remember? Instead, I made
it so that the Go code constantly monitors the temperature reported by the air
quality sensor, and queries the free &lt;a href=&#34;https://openweathermap.org/&#34;&gt;OpenWeatherMap API&lt;/a&gt;
to get the rough temperature outside. It can then turn the fan on if the room is
too hot, and outside is cool enough to make a difference (there’s no point in
blowing hotter air in!).&lt;/p&gt;
&lt;figure class=&#34;image left&#34;&gt;
  &lt;picture&gt;
      &lt;source srcset=&#34;https://chameth.com/home-automation-without-megacorps/fan-graph.avif&#34; type=&#34;image/avif&#34;/&gt;
      &lt;source srcset=&#34;https://chameth.com/home-automation-without-megacorps/fan-graph.webp&#34; type=&#34;image/webp&#34;/&gt;
      &lt;img src=&#34;https://chameth.com/home-automation-without-megacorps/fan-graph.png&#34; alt=&#34;A graph of room temperature, slowly rising to 23.5 degrees, then sharply dropping to 19, rising to 20, dropping to 19 again, etc&#34; loading=&#34;lazy&#34; width=&#34;540&#34; height=&#34;500&#34;/&gt;
  &lt;/picture&gt;
  &lt;figcaption&gt;&lt;p&gt;A graph of room temperature, showing the effect of the fan being turned on and off&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;I don’t want it to do that all the time though. The room doesn’t need to be
cooled if I’m not around. There are various Zigbee presence sensors you can get,
but the cheaper ones seem to be of dubious quality. Instead, I wrote some code
to guess whether I’m present. It uses the state of the monitor light
as a proxy for “is the computer in use”, and then makes some guesses based on
the last time the computer was used and the current time (if I turn the computer
off at midnight it probably means I’m going to sleep; if I turn it off at 2pm
it probably means I’m going out somewhere).&lt;/p&gt;
&lt;p&gt;You can see in the graph that the fan has a decent impact on temperature. I
coded it to cool the room to 19 degrees, but then not turn on again until it
was above 20. This prevents it flip-flopping on and off constantly. You can
clearly see the pattern in the graph, as it actively cools and then slowly
the room warms back up. This arrangement is much better than being woken up at
5am because it’s painfully cold. Trust me.&lt;/p&gt;
&lt;h3 id=&#34;bonuses-metrics-and-3d-printer&#34;&gt;Bonuses: metrics and 3D printer&lt;/h3&gt;
&lt;p&gt;One of the things my custom Go code does is collate all the various stats
reported by the Zigbee devices, and inserts them into a &lt;a href=&#34;https://victoriametrics.com/&#34;&gt;VictoriaMetrics&lt;/a&gt;
database. I originally hosted this on the Pi itself, and it performed fine, but
I’ve since moved it onto a server so that I can use it for some other things
as well.&lt;/p&gt;
&lt;p&gt;I set up Grafana to point to VM, and can create dashboards showing power usage,
what devices are turned on when, and a bunch of environmental conditions. This
also makes it easy to spot how good the data coming from the devices are. For
example, the air quality sensor reports a figure for the amount of Carbon Dioxide
in the air, as well as the amount of Volatile Organic Compounds (VOCs). The
graphs are basically identical, but on a different scale. It turns out this
particular device has no actual way of detecting CO₂, so it just “calculates”
it from the VOCs figure. Useful to know if you want to actually use that data.&lt;/p&gt;
&lt;p&gt;Recently I came across &lt;a href=&#34;https://github.com/torbenconto/bambulabs_api&#34;&gt;a go library for interacting with Bambu Lab printers&lt;/a&gt;,
so I’ve also hooked that into my automation. It exports metrics about the
printer, so I now have a way of seeing what’s going on when I’m not physically
present&lt;sup id=&#34;fnref:5&#34;&gt;&lt;a class=&#34;footnote-ref&#34; href=&#34;#fn:5&#34; role=&#34;doc-noteref&#34;&gt;5&lt;/a&gt;&lt;/sup&gt;. I even added a HTTP endpoint (exposed over &lt;a href=&#34;https://tailscale.com/&#34;&gt;Tailscale&lt;/a&gt;) that
shows pictures from the built-in camera.&lt;/p&gt;
&lt;p&gt;On the automation front, I’ve made it automatically turn off the printer’s light
when it finishes a print, and also added push notifications via &lt;a href=&#34;https://pushover.net/&#34;&gt;PushOver&lt;/a&gt;
whenever the state changes. No longer will I be sat in another room blissfully
unaware it ran out of filament seconds after I walked out the door!&lt;/p&gt;
&lt;h3 id=&#34;was-it-worth-it&#34;&gt;Was it worth it?&lt;/h3&gt;
&lt;p&gt;These days you could probably just buy some kind of ‘smart home’ hub that works
well enough, and do most of what I’ve done with a lot less effort and no coding.
I’m still of the opinion that for something so essentially &lt;em&gt;local&lt;/em&gt;, it should
itself be managed entirely locally. I don’t trust companies like Google or
Amazon not to kill their products, or change or remove an API I rely on.&lt;/p&gt;
&lt;p&gt;Obviously the “Not Invented Here” approach of coding everything yourself doesn’t
suit everyone, but as someone who enjoys coding and enjoys having things work
&lt;em&gt;just so&lt;/em&gt; it works very well for me.&lt;/p&gt;
&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr/&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34;&gt;
&lt;p&gt;It turns out the chipset is important. I initially used a similar Sonoff
dongle that used a CC2531 chipset, and its performance wasn’t great. It often
failed to pair with new devices, and dropped links to existing ones. The
&lt;a href=&#34;https://www.zigbee2mqtt.io/advanced/zigbee/02_improve_network_range_and_stability.html&#34;&gt;zigbee2mqtt docs&lt;/a&gt;
do explicitly advise against the CC2531 chips for that reason. At the time they
recommended CC2652Ps, so that’s what I went with. If you’re starting new I’d
go with whatever their latest recommendation was. &lt;a class=&#34;footnote-backref&#34; href=&#34;#fnref:1&#34; role=&#34;doc-backlink&#34;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34;&gt;
&lt;p&gt;MQTT is basically a network protocol for publishing and subscribing to
arbitrary messages. A broker is the thing that sits in the middle and routes
the messages. I use &lt;a href=&#34;https://mosquitto.org/&#34;&gt;Mosquitto&lt;/a&gt; but any will do. &lt;a class=&#34;footnote-backref&#34; href=&#34;#fnref:2&#34; role=&#34;doc-backlink&#34;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:3&#34;&gt;
&lt;p&gt;They originally also re-opened at sunrise but that was a terrible
mistake. Who knew the sun rose so early?! &lt;a class=&#34;footnote-backref&#34; href=&#34;#fnref:3&#34; role=&#34;doc-backlink&#34;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:4&#34;&gt;
&lt;p&gt;“open” meaning “there’s a gap so it doesn’t work” not
“open for business”. This confusion in terminology also extends to drawbridges. &lt;a class=&#34;footnote-backref&#34; href=&#34;#fnref:4&#34; role=&#34;doc-backlink&#34;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:5&#34;&gt;
&lt;p&gt;I use the printer in LAN mode, which means there’s no way to monitor it
from a phone, even if you’re connected to the same network still. &lt;a class=&#34;footnote-backref&#34; href=&#34;#fnref:5&#34; role=&#34;doc-backlink&#34;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</content>
    </entry>
    <entry>
        <title>Further adventures in 3D printing</title>
        <link href="https://chameth.com/further-adventures-in-3d-printing/"/>
        <updated>2024-08-04T00:00:00Z</updated>
        <id>https://chameth.com/further-adventures-in-3d-printing/</id>
        <content xml:lang="en" type="html">&lt;figure class=&#34;image right&#34;&gt;
  &lt;picture&gt;
      &lt;source srcset=&#34;https://chameth.com/further-adventures-in-3d-printing/p1s.avif&#34; type=&#34;image/avif&#34;/&gt;
      &lt;source srcset=&#34;https://chameth.com/further-adventures-in-3d-printing/p1s.webp&#34; type=&#34;image/webp&#34;/&gt;
      &lt;img src=&#34;https://chameth.com/further-adventures-in-3d-printing/p1s.png&#34; alt=&#34;Marketing image of the Bambu Labs P1S&#34; loading=&#34;lazy&#34; width=&#34;404&#34; height=&#34;400&#34;/&gt;
  &lt;/picture&gt;
  &lt;figcaption&gt;&lt;p&gt;The Bambu Labs P1S.&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Not quite a year ago, I bought a Sovol SV06 3D printer and &lt;a href=&#34;https://chameth.com/adventures-in-3d-printing/&#34;&gt;wrote about&lt;/a&gt;
my initial experiences. At the end I joked:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;I’m sure there will be more problems, but hopefully I get at least a week or
so before anything else goes wrong. Maybe I’ll print an “X days since the
last SV06 problem” counter…&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;That turned out to be more prophetic than I expected. It became a running joke
that I’d flip the imaginary “days since” sign back to 0 almost every time I
printed. I still really enjoyed having a printer, though: it’s so useful to
be able to be able to go from an idea to a CAD drawing to a physical object
in the space of minutes or hours. So when Bambu Labs reduced the price of the
&lt;a href=&#34;https://uk.store.bambulab.com/products/p1s&#34;&gt;P1S&lt;/a&gt; — a printer generally regarded
as about as trouble free as you can get — to £522 including shipping, I splurged on one.&lt;/p&gt;
&lt;h3 id=&#34;concerns&#34;&gt;Concerns&lt;/h3&gt;
&lt;p&gt;I make it sound like that was an easy decision, but I actually ummed and ahed
a lot before pulling the trigger. I had a lot of objections to a Bambu Labs
printer, and wasn’t quite sure if the price made up for them.&lt;/p&gt;
&lt;!--more--&gt;
&lt;p&gt;The Bambu Labs printers are designed to be more consumer friendly than most
previous 3D printers. You can start a model printing directly from their
website or mobile app, which employs a cloud-based slicer that then sends the
model down to your printer. This is one of those things that sounds amazing for
consumers, but should terrify anyone who works with computers. There are so many
ways for a “cloud-connected” printer to go wrong, and with such potentially
disastrous results it gives me anxiety just thinking about it.&lt;/p&gt;
&lt;p&gt;This is not just theoretical, either. In a blog post with the rather under-stated
title of &lt;a href=&#34;https://blog.bambulab.com/cloud-temporary-outage-investigation/&#34;&gt;“Initial Investigation in the Bambu Cloud Temporary Outage”&lt;/a&gt;,
Bambu describe how a server-side error caused printers to start printing unprompted.
Users on Reddit reported printers starting in the middle of the night, trying
to print on top of other objects that were left on the build plate, and so on.
3D printers can easily start fires; having them cloud controlled is frankly
insane.&lt;/p&gt;
&lt;p&gt;As a result of that “temporary outage”, Bambu further improved the “LAN mode”
for their printers, which allows you to sever its connection from their servers
and control it over the network. That’s basically how my old printer worked
anyway, so I was happy enough that I could enable LAN mode and ignore all the
cloud nonsense.&lt;/p&gt;
&lt;p&gt;My other objection to Bambu was more nebulous. Almost all 3D printers are built
upon open source software, and some companies like Prusa go out of their way to
make their products more open to give back to the community. Bambu don’t really
do any of that: I’d be very surprised if they &lt;em&gt;hadn’t&lt;/em&gt; incorporated a bunch of
open source software into their printers and just ignored the licences&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a class=&#34;footnote-ref&#34; href=&#34;#fn:1&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;. I’d
much rather give my money to a company doing good, but the only equivalent
printer was the &lt;a href=&#34;https://www.prusa3d.com/product/original-prusa-mk4-2/&#34;&gt;Prusa MK4&lt;/a&gt;
which was &lt;em&gt;double&lt;/em&gt; the price and didn’t come with an enclosure. To add an
enclosure kit would have made it £800 more expensive than the P1S, and I just
can’t justify that.&lt;/p&gt;
&lt;h3 id=&#34;experience&#34;&gt;Experience&lt;/h3&gt;
&lt;p&gt;The initial setup of the P1S was a breeze. While the SV06 shipped in parts, the
P1S came fully assembled and just needed some packaging and retaining screws
removed. These were all clearly marked with large coloured arrows. It’s very
much designed so anyone can do it.&lt;/p&gt;
&lt;p&gt;I ran through the initial calibration, firmware update, and then put it
in LAN mode. Then I just started printing and it went fine. No messing around
levelling a bed, or using a sheet of paper to try and set the Z-offset properly;
it just worked. It was &lt;em&gt;really&lt;/em&gt; loud though. After talking a bit with a friend
who’d also bought a P1S, I realised that most of his noise was from the fans,
while most of mine was from the servos. A bit of research later and I found out
they added servo noise compensation in a firmware update, but I hadn’t run the
calibration for it because the initial calibration happened before the update.
After doing that, the printer went from sounding like it was impersonating a
continental police siren to just being a bit fan-y.&lt;/p&gt;
&lt;p&gt;The biggest difference over the SV06 is the speed. I’d swapped the nozzle on the
SV06 to a 0.6mm one, and generally printed at a layer height of 0.4mm. The P1S
still has its 0.4mm nozzle, and I mostly print at a layer height of 0.2mm. So
it’s laying down twice the number of layers, with a nozzle that can extrude
half the amount of plastic… And it’s at least twice as fast! Prints that I
previously wouldn’t have even attempted on the SV06 are now 8-10 hours on the
P1S, without even adjusting the speed or lowering the quality. Here’s a
side-by-side comparison:&lt;/p&gt;
&lt;figure class=&#34;image full&#34;&gt;
  &lt;picture&gt;
      &lt;source srcset=&#34;https://chameth.com/further-adventures-in-3d-printing/comparison.avif&#34; type=&#34;image/avif&#34;/&gt;
      &lt;source srcset=&#34;https://chameth.com/further-adventures-in-3d-printing/comparison.webp&#34; type=&#34;image/webp&#34;/&gt;
      &lt;img src=&#34;https://chameth.com/further-adventures-in-3d-printing/comparison.png&#34; alt=&#34;A side-by-side comparison of printing time on the P1S and SV06. The P1S prints 8 objects at higher quality than the SV06 prints 3.&#34; loading=&#34;lazy&#34; width=&#34;1856&#34; height=&#34;944&#34;/&gt;
  &lt;/picture&gt;
  &lt;figcaption&gt;&lt;p&gt;P1S vs SV06.&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;The P1S can print eight objects because of its slightly larger bed, while the
SV06 can only manage three. The P1S is also printing at a much higher quality.
Yet somehow it still ends up being faster. It’s mind blowing.&lt;/p&gt;
&lt;p&gt;The other big difference I’ve not mentioned yet is that the P1S is a “core XY”
printer rather than a “bed slinger”. That means in order to move along the
Y-axis (from the front of the bed to the back), the P1S moves the extruder
while the SV06 moves the bed. This makes a big difference when printing tall
objects, as they’re far more likely to wobble and come loose when the bed is
moving back and forth. It also presumably makes the kinematics a lot easier
as the mass of the moving parts is constant, instead of gradually becoming
heavier as more and more plastic gets added.&lt;/p&gt;
&lt;h3 id=&#34;the-only-failures&#34;&gt;The only failures&lt;/h3&gt;
&lt;p&gt;I’ve only had a handful of failures since getting the P1S. I had one weird
issue where the slicer decided to print some parts extremely slowly, and the
print just didn’t work out in those parts; that’s more of a slicer issue,
though: after tweaking the model to stop the weird behaviour it printed fine.&lt;/p&gt;
&lt;p&gt;The only failure I can directly attribute to the printer was when I tried
ironing. This is a process where after printing the top layer, the printer
slowly goes back over it at the same height while extruding a small amount of
plastic. This is meant to fill in the small gaps between extrusions and give
a smooth finish. In my case, though, it just clogged the nozzle and extruder.&lt;/p&gt;
&lt;p&gt;At first I thought it was because I was printing too hot: the profile I was
using was designed for fast printing, so had to melt the filament rapidly, but
there was no way to turn that temperature down just for the ironing pass. I
tried another run at a lower temperature and everything clogged again. I then
swore off ironing, did a normal print, and everything clogged once more.&lt;/p&gt;
&lt;p&gt;At this point I was getting exceedingly good at disassembling the hot end, but
also fairly annoyed. It felt like I was using an SV06 again&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a class=&#34;footnote-ref&#34; href=&#34;#fn:2&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;! I’d previously
read some recommendations that you should leave the door or top of the enclosure
open when printing PLA, but had never really had any issues so hadn’t bothered.
I tried a print with the top propped open and everything worked smoothly again.
In hindsight all these clogging issues happened when it was particularly hot
and humid outside, which was probably a factor.&lt;/p&gt;
&lt;h3 id=&#34;summary&#34;&gt;Summary&lt;/h3&gt;
&lt;p&gt;Upgrading to the P1S has made the 3D printer feel more like a tool and less like
an additional ongoing project. The speed increase continues to amaze me, as
does the increase in quality.&lt;/p&gt;
&lt;p&gt;I still think it was valuable to have the SV06 to learn how printers work — you
definitely don’t get as much of that from using something so consumer-focused
as the P1S — and figure out if I was actually going to use it long-term or
whether it was just a fad for me. So it served its purpose, but I’m rather
glad to see the back of it in favour of something better in pretty much every
way.&lt;/p&gt;
&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr/&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34;&gt;
&lt;p&gt;And if they did there’s nothing anyone can do about it because copyright
doesn’t exist in the same way in China. &lt;a class=&#34;footnote-backref&#34; href=&#34;#fnref:1&#34; role=&#34;doc-backlink&#34;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34;&gt;
&lt;p&gt;Although taking apart the P1S (which is a proprietary machine you might
not expect to be very user-servicable) was orders of magnitude easier than taking
apart the SV06 (which was an open source design). Everything is just much nicer:
the connectors are easier to attach and detach, the screws are all a consistent
size instead of needing a whole suite of allen keys, and so on. &lt;a class=&#34;footnote-backref&#34; href=&#34;#fnref:2&#34; role=&#34;doc-backlink&#34;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</content>
    </entry>
    <entry>
        <title>Project log: Filament weight display</title>
        <link href="https://chameth.com/filament-weight-display/"/>
        <updated>2023-12-03T00:00:00Z</updated>
        <id>https://chameth.com/filament-weight-display/</id>
        <content xml:lang="en" type="html">&lt;figure class=&#34;image left&#34;&gt;
  &lt;picture&gt;
      &lt;source srcset=&#34;https://chameth.com/filament-weight-display/finished.avif&#34; type=&#34;image/avif&#34;/&gt;
      &lt;source srcset=&#34;https://chameth.com/filament-weight-display/finished.webp&#34; type=&#34;image/webp&#34;/&gt;
      &lt;img src=&#34;https://chameth.com/filament-weight-display/finished.jpg&#34; alt=&#34;Filament weight display&#34; loading=&#34;lazy&#34; width=&#34;327&#34; height=&#34;247&#34;/&gt;
  &lt;/picture&gt;
  &lt;figcaption&gt;&lt;p&gt;The finished project&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;One problem&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a class=&#34;footnote-ref&#34; href=&#34;#fn:1&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt; I have when 3D printing is that it’s hard to gauge whether
there’s enough filament left on a roll to complete a print. Sometimes it’s
obvious when the print is small or the roll is full, but often it’s not.
If I’m unsure about it, I end up obsessing over the printer instead of just
leaving it to do its thing.&lt;/p&gt;
&lt;p&gt;The typical approach to this problem is to use a run-out sensor, which stops
the printer when it detects that the filament is no longer running through it.
I’d rather know in advance though: it’s no good stopping the print if I’m
making something that has to look nice and now half of it is one colour and
the remainder will be something else.&lt;/p&gt;
&lt;p&gt;While browsing around for ideas, I came across a project that used a load cell
to measure the weight of the filament roll&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a class=&#34;footnote-ref&#34; href=&#34;#fn:2&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;. I didn’t really know what a
load cell was, but decided to do some research and see if I could build my own.
I didn’t actually read the article I found, intending to figure things out on
my own if I could.&lt;/p&gt;
&lt;!--more--&gt;
&lt;h3 id=&#34;load-cells-101&#34;&gt;Load Cells 101&lt;/h3&gt;
&lt;figure class=&#34;image right&#34;&gt;
  &lt;picture&gt;
      &lt;source srcset=&#34;https://chameth.com/filament-weight-display/loadcell.avif&#34; type=&#34;image/avif&#34;/&gt;
      &lt;source srcset=&#34;https://chameth.com/filament-weight-display/loadcell.webp&#34; type=&#34;image/webp&#34;/&gt;
      &lt;img src=&#34;https://chameth.com/filament-weight-display/loadcell.jpg&#34; alt=&#34;Product picture of a load cell and amplifier&#34; loading=&#34;lazy&#34; width=&#34;400&#34; height=&#34;400&#34;/&gt;
  &lt;/picture&gt;
  &lt;figcaption&gt;&lt;p&gt;A load cell, its amplifier, and some random headers&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;At the heart of the project is a load cell. It turns out these are the things
that do the lifting in most electronic scales. They’re basically a carefully
machined metal bar with a strain gauge attached to it. The strain gauge is
a long trace of conductive material that runs back and forth across the middle
of the bar. When the bar bends very slightly (due to load), the conductor flexes
with it and gets longer or shorter; that flex changes its resistance by a tiny
amount, which can be measured using a
&lt;a href=&#34;https://en.wikipedia.org/wiki/Wheatstone_bridge&#34;&gt;Wheatstone bridge&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The Wheatstone bridge is a diamond of resistors, and requires an ’excitation’
voltage to be applied across it in one direction, and the resistance is then
read from the perpendicular pair. As the resistance is tiny, and the changes
even more tiny, you generally need an amplifier to read it and output something
more useful. The HX711 is such an amplifier, and is so ubiquitous that most
places that sell load cells will just bundle one with it.&lt;/p&gt;
&lt;p&gt;The HX711 connects to the load cell using four wires: two for the excitation
voltage, and two for the output. On the other end it takes a 5V input, ground,
and then has two pins to deal with the onward communication: one for a clock
signal, and one for data. We’ll get back to that later!&lt;/p&gt;
&lt;h3 id=&#34;early-prototyping&#34;&gt;Early prototyping&lt;/h3&gt;
&lt;figure class=&#34;image left&#34;&gt;
  &lt;picture&gt;
      &lt;source srcset=&#34;https://chameth.com/filament-weight-display/prototype.avif&#34; type=&#34;image/avif&#34;/&gt;
      &lt;source srcset=&#34;https://chameth.com/filament-weight-display/prototype.webp&#34; type=&#34;image/webp&#34;/&gt;
      &lt;img src=&#34;https://chameth.com/filament-weight-display/prototype.jpg&#34; alt=&#34;Prototype weight sensor built on a breadboard&#34; loading=&#34;lazy&#34; width=&#34;500&#34; height=&#34;750&#34;/&gt;
  &lt;/picture&gt;
  &lt;figcaption&gt;&lt;p&gt;The prototype, mid-debugging&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;I decided early on to base the project around an RP2040-based board, as I had
previous experience with them and they’re cheap and easy to get hold of. I
started off with a Raspberry Pi Pico, slotted it into a breadboard, and
connected it to the HX711. A short search produced three or so different
python libraries, but I couldn’t get any of them to work reliably.&lt;/p&gt;
&lt;p&gt;If you look at the picture of the prototype, you’ll notice a large bundle
of wires to the left. These are connected to a logic analyser I bought to
try and understand what on earth was happening, because it &lt;em&gt;seemed&lt;/em&gt; like
the code should work, and there was definitely some communication with the
HX711 happening, but none of the readings made any sense.&lt;/p&gt;
&lt;p&gt;At one point I noticed that moving my head near to the Pico caused the
readings to change, but I didn’t understand the implication of that&lt;sup id=&#34;fnref:3&#34;&gt;&lt;a class=&#34;footnote-ref&#34; href=&#34;#fn:3&#34; role=&#34;doc-noteref&#34;&gt;3&lt;/a&gt;&lt;/sup&gt;.
I went to bed unable to figure out what was going on, and just before I dozed
off realised that I must have the pins configured wrong. The next day I checked
the spec sheet and discovered that the pin with the number “1” silk-screened
next to it is in fact GPIO 0, not GPIO 1&lt;sup id=&#34;fnref:4&#34;&gt;&lt;a class=&#34;footnote-ref&#34; href=&#34;#fn:4&#34; role=&#34;doc-noteref&#34;&gt;4&lt;/a&gt;&lt;/sup&gt;. The pin the Pico was trying to
read data from wasn’t actually connected to anything, which is why waving my
hand near it was enough to induce a signal.&lt;/p&gt;
&lt;p&gt;Updating the code to use the correct pins made everything work &lt;em&gt;much&lt;/em&gt; better
and I started to get sensible readings. At this point I came across the
&lt;a href=&#34;https://www.waveshare.com/rp2040-zero.htm?sku=20187&#34;&gt;RP2040-Zero by Waveshare&lt;/a&gt;,
which is not only a smaller, cuter, cheaper Pico, but has silk-screened numbers
that actually match the GPIO pin numbers (plus an actual a reset button!). I
immediately bought several, and switched the prototype over as soon as they
arrived.&lt;/p&gt;
&lt;p&gt;The rest of the prototyping was reasonably uneventful. I used a little OLED
screen I had sitting around from a past Ali Express order, and once again
there were several python libraries to handle it. Soon enough I had raw
weight readings from the load cell (which was stuck to my desk with painters’
tape) being displayed on the screen.&lt;/p&gt;
&lt;p&gt;The load cells don’t measure absolute weight, so you have to “calibrate” them
by remembering the reading when there is no load, and then applying a scaling
factor to turn the raw reading into a weight. I worked these out by putting
a known weight on the business end of the load cell, and then hard-coding the
numbers.&lt;/p&gt;
&lt;h3 id=&#34;an-interruption-to-deal-with-interrupts&#34;&gt;An interruption to deal with interrupts&lt;/h3&gt;
&lt;p&gt;One thing I noticed with the MicroPython libraries for the HX711 is that they
relied on polling the data pin to see if there was any data to read. The way
the HX711 communicates is by pulling the data line low when it has data; you
then have to pulse the clock line to get it to shift a bit of the reading out
over the data line. The HX711 I have operates at 10Hz by default&lt;sup id=&#34;fnref:5&#34;&gt;&lt;a class=&#34;footnote-ref&#34; href=&#34;#fn:5&#34; role=&#34;doc-noteref&#34;&gt;5&lt;/a&gt;&lt;/sup&gt;, and
reading the data takes almost no time at all, so the most “efficient” thing
to do is to sleep for 100ms between readings.&lt;/p&gt;
&lt;p&gt;This is fine if you’re not doing anything else, but gets awkward if you also
want to refresh a screen at certain points, or check for button inputs, etc.
It also upset me to see the data line being low for so long when viewing the
logic analyser traces. The RP2040 supports setting interrupts on the GPIO pins,
but I couldn’t find anyone who was actually using them for the HX711.&lt;/p&gt;
&lt;p&gt;I therefore did the only sensible thing: wrote my own library, using interrupts
to monitor for data availability. It was pretty straightforward, but didn’t
actually work consistently. Looking more closely at the other libraries, they
all do &lt;em&gt;something&lt;/em&gt; to try to increase the speed at which the clock signals are
written&lt;sup id=&#34;fnref:6&#34;&gt;&lt;a class=&#34;footnote-ref&#34; href=&#34;#fn:6&#34; role=&#34;doc-noteref&#34;&gt;6&lt;/a&gt;&lt;/sup&gt;: some were disabling interrupts, others were using assembly. I,
again, did the only sensible thing: I threw all the python away and wrote a new
driver in &lt;a href=&#34;https://tinygo.org/&#34;&gt;TinyGo&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;My new code is event driven: it adds interrupts for button presses, and one for
the HX711 data line. When the data line is pulled low, it removes that
interrupt (so it doesn’t fire for every bit of data we receive), does the
reading logic, then re-adds the interrupt. Theoretically if you spam buttons
at an inopportune time you could mess up a reading, but the reading 100ms after
would be fine. So my code spends most of the time idle, which translates to very
little power draw.&lt;/p&gt;
&lt;h3 id=&#34;user-experience&#34;&gt;User experience&lt;/h3&gt;
&lt;p&gt;While prototyping I was using some standard small push buttons to navigate the
user interface I was creating. I soon realised that if I needed to enter
weights on the real device I wasn’t going to be happy poking an annoying little
button hundreds of times, and I didn’t feel like coding anything more elaborate
to make input easier. Instead, I switched to using a rotary encoder. This is
a bit like a variable resistor, but it can rotate completely freely, and sends
a signal when it’s turned. It also has a button built in, so you can press it
down to select things.&lt;/p&gt;
&lt;p&gt;It took me a while to get the hang of the rotary encoder: it has two data pins
for turning, and you have to wait for a falling edge on one pin and then
immediately read the other to figure out which way it’s turning. My initial
attempts at doing this weren’t quite immediate enough&lt;sup id=&#34;fnref:7&#34;&gt;&lt;a class=&#34;footnote-ref&#34; href=&#34;#fn:7&#34; role=&#34;doc-noteref&#34;&gt;7&lt;/a&gt;&lt;/sup&gt;, so I ended up with
somewhat random data. Trying to select a number when going right sometimes
increases it and sometimes decreases it is an exercise in frustration.&lt;/p&gt;
&lt;p&gt;The correctly functioning rotary encoder makes it much easier to input numbers
and change settings. I ended up with a very simple menu system at the bottom
of the screen which lets you cycle between three options: setting the spool
weight, zeroing the scale, and calibrating it. Zeroing is the most
straightforward option: it simply reads the current value, and saves it as the
zero offset in the flash memory. Selecting spool weight enters a mode where
turning the rotary encoder increases or decreases the spool weight by a gram at
a time; pressing the encoder in saves the value to flash and exits the mode&lt;sup id=&#34;fnref:8&#34;&gt;&lt;a class=&#34;footnote-ref&#34; href=&#34;#fn:8&#34; role=&#34;doc-noteref&#34;&gt;8&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;
&lt;p&gt;Calibration is a bit more confusing. Changing the spool weight changes the
value you see on the screen directly and predictably. Calibration instead
affects the “scale” value you can’t actually see; you just see the effect
of the scaling on the weight reading. Still, if you have a known weight on
the scale you simply rotate the encoder until the right weight is displayed
on the screen. Pressing the encoder saves the value to flash as with the other
modes.&lt;/p&gt;
&lt;h3 id=&#34;putting-it-together&#34;&gt;Putting it together&lt;/h3&gt;
&lt;figure class=&#34;image right&#34;&gt;
  &lt;picture&gt;
      &lt;source srcset=&#34;https://chameth.com/filament-weight-display/protoboard.avif&#34; type=&#34;image/avif&#34;/&gt;
      &lt;source srcset=&#34;https://chameth.com/filament-weight-display/protoboard.webp&#34; type=&#34;image/webp&#34;/&gt;
      &lt;img src=&#34;https://chameth.com/filament-weight-display/protoboard.jpg&#34; alt=&#34;Components mounted onto a protoboard&#34; loading=&#34;lazy&#34; width=&#34;500&#34; height=&#34;626&#34;/&gt;
  &lt;/picture&gt;
  &lt;figcaption&gt;&lt;p&gt;The final assembly&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;The final step was to assemble everything in a way where it would be usable,
and wires wouldn’t keep falling out whenever you looked at it. I found some
cute little prototype boards that would just about fit all the components on –
I left the OLED screen and rotary encoder off so they could be mounted to the
front of the box.&lt;/p&gt;
&lt;p&gt;I obviously 3D printed the enclosure, because I own a 3D printer and therefore
spend a lot of my time 3D printing parts for my 3D printer. In my first prototype I
put raised areas on the back panel and put some heat-press inserts in them,
intending to screw down the protoboard. The screw holes I was going to use,
however, were underneath the soldered-down RP2040-Zero and HX711. I instead
uninserted the inserts and simply put some screws through the back panel with
the intention of slotting nuts under the components. This turned out to be both
incredibly annoying and entirely unnecessary; the board sits at the back of the
box on its own, and there’s no real danger from it having a bit of freedom.&lt;/p&gt;
&lt;p&gt;While I was prototyping I was powering the circuit from the USB port on the
microcontroller, but for the actual unit I added a buck converter and ran a
cable from the 3D printer’s power supply (which outputs 24V). This has the
handy side effect of turning the scale on and off with the printer. I’ve
recently bought a bench power supply, which made testing this part a lot easier:
being able to dial in a voltage and current limit and then just plug things in
is great.&lt;/p&gt;
&lt;p&gt;The other thing that needed to change between my prototype and the final version
was the load cell. It needed to be attached to the printer in such a way that one
end bore all the weight of the spool (and, you know, not stuck to my desk with
painters’ tape). I was originally going to do something fancy with bearings,
but settled on the easier option of a spool holder which uses the same threading
as the original, so it slots straight in:&lt;/p&gt;
&lt;figure class=&#34;image full&#34;&gt;
  &lt;picture&gt;
      &lt;source srcset=&#34;https://chameth.com/filament-weight-display/spoolmount.avif&#34; type=&#34;image/avif&#34;/&gt;
      &lt;source srcset=&#34;https://chameth.com/filament-weight-display/spoolmount.webp&#34; type=&#34;image/webp&#34;/&gt;
      &lt;img src=&#34;https://chameth.com/filament-weight-display/spoolmount.jpg&#34; alt=&#34;3D printed spool holder with embedded load cell&#34; loading=&#34;lazy&#34; width=&#34;1000&#34; height=&#34;738&#34;/&gt;
  &lt;/picture&gt;
  &lt;figcaption&gt;&lt;p&gt;The load cell mounted as part of a spool holder on the printer.&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;With all of this done, I invented a complicated mounting system to keep it
attached to the printer. Any resemblance to blue painters’ tape is entirely
coincidental.&lt;/p&gt;
&lt;h3 id=&#34;bill-of-materials-and-sources&#34;&gt;Bill of materials and sources&lt;/h3&gt;
&lt;p&gt;Here are the major components that I ended up using:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Part&lt;/th&gt;
&lt;th&gt;Source&lt;/th&gt;
&lt;th&gt;Cost&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;RP2040-Zero microcontroller&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://www.waveshare.com/rp2040-zero.htm?sku=20187&#34;&gt;WaveShare&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;£3.15&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5KG load cell + HX711&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://www.aliexpress.com/item/1005005990833147.html&#34;&gt;AliExpress&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;£1.89&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Buck converter&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://www.aliexpress.com/item/32832061095.html&#34;&gt;AliExpress&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;£0.51&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SH1106 OLED module&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://www.aliexpress.com/item/1005005967766159.html&#34;&gt;AliExpress&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;£1.70&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Rotary encoder&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://www.aliexpress.com/item/1005005973850924.html&#34;&gt;AliExpress&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;£0.80&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mini PCB prototype board&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://www.amazon.co.uk/dp/B09X1DMSYZ&#34;&gt;Amazon&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;£1.49&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Where things come in packs of more than one, I’ve listed the cost of one unit.
I’ve not included things like wires, connectors, or the filament used in
printing the enclosure as you can use whatever you have to hand.&lt;/p&gt;
&lt;p&gt;The source code I wrote is &lt;a href=&#34;https://github.com/csmith/gorp2040&#34;&gt;available on GitHub&lt;/a&gt;,
and the designs for the 3D printed parts are &lt;a href=&#34;https://cad.onshape.com/documents/ccd44795b969ab9fcd0a9722/w/753c45e468de6247c6c31aa9/e/a7a698a0dc8a49767764053f?renderMode=0&amp;amp;uiState=656d12a3f305150149b205cc&#34;&gt;shared in OnShape&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr/&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34;&gt;
&lt;p&gt;Among many, many others, of course. &lt;a class=&#34;footnote-backref&#34; href=&#34;#fnref:1&#34; role=&#34;doc-backlink&#34;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34;&gt;
&lt;p&gt;I can’t actually find where I saw this original project now, but there
are quite a few kicking around if you search. &lt;a class=&#34;footnote-backref&#34; href=&#34;#fnref:2&#34; role=&#34;doc-backlink&#34;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:3&#34;&gt;
&lt;p&gt;This happened at about 1am and I was tired and frustrated. That’s my
excuse, anyway. &lt;a class=&#34;footnote-backref&#34; href=&#34;#fnref:3&#34; role=&#34;doc-backlink&#34;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:4&#34;&gt;
&lt;p&gt;At this point I realised I’d made the exact same mistake the last time I
used a Pico. Fool me once, etc. &lt;a class=&#34;footnote-backref&#34; href=&#34;#fnref:4&#34; role=&#34;doc-backlink&#34;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:5&#34;&gt;
&lt;p&gt;You can change this to 80Hz by resoldering a resistor on the board, but
10Hz is already several orders of magnitude faster than I actually need. &lt;a class=&#34;footnote-backref&#34; href=&#34;#fnref:5&#34; role=&#34;doc-backlink&#34;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:6&#34;&gt;
&lt;p&gt;If the clock signal stays high for longer than 60ms it’s treated as
a shutdown signal by the HX711. This is somewhat unideal when you’re
trying to read data from it. &lt;a class=&#34;footnote-backref&#34; href=&#34;#fnref:6&#34; role=&#34;doc-backlink&#34;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:7&#34;&gt;
&lt;p&gt;Because of my very clever interrupt system. I wanted to do as little work
in the interrupt handler as possible, so I was just enqueuing an event
to be processed in the main loop. This introduced enough delay that I
wasn’t reading the second pin at the right time. The solution was to read
the pin in the interrupt handler and then just enqueue a “left” or “right”
event instead of my original “turning somehow, you figure it out” event. &lt;a class=&#34;footnote-backref&#34; href=&#34;#fnref:7&#34; role=&#34;doc-backlink&#34;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:8&#34;&gt;
&lt;p&gt;I was initially planning on hard-coding the weights for all the spools
I’m likely to use, and just having a way to switch between them. But the
thought of having to re-flash the device every time I bought a new type
of filament made me reconsider. Plus, it was way easier to not do that. &lt;a class=&#34;footnote-backref&#34; href=&#34;#fnref:8&#34; role=&#34;doc-backlink&#34;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</content>
    </entry>
</feed>
