I’ve been pretty busy with skiing, but have made some good progress. I’ve played around a bit with the available commands, and have made a few decisions.
First, I’ve decided to use the xbees in their simple serial replacement mode. In this mode, it just acts like there’s a serial cable between the two modules. The more complex stuff looks interesting for future stuff.
Second, I’ve figured out what I want to do to handle the handshake between the two devices and how to structure the code. I’ll share some code when I get it written.
Base station:
- The main loop will constantly send out a heartbeat with the current status of the lights. It will send “EG0†if the lights are off and “EG1†if the lights are on, at an interval of 1 second. I’ll either do the loop with a simple delay routine (delay_ms() from the standard library), or I’ll piggyback on the short-period timer that I’ll use to debounce. Probably the former.
- The interrupt service routine for the xbee will look for commands and process them. If it sees S0 it will turn the lights off, and S1 it will turn the lights on.
- The interrupt service routine for the pushbuttons (“all onâ€, channels 1-3 on individually, “all offâ€) will handle servicing the buttons. I’ll probably use the short-period timer to debounce the pushbuttons
- The interrupt service routine for the long-period timer will handle turning the lights off after a time period.
That’s going to use up most of the capability of the 2313 I’m using. I decided to do 3-5 output channels, each with a dedicated 30A relay to do the actual switching. The relays will be driven off of the avr using a transistor to get the necessary current, which is something like 200mA, far more than you can get from an AVR.
The xbee unfortunately runs on 2.8-3.4V, not the 5 volts I bought for the power supply. The adapter boards that I bought down-regulate the voltage, but I don’t want to waste them on a project like this. I could put a nice 3V regulator on it if I have it, but I’m thinking of just putting three silicon diodes in series, which would give me 0.65 * 3 volts – almost perfect – and it will work fine assuming I don’t pull too much power through them.
Remote station:
This one is going to go in a tiny project box, which an on/off switch, a link LED, a status LED, and a pushbutton. I’m going to fit all that into a tiny project box, along with two AA alkalines (or maybe AAA if I don’t have the space).
The code will be something like the following:
- On startup, blink the link LED a few times.
- On the interrupt service routine for the xbee, look for the EG0 or EG1 data. If it’s there, turn on the link LED, and turn on the status LED if the command was EG1. Set the short-period timer for about 900 mS.
- On the short-period timer interrupt, turn off the link LED. This will have the effect of blinking the link LED off for 100mS as long as the remote is receiving data from the base station.
- I’ll use the long-period timer to debounce the switch. On that interrupt I’ll send S0 if the current status is on, and S1 if the current status is off.
Lights
I mounted three sets of three lights on trees over Sunday, so this weekend I’ll be able to wire them up to the transformer and see what voltage I need to use for each zone.