Friday, October 22, 2010

RF Remote Control Emulation

A few weeks ago I got one of these:


It's a remote controllable light switch that comes with an RF remote. The only light switch is across the room from my PC and it's a pretty large room. (The building's basically a 1-room apartment) so this works out great with the remote. Of course since I'm using the remote to cut the lights when I go to bed I'm basically using the remote from two places which brings with it the unavoidable annoyance of the remote being in the wrong place all the time. Which means I have to get up and look for it which is effectively as much of an annoyance as it was meant to solve. So I wanted a second controller that would basically be a stationary switch by my bed so I could leave the portable remote around the desk.
Call me lazy I won't even deny it.

I popped the original remote open to see what I was dealing with.


After some research I concluded that LP801B is a PT2262 clone which is a remote control encoder chip. Has a few address and data pins and generates a signal on the output pin based on the configuration of those at the time the enable pin is connected to ground.
At first I didn't think much of it and ordered some PT2262s and made a PCB which is basically a clone of the original remote adapted for components I had lying around (or just stupidly large pads where I had no idea what I was going to use when I made the board)


Not being patient enough however I started looking around to see if anyone's emulated this chip on a microcontroller before. Turns out, several people did.
So I took the code at http://www.mikroe.com/forum/viewtopic.php?f=13&t=10832 and ported it over to BASCOM for the ATTINY13.
I think that code has a bug though as the logic low component of the syncbit should be 31 times the short-pulse duration according to the datasheet not 7. (He's basically divided the datasheet units by 4 in case anyone actually looks into this) The decoders may not care as It seems to have worked for him. When I got mine to work I was using the datasheet-correct count so I didn't test with that. It took several modifications to my original board to get it working with the attiny. Had to put in 3 zeners as the PT2262 operates directly from 12v which the attiny can't do. I actually fried an ATTINY2313 the first time around because I forgot the two selector/power buttons that were still at 12v. If I knew in advance that I'd be able to do this I would've designed a much smaller board..

I was trying random numbers for the pulse duration and randomly tuning the white variable capacitor but with none of the parameters actually being correct this method was never going to work. After some wasted time I caved and connected the original remote's encoder chip data output pin to the microphone input of my netbook.
Then with the cool Soundcard Oscilloscope from http://www.zeitnitz.de/Christian/scope_en got this:
To which I could adapt my pulse duration.
At this point I tested my board and while tuning the variable cap it suddenly became dark in the room :) It took a few more iterations to get the delay "just right" but now it works perfectly.
I put it in a small electrical box with 2 push-buttons and installed it in an easy to reach location from the bed.


Some component leg that I forgot to cut (probably a resistor) must have punctured the battery wire though as it drained to 10v by that night and since the circuit is basically open when none of the buttons are pressed that shouldn't happen at all. I did find a puncture mark on the positive lead so that must have been it.. damn. After reseating the board in the box and making sure the battery wires don't pass under any component legs it hasn't happened again.

Project files:

Board
Very large. But the (somewhat smaller, by about 20%, still fairly large) version is on the browsing/printing PC upstairs and I'm too lazy to get it :) Note below on the jumper blocks:
[1] [2] [3]
No connection: FLOAT bit
1+3: Bit 0
2+3: Bit 1
1+2: Short out the battery
And that this PCB is for the PT2262 (and clones) so it needs modifications to be used with an AVR. At least 1 5.1V zener for the CHIPPWR and 1 per button.

The board runs off a 23A (12 volt) stack battery. Running from lower voltages may be possible but the RF circuit definitely needs to be retuned.

Schematic
Messy. The seemingly unconnected wires from the diodes on the data pins are actually connected to CHIPPWR.

PT2262 emulation code in BASCOM

Thursday, October 14, 2010

Water Heater Thermostat

I have a small(50L) electric water heater in my apartment. It was a cheapo and came with a mechanical thermostat. Just a few days after this was installed (and construction work still going on) I looked at the external thermometer and realized that the water temperature has dropped to a uselessly low level. So I went ahead and set the thermostat to 4 (out of 5). This made it go up to about 65C but in a day or so it was already below 50. I had to conclude that either the thermostat is broken or (what still seemed unlikely at the time) this type of thermostat either works completely unreliably when the cooling is slow or has a huge hysteresis gap that can't be changed or maybe both. So I bought one from a different manufacturer, installed it and got the exact same results. This is actually why I started looking into thermostats in the first place. Changing the pipe heater's was just a side-project. At first I considered just buying a capillary thermostat that higher-end water heaters use but decided against it because I've stumbled on the DS1821s.

It was important for this to a be a drop-in replacement for the original mechanical thermostat.
It was also important for it to be safe(ish) with at least one thermal overrun protection that isn't electronic. So I've designed a board that is essentially a relay driver adapter that the 1821 can control with a terminal block for connecting a thermal fuse. The first version looked this like:




The measuring tube in the tank turned out to actually be really narrow so I had to throw out that chrome rod and use smaller wire for the thermal fuse. It doesn't look as nice or tidy now but it fits. Here's a test fitting with the thick wire still and no fuse at the end:


The relay is an 8A DPDT. I was unsure about the reliability of the 1821 at higher temperatures so at first I've built an ATTiny13 based "debugger" that reported the temperature and the config register to a PC that I checked on from time to time. It seemed stable enough so I've been using this for a few days now and water temperature is pretty much constant :)

Board Eagle here
R6 - 2.2k
R8 - 10k

The board requires 5v and 12v DC and the AC for the water heater. Currently I'm using an external power supply in a modified wall adapter box.


Notes on soldering thermal fuses:

For a project like this a 98C or 104C SEFUSE or ThermoDisc G4 works nicely. They're small (size of a larger resistor) and can do 10A. They should be cooled (spray from some alcohol-based cleaner should do) and their leads held in a clamp or larger pair of pliers while soldering to keep them from reaching their cutoff point. Being quick also helps.

UPDATE: Safety modification
I've reencountered the problem that initially prompted me to build the ATTINY based debugging board. Apparently the 1821 can fail to enter thermostat mode when powering up.
Maybe it has to do with noise on the PSU during the initial stages of powerup and connection to mains that may be erroneously triggering Sensor-mode reset. I have no oscilloscope to see what's going on but the end result is that If the sensor fails to enter thermostat mode the boiler will overheat. Which is decidedly not a good thing. I can't reliably reproduce the problem but I'm going to assume that it's uninfluenced by the POL register and just basically makes the thermostat output stick at logic high. I've added an inverter and changed POL to 1. This way the 1821 is logic high once the upper threshold is reached, which is inverted to 0 turning off the heater. If it decides not to start up correctly sticking at logic high it just won't start heating.

UPDATE:
The above modification seems to have fixed the issue. I've had no problems with the system since.

UPDATE several years later: R.I.P
In hindsight.. this really wasn't a project worth doing. It was a good learning experience and it worked fine for years but then it started smelling worse and worse. My contacts weren't the right thickness for the heating element and it started to heat up and melt the plastic around it. I retired it and went back to the mechanical unit in the end. I'm not sure if it's just my imagination or if spending a few winters and summers outside helped smooth out the operation of the bimetallic switch but the thing seems to work better now.

Friday, September 17, 2010

Standalone DS1821 thermostat programmer



As a continuation of the previous project I decided to make a standalone gadget to program DS1821 thermostats. As mentioned before these devices are non-MicroLan 1wire thermometers capable of standalone thermostat operation. After configuration for thermostat mode the center (1Wire DQ) pin becomes a thermostat output pin. Since it's still an open collector pin it needs a pull up resistor, and since it's still basically a 4mA GPIO a transistor at least is needed to switch anything meaningful with it.

I've used the ATMega8 "devboard" that I used in the v1 heating cable thermostat. Made a plug in board for that (don't call it shield) with a couple of TIL311s, 3 buttons, some pullup resistors and a socket for the 1821s.


On the underside is an incredible mess of cables that I'm not going to show.
Buttons are Up, Down and OK

First it asks for the TL, then the TH 1 digit each (settable 0-9).
Then it'll display A0. with the 0 being switchable between 0 or 1. This is the POL (0 for heating 1 for cooling thermostat)
B0 similarly is the thermostat mode (0 = 1wire sensor 1= thermostat)
C0 is the negative setting. Since I'm only using 2 displays this is how I'm handling negative entry.
C0 = neither value is negative
C1 = TL is negative
C2 = TH is negative
C3 = Both are negative

Once OK is pushed here it'll program the settings and display 00
That's it!

Spaghetti BASCOM code can be found here

Any latching BCD display could be used in place of the TILs, these are just what I had lying around. Hookup can be determined from the source code. I have no schematics or pcb as I was just hooking stuff up on the fly and coding to adapt. Pullups needed for buttons and the 1wpwr and DQ pins. Most delays in the code are probably not needed.

UPDATE:

Congrats if you've read this far. Two things I'd like to add. This is a sideproject from the more useful application of the DS1821: Keeping my pipes from freezing in during the winter.

And I actually made two videos during the making of this that I didn't include because well.. They're dark and boring and I didn't think another blog(HackedGadgets) would pick up this particular project. Thanks Alan.
Well, here they are. If you're wondering no I didn't record it in the dark. Actually, the room was blasted with four 40W CFL tubes. This is just how bad my point-and-shoot is.

First one's just testing out the TILs counting 0-F on each. (and I called it shield.. d'oh!)





Second one shows the programmer working



Wednesday, September 15, 2010

Water Pipe Anti-Freeze Heating Take 2


With winter approaching I decided to simplify my water pipe anti-freeze system. The initial project here used an ATMega8 and an I2C thermometer. I replaced that with a single DS1821. This small device looks like a transistor but is actually a thermometer chip capable of standalone thermostat operation once configured via 1Wire.

The DQ pin becomes a thermostat output pin, which in my case is then used to control a transistor which switches the Heating On LED and an optocoupler which then switches the ATX PSU. The system looks exactly the same from the outside and I'm not taking pictures of the inside as it's basically just the schematic above implemented on a piece of stripboard with the DS1821 at the end of some telephone cable running a few meters under the insulation putting the thermostat where the yellow tape is on the picture below.


Note that the DS1821 is NOT a MicroLAN capable device, it doesn't support the protocol required for MicroLan enumeration/operation. It also cannot be connected to my 1-Wire MicroLan modded Fonera. To program it I used an ATTiny2313 and some ugly hacked-together piece of BASCOM code. The 1821 has to be hooked up according to the pins configured in the code (the bottom 3 pins on the left side of the chip by the way, I basically just put 3 pins from an ic socket there to hot-swap the devices.) pullups then need to be added to DQ and Vcc(4.7kohm will do). Also configure the fusebits to use the internal osc of the ATTiny with the clock divider disabled, setting it to run at 8MHz.

The ATTiny's UART then needs to be connected to a PC. To program first issue a read command.

>read
temp:0
conf:84
TH:10
TL:5

This device is already configured for my pipe-heater. The temp will be 0 because we haven't issued a Start command to the chip. For info on the conf register byte consult the datasheet.
TL is the low threshold TH is the high threshold.

the set command configures the device. It'll just ask for TL and TH, then print out the read-back values for verification.

>set
TL:5
TH:10
5
10

deploy then ends the configuration of the device

>deploy
POL1
Thermo1

POL is the POL bit in the config register. It determines whether the Thermostat output is active-low or active-high. Simply put: you use POL0 for heating and POL1 for cooling.

Thermo1 actually switches the device over into standalone thermostat mode. If you set 0 here the device will remain in 1Wire mode.

When the device is in thermostat mode it can't communicate over 1Wire anymore unless a specific reset sequence is performed. The read command in the code automatically performs this sequence if the device doesn't respond. It will mark this with ".." so if you see .. .. .. .. it means the device isn't responding despite that and you should check your connections :)

As always, leave a comment if you end up building this.