This Time Self-Hosted
dark mode light mode Search

Quarantine Project: Birch Books Smart Home

By now, everybody knows we’ll be spending a few more weeks closed up in our houses, flats, or rooms. And so everybody is looking for new ways to keep busy. While I do have a significant number of incomplete open source projects to dedicate my time to, I also felt I needed something that was just for myself. So I decided to start what could be described as an “art project”.

A few months ago, I have bought for myself a Birch Books Lego set. It’s a lovely set, and I have a particular place in my heart for bookstores in general (despite having switched to ebooks many years ago). I wanted to take good pictures of it, particularly since I have a few macro lenses that should do it justice, but to do so I felt the need for lighting it up.

Now, you can buy light kits on Amazon for it (and for most other kits out there), but I wanted to do something. So I ended up buying a bunch of battery holders, white LEDs, and a box of assorted lego bricks for me to take a look at, for modifications. I also got lucky, and found a number of bricks the right color for the set.

And since I’m a geek and I love overkill solutions, I started thinking “can I make wire this to a microcontroller, and have it control the lights over time?” — Originally I considered keeping it aligned to the wallclock (as in, the time in the real world) but it turned out that it’s not that interesting to change so slowly — and it’s actually much harder. Having it cycle at a fixed speed is much easier, and with a couple of button controls you can do pretty much all you need.

As it turned out, I had most of the stuff I needed at home already: for Valentine’s Day, I ordered three heart-shaped LED kits on eBay (three because that’s how many they sold it as), that came with a microcontroller — a STC89C51, which are Intel 8051 compatible micros with 35 I/O ports. Back then I also decided I would like to try programming one for custom patterns, and bought a programmer/development board as well, and it came with another micro. While this seemed like a fairly niche micro, it made prototyping easy, since it’s a DIP micro, which I can just put on a breadboard.

The first problem I had with this was figuring out how to flash anything on the micro. What I found online suggested using a set of Windows tools that are only in Chinese. I then found another page, that suggests to just use SDCC and a tool called stcgal, which is Python command line tool that allows one-command programming of the micro. This worked great — the Special Function Registers are described in the datasheet, so it shouldn’t be hard to describe in a header.

So I turned to EAGLE first, and KiCad second, trying to figure out how I would layout what I need on a board, and couldn’t find the STC anywhere. And then I started thinking that maybe this is a clone of something else. A few Google searches later, I found the AT89S52 — which turns out to be exactly the same pinout and most likely the same registers as well. The STC89C51 is (mostly) a clone of the AT89S52. It does not appear to share the same programming protocol, and it actually appears to provide a list of additional capabilities and registers that the Microchip MCU does not have, but it does mean I can just write the code targeting the AT89S52, and be done with it.

Now let me remind you that I’m not particularly versed with electronics, so I’ll probably be making tons of mistakes throughout this experience. But I’ll also be trying to provide regular updates on how the project is going and, assuming I do make it to get it to work, I’ll be publishing all the source code, and any schematics I might end up drawing for the project.

I’m actually happy of having found out that the chip is just a Microchip/Atmel chip instead — because this increases not just the usefulness of me talking about the design, and opening up the sources, but also for myself as I would rather play with something that I can reuse later, rather than with some specific micro I just happen to have at home.

Also, I might end up designing a few alternatives for this anyway. The original draft of this blog post was written when I just started thinking this around, but I’m now putting a few more edits on it while having fleshed out some of my intentions for the project, and it might just be I’ll run with a number of different options around. We’ll see.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.