The Bug Hunt

A few years ago, someone’s project came up on my Twitter Feed (or elsewhere — it’s been a while, and I don’t remember with certainty) that caught my interest. This happens with an alarming frequency, but most of the time I can stifle the interest sufficiently to avoid ordering all the parts. Our house is littered with projects that I have bought the parts for, but never completed. Projects that are born of my own fevered brain, especially those whose inspiration is a really nifty part or gizmo I’ve come across, are especially susceptible to this fate. And the Classroom Clock started out like many — I purchased the necessary parts, and then they sat there for a couple of years.

But unlike so many others, this one did eventually come together. Probably at least in part because it was given as a Christmas gift to my wife, Susan, a middle school science teacher. It took some work to get it all together, but then the problem was that the kind of schedule it was originally programmed for didn’t really mesh well with the schedule at Susan’s school. Once I began to get familiar with the code, I realized I didn’t like it very well, so I rewrote most of it from scratch, in a somewhat more generalized way. This past year, I made some more minor updates to it, basically to make it easier to update the schedule and calendar from year to year. The official school clock seems to drift more than the Chronodot that’s at the heart of the Classroom Clock, so periodically I have to re-program the time. The original project didn’t have any means for user input, so there is no way to manually change the time on the clock. In fact, the only way to change the time is to reprogram the clock, and the only way to “synchronize” the time is to calculate exactly how long it takes to upload the code to the clock, and hard-code an appropriate time in the program. Argh!

My contribution in this area was to write a completely separate program that can be uploaded to the clock, with which you can interactively set the time. Then, you reload the normal clock firmware which no longer attempts to set the clock at all, and everything is good.

So one time in the fall, Susan’s students apparently wanted the clock to display in 24 hour time. This is of course an easy change. The Chronodot tracks time in 24 hour mode, so it was just a matter of not subtracting 12 from the hours.

Recently, the delta between the official school clock and the Classroom Clock got to be large enough to be annoying, so Susan asked me to come adjust it. We ended up bringing the clock home, and it was approaching 9 p.m. when I got around to looking at it. I wasn’t paying attention to the actual time, but when I powered up the clock, it said something like 10:43! It had always been completely reliable, so I was mystified as to why it would display a completely random time like that. After a few minutes, I realized that the minutes were correct, but why were the hours off by 2? That was a bizarre mystery.

A little while later, it finally dawned on me what the problem was. The clock might have read 10:43, but that’s only because it was in fact not designed for 24 hour time. The digit for tens of hours was not a full seven segment digit, but rather just the two rightmost vertical segments — an engineering shortcut if ever there was one! The code in the clock, when deciding what to display there, would turn both segments OFF if the hours were less than 10, and both segments ON otherwise. So, it was doing its darnedest to display 20:43, but couldn’t. And of course I was not thinking about the fact that it ought to be in 24 hour mode — I just saw 10:43 and eventually decided it was off by 2 hours somehow.

I asked Susan if she’d ever noticed it being wrong like that before, and she recalled that perhaps she had. When pressed, she remember that it was during parent-teacher conferences, in the evening. One of the only other times anyone would have been looking at the clock after 19:59.

It’s easy to see how a bug like this could cause lots of head scratching, because it would be easy to report the problem as “sometimes the clock is off by 2 hours” and leave it at that. And you’d be left poring over the code, trying to figure out how a simple math error could occur occasionally and seemingly randomly.

In the end, we decided to set the clock back to 12 hour mode.

I’ve long had a Version 2 of the clock in my brain. I’ve constructed it so that the “brains” of the clock can be transplanted while leaving the display parts intact. The brains for V2 will run on a chip that provides WiFi connectivity and runs microPython. It will therefore be able to:

  • query a timeserver on the internet for the actual time
  • periodically download a configuration file, which can have the calendar, schedule, and an offset to apply to the real time, so the clock can match the official school clocks

The hope is to write the code in a flexible enough manner that the config file can provide lots of different ways of arranging schedules and using the “extra” digit to denote the period, or day, or whatever.

And now I realize there ought to be a V2 of the display hardware as well, which would have a full digit for tens-of-hours to allow for 24 hour time, and also some form of explict PM indicator for 12 hour mode.

Some day…

EDC

If you weren’t aware EDC stands for Every Day Carry — the things you keep with you all the time so they will be handy. Here’s what I tend to carry on my person (thankfully, my pants have good pockets):

Top row includes:

Bottom Row:

And about in the middle we have the Nokia Go step tracker. Of course when I got it, it wasn’t Nokia, it was Withings, but they were purchased by Nokia.

Maybe someday I will do a backpack dump, but that would take a lot more work.

Hello, World!

When you start programming, or pick up a new programming language, often the first program you write is referred to as a “Hello, World!” program, because for the most part all you want to do is be able to produce a working program, so printing something like “Hello, World!” to the screen often feels like a great start. Once you have that working, you can expand upon it.

So we have a MOD-t 3-D printer that we bought a couple of years ago, and I’ve printed a bunch of things on it, but they were all things that other people designed. I’d always wanted to be able to do my own designs, and had two particular projects in mind. One is a part of a cover for a Starbucks travel mug. I have one that I really like, but the small piece which closes over the mouth hole keeps coming off. It doesn’t really stay in the cover, and is constantly at risk of being lost. So I’ve wanted to create a replacement. But that would seem to require considerable design skill. On the simpler end, I have a portable phone charger that I carry, which doubles as a flashlight. I like it, but periodically the light will come on in my pocket, and I may or may not notice. If I don’t, the battery will die. So I’ve wanted to create an end cap for it, to protect the switch from being pressed accidentally by all the other things in my pockets.

And so I have! I created such a cap using the program OpenSCAD which allows you to design things by describing them with code. For this particular item, it is essentially 3 things: a pretty flat cylinder for the base, a hollow cylinder for the body, and another hollow cylinder that sits just inside the larger one, which is very small to make a tiny ridge inside the body, enabling the cap to “snap” fit on the device at its seam. On the 8th try, I have something I am now happy with:IMG_2764

And I have “published” this design to a site called Thingiverse, which is the biggest repository of shared 3-D designs on the web. We’ll see if anyone else finds it useful.

Whither Weather?

A long, long time ago, we had an amateur weather station (Oregon Scientific WMR-968) at our house. It had a wind vane/anemometer; a rain gauge; an outdoor thermometer/hygrometer; and an indoor thermometer/hygrometer/barometer. It came with a nice LCD display, and all the instruments communicated their data to the display wirelessly. The instruments also had a small solar panel, and a battery compartment, all weather-tight. The solar panels charged a built-in pair of small rechargeable batteries, and the batteries would power the instrument and the radio. There was also room for you to install fancy/expensive Lithium AA batteries which would allow the instruments to work down to -40 F. The console could be connected to a computer as well, and the computer could run software to gather the data from the instruments, log it, and even post it on the internet! We ran our own little weather site, a sub-domain of tastewar.com, but also posted the data to some other sites, notably The Weather Underground. (Not to be confused with the Weather Underground). It was fun knowing that we were helping to provide a “public service” and conceptually having all that weather data on file.

Well, eventually (after a good number of years), the instruments began to fail. I think a big part of it was the built-in rechargeable batteries. I made a half-hearted attempt at building new battery packs from rechargeable cells I bought on eBay, but never really succeeded, and the station fell into disuse until it was only a clock (yet another clock that had to be reset whenever the power went out). And long before that, the PC that had been logging the weather and posting it to the internet had been replaced with a Mac, and I never took the time to find good Mac software to do the same thing. So we’ve been out of the weather picture for a long time. But it’s always been on my mind to get back in the game.

This Christmas, I used my Christmas money to buy an inexpensive weather station from Costco.

It’s an Acurite 5-in-1 with a snazzy display.

It provides the same basic instruments as the old station, but all the outdoor instruments are housed in a single package. This certainly makes installation easier, but the downside is that the location for each instrument is somewhat compromised. Your anemometer/wind vane is supposed to be up as high as possible, away from any obstructions. Temperature readings, on the other hand, are supposed to be taken at four feet above ground, and the instrument should be out of direct sun, yet away from buildings, etc. Similar for the rain gauge, etc. Oh well! I am just excited to have a weather station again!

The console for this station can also be connected to a computer, and of course, you can run software on the computer to log the data, post to the internet, etc. This time, though, it’s not connected to a big, traditional PC, but rather to a Raspberry Pi,

so it’s very unobtrusive. We are using Meteohub software which is the only Linux package I could find that supports this station. You can view our weather data at The Weather Underground. Someday, we may re-create our own weather site as well.

Winter Hobbies

During the good weather, I enjoy riding my bike a bit with my free time, but in the winter I am often de-motivated. That makes it a good time to focus on one of my other hobbies: electronics. I had a pretty fruitful weekend (so far!) on the electronics front. For Christmas, I had bought Tyler a “Game of Life” kit. This isn’t the board game you are likely thinking of, but rather a one (or zero, depending on how you look at it!) player computer simulation of a colony of organisms. A grid of cells is represented by LEDs, and their death or birth is dependent on the level of crowding in their neighborhood. Tyler did a great job soldering the kit together, I think we counted over 100 connections had to be soldered! Certainly, the most challenging project he’s put together thus far.

Trouble is, although you can connect multiple boards together (very clever!), they do cost $$ and a single board ends up with very fleeting generations. I thought to myself, “Well, since this is a board with a software programmed micro-controller, I ought to be able to change the delay between generations!

That idea ended up causing me a lot of work (and/or expense…). First, I had to build the AVR programmer kit that I’d bought previously, figure out how to install a driver for it (on my Win64 system), install all the AVR dev tools, solder a programming header on the board, figure out just enough to be dangerous, mod the code, and upload the new firmware.

Happily, this all worked pretty well! Except for the final step. It should be obvious, but I can’t figure out where the delay between generations comes from, ultimately. But, in preparation, I did all the rest of the above, along with re-building the current firmware, and just reloading that.

I’ve posted a question or two in the Adafruit forums on where the delay might be coming from, so hopefully someone will help me out there.

Sign Switcher

For our church pageant, we retold the Christmas story in the guise of a Christmas Trivia game show. There was going to be a person responsible for holding up signs like “Applause!” etc. but I thought to myself, “I have some scrolling LED signs. I bet with a little effort, I can build/program a device to let someone select from a list of pre-defined messages.” And it turns out, I was right! Pictured below is a slightly updated version of the device. It now has a (lighted) power switch, to save battery, and the Display on/off switch has been upgraded from a bat handle toggle to a nice rocker. Oh, and I changed the messages to some that could be used in a sermon…

20120111-205156.jpg

So intuitive, even a (very bright) dog can use it 🙂

Useful

On Thursday (2 days ago) I ordered an electronics prototyping kit based around an Atmel ATmega8U2 microcontroller. The kit is called an Arduino, and I ordered it from Adafruit Industries (funny name, I know), and paid for UPS ground shipping. I’m glad I didn’t pay for 2-day or 3-day “Priority” shipping, because it arrived Friday, the very next day.

The hardware is “open source” and there are many freely available open source tools for programming it. Tyler and I played around a little with it last night, and made it blink an LED. I played a little more after he went to bed and made it light up a series of LEDs in various patterns. Cute. The programming environment is C-based, so it is pretty familiar to an old programmer like me. Today (Saturday), I spend a couple of hours (chopped up into 5, 15 or 30 minute increments) and was able to make something, well, useful. It also uses a separate LCD display that I also purchased (seemed like it could be a fun add-on), and a temperature sensor that came with the kit. Using the display meant also using my nice new soldering station to solder 21 connections! Here it is:


It is a thermometer that displays the temperature when you press a button. It displays for 5 seconds, then the display turns off to conserve the battery.

I was partly inspired by a friend who also bought a kit and has been enjoying it. I had heard of Arduino starting a few years ago from the Make: blog and magazine. It is very popular among hobbyists and artists of a certain bent. It has lots of useful means of interacting with the real world, and a bevy of enthusiasts who have contributed lots of code and made add-on hardware for the platform. We have plans for a much more involved project, but for now, these little steps are still exciting.