Raspberry Pi Bed Warmer Controller

Andrew asked for a write-up, but this is probably shy of that. Feel free to contact me with questions.

The motivation for the project is that our house is cold in the winter, and it’s painful to go to bed without the bed warmer on. It’s difficult to remember to turn it on every night until it’s time to go to bed, but it takes a good 45 minutes to get nice and warm. The solution? A Raspberry Pi!

Sure, an entire computer is overkill, but there’s actually not an obvious solution that’s smaller. A simple lamp timer or X10 sort of device won’t work because it’s a soft-power switch. Even if you could make it turn on when power’s applied, it’s difficult to manually override.

The bed warmer has separate controls for each side, and this solution handles them separately. I started by wiring leads to one of the warmer controls. First across the switch contacts to be able to control and, and then also across the LED so that I could detect whether or not it was on.

I was able to determine that the GPIO pins on the raspberry pi should be sufficient on their own and I didn’t need anything fancy like a gertboard for this project. I ordered a pi breakout cobbler as well as a dish and solderless breadboard and some jumper wires from Adafruit. I bought a giant pack of resistors from Amazon.

I started with a sainsmart relay module to close the contacts on the switch. I initially figured I could do it with a transistor, but I was worried about interference and strange things happening if I tried a common ground between the Pi and the warmer. I ended up needing some NPN transistors anyway because 3.3V wasn’t going to flip the relay, but the +5V available on the GPIO worked fine.

There’s a ton of ways to access the GPIO pins on a Pi (Python seems to be the most popular). Probably for the purposes of this project the /sys interface and a bash script would have been sufficient, but being the C kind of guy that I am, I was very happy with the well-documented and very robust BCM2835 C library.

After demonstrating that I could flip the relays and turn the warmer on and off, I set about figuring out how to read the LEDs. Once again, I could use a transistor, but I was still worried about interference. Some searching on the internets led me to the wonderful world of optoisolators. I’d never heard of such a thing, but it’s exactly what I needed.

Unlikely the NPN transistors I was able to pick up at the Radio Shack in Woodland Park, optoisolators turned out to be more difficult to come by. I picked up a pair of NTE3083’s from a local store in Colorado Springs I had no idea existed, but they have a huge selection of components. the NTE3083 has a darlington step-up transistor which I don’t believe was at all necessary in my case, but worked just fine. I had to play around quite a bit to find a resistor value to power the LED side of the optoisolator that was just right. Too small, and the LED on the warmer would dim noticeably. Too high, and the optoisolator wouldn’t trigger. Once I figured that out by trial and error, I had a working prototype.

I wasn’t satisfied, though. The clicking of the relays was annoying, and I didn’t want to be woken up by them. (One of the design goals is that if we forget to turn a warmer off, the Pi can do that for us as well, because it’s seriously annoying to wake up at 1am drenched in sweat because you forgot to power the thing off.) Fortunately, my discovery of optoisolators would work well for activating the switch as well. I ordered some more optoisolators from Amazon.

A week later they still hadn’t arrived and I checked the Amazon order status. I failed to notice they were being shipped from Hong Kong and were scheduled to arrive at the end of December. So I gave up and ordered from Radio Shack. This time I went with an NTE3086, which had two opto-isolators on a single 8 DIP IC. Perfect.

Today I finally got around to testing with that. The only problem with this setup is that I used the same color leads from both sides of the switch contacts, because with a relay the order didn’t matter. Now that they’re going through a transistor, it very much matters. It was even simpler to connect the optoisolators than the relays (especially with the very nice and easy-to-locate datasheets that NTE puts on the web), and so I was ready to convert the prototype into something more functional.

I got a solderable breadboard that’s nearly identical to the solderless one I had so transferring the layout would be simple. Were I planning ahead, I would have put the solderable breadboard on top of the solderless one (as it was designed to do), because then you can just lift the solderable one up, flip it over, solder the connections and be done. As it was, I had to transfer it all without forgetting what went were. Not a big deal, but I’ll know if I ever do this sort of thing again.

I’d also spent an insane amount of time ordering some 22 AWG solid-core wire, because threading stranded wire through breadboard holes is a pain. I finally found what seemed like the best value on Amazon and ordered it. When I went to use the wire today, I discovered it’s stranded! I went and looked at the Amazon order and the one I ordered is clearly labeled “stranded”, though the solid core version looks exactly the same.

Anyway, after a day of soldering, modifying the second warmer controls, and then fleshing out and cleaning up the code, it’s done and it works! It’s the first bit of electronics I’ve ever created, and if it weren’t for the existence of the raspberry pi, its great documentation and an internet full of people messing with it, it probably would never have occurred to me to even try it. I really enjoyed hacking on hardware for a change, and I’m guessing that there’s more projects to come.

The source code is nothing fancy and contains nothing non-obvious, but if you’d like to take a look, I put it up on github.

Screw you, Jason Jones

On the very episode of the Daily Show that takes 60 minutes to task for not bothering to fact check their interviews, the Daily Show airs a segment that’s either demonstrative of their own laziness or ignores the facts of a situation in order to score comedic points.

The segment revolves around John Morse, who was recalled for supporting entirely sane legislation that required background checks for conceal carry permits and limited legal magazine capacity to 15 rounds. They interview John Morse, which was just fine. But then, Jason Jones wanders the streets of Denver and asks residents if they voted in the recall election. All but one say that they didn’t vote. Why didn’t they vote? BECAUSE THEY WEREN’T ELIGIBLE TO VOTE. John Morse’s district is a small subset of El Paso county, in Colorado Springs, and those are the only people who got to vote in the recall election. The dude who claimed to vote (for the recall) was probably lying, but it’s possible he was a Colorado Springs resident who just happened to be in Denver when Jason Jones was there. Denver is extremely liberal and makes up the majority of the people who supported the legislation, and exactly 0% of the people who were even eligble to vote for the recall.

So, screw you, Daily Show. Next time you want to make fun of my state, how about you actually take the time to get it right?

AMD K6-400

In the summer of 1999, I bought a computer with my own money for the very first time. I picked it up second-hand from Peter for some amount of money that amounted to a large portion of the money I made that summer working in the library with Todd, throwing books. Included was a motherboard, RAM, CPU, and a graphics card. When I picked it up from Peter’s apartment, he informed me after I gave him the money that he’d accidentally scraped the key lock diode off the motherboard, so the key lock wouldn’t work. I was annoyed, but it’s not like I needed the key lock for anything.

I needed a case, because my Gateway-2000 486/33 with the 83mhz Pentium CPU in the upgrade slot was in an abnormally small case with a gateway proprietary form factor. I drove down to a local shop in Irving and spent $40 on the least-ugly case they had. I also ended up having to buy a 10-base-T ethernet card as well, because the ISA card I had wasn’t going to work.

The CPU was an AMD K6-2-400mhz, and it was insanely fast. It was the first thing I ever over clocked (lots of jumpers were involved), but it would post at 500mhz and seemed stable at 450mhz. When I went to Rome that fall, Sydney needed a computer to go to college, and I wasn’t going to need mine for a long time. I made an agreement with Dad that I’d send it to Sydney then, and when I got home from Rome, he’d help me buy a new one.

It was Sydney’s computer for years. She somehow managed to fry the onboard ATA controller by installing a CD burner with the system powered on, but it treated her well. When she got accepted to law school, she needed a laptop and agreed to mail the computer back to me.

I installed OpenBSD on it, and turned into a router. It’s been my router for the last 6 years or so, and has served me with very few problems. Today, I have retired it.

When I got home this evening, the power had gone out at somep oint during the day. The BIOS on that motherboard has no option to automatically power on after a power failure, so it was unsurprisingly powered off. But when I pushed the power button, nothing happened. Played with it for awhile, and it would try to power on, but fail. Clearly the power supply had died. I nearly just replaced the power supply with a spare I’ve got lying about, but didn’t for a couple of reasons. (1) The system clock is flaky. Sometimes it gets confused on boot, and despite the ntp daemon’s best efforts, the clock gains time at a ridiculous rate. (2) the aforementioned lack of a reutrn-to-previous state option in the BIOS after a power failure, and we get a lot of power failures.

So I pulled the hard drive and network cards out of it, and stuck them in a Dell Pentium-4 that I’d gotten for free when the USAFA contract ended in 2007. After resolving a minor IRQ conflict with one of the network cards, the OpenBSD install booted right up, found the network cards, did the PPPoE negotiation for the DSL, and everything is back. Way easier than I would have thought.

Rest in peace little AMD. You’ve served me well.

Columbia, MD

As we pulled up to the Sheraton in Columbia, MD, at midnight, on a Sunday, I remarked that there were an insane number of people sitting around outside smoking. In fact, the streets seemed to be lined with what appeared to be drunk degenerates. My coworker hypothesized that maybe there was some sort of comic-con sort of thing going on. It didn’t add up. When we checked in, I asked at the front desk what was going on. “Some concert.” “Who?” “I don’t know.” I asked 5 people at the hotel, finally someone said, “Phish.”

Apparently they played the last couple nights at the Merriweather Post Pavillion. Now it makes sense. What does not make sense is the two bottles of water in my hotel room. One is complementary, the other is $4.