Ok as promised, some more details on the home automation setup I've been working on.
The first step was to learn about how RS485 worked, so I breadboarded up a MAX485 RS485 transceiver chip with my Arduino Eleven. That was enough to prove that I understood how to drive the chip.
RS485 (in multidrop mode) is a little harder than RS232. It's more like Ethernet really - everyone sits on the same two-wire bus, and only one can transmit at any time. If two nodes transmit at the same time, if one node is driving high while the other is driving low, the bus ends up in an indeterminate state. So - some sort of protocol is required to ensure that nodes take turn in transmitting, and if two nodes to transmit at the same time, it is detected and the transmision can be retried after some arbitration to work out who transmits first.
I've connected the MAX485 to the hardware UART on the Arduino, with the Tx and Rx enables connected to other digital outputs. The controls are pulled up to ensure that when the Arduino is reset, the MAX485 won't be transmitting on the bus, and the Rx line won't be driven by any data from the bus. This is important, otherwise software downloads wouldn't work, as the FTDI chip (or the Mega8U2 on the Arduino Uno / Eleven board) would be conflicting with the MAX485 driving the Rx line.
I could have avoided this by using a software UART on the Arduino, but I'm planning on pushing the CPU enough as it is, without trying to get high speed RS485 as well. RS485 can operate up to 1Mbps provided proper care is taken of the bus - i.e. termination, topology etc. I'm using passive termination at each end of the bus, and using a bus topology with very short stubs, over a pair of Cat5, so there's a good chance I can get close to that rate if need be.
Once I was happy with driving the MAX485, I was sick of wiring up the breadboard, so it was time to make something a little more permanent. This was the result :
This is a FreeTronics RF Receiver shield, which as well as holding a 433Mhz ASK receiver, also has a heap of prototyping space. Jammed in there is the MAX485, a DS1307 Real Time Clock chip, a connector for the LCD (shown), a connector for a DHT-11 Temperature/Humidity sensor (not shown), a connector for the 1-wire Bus (with a DS1820 temperature sensor attached), as well as wires for the RS485 bus (D+, D-, Ground)
The RF receiver just detects any CW signal around 433Mhz and drives an input pin on the arduino. A surprising amount of stuff uses this frequency and can be read from this board. X10 RF devices use it - so my WinPlus X10 remote is capable of sending hundreds of different commands to my software via this board. (I'm using the Arduino IR library to read the data in the same way that IR codes are read). Some home weather stations use this frequency to transmit their readings to the base station - I've got one but haven't been able to decode its bit stream yet.
The LCD module is used during debugging to dump things out the screen, it also hold a micro-SD card for file storage.
This board is my general protoyping board, it's not intended to be part of the final home automation solution.
The next board (which IS part of the final solution) looks like this :
This board also has a DS1073, MAX485, and connectors for the DHT11 and one-wire bus. And a connector for a Nokia 5110 84x84 pixel LCD. The LCD is removable - it's only there during development since this board (and more like it) will live in a box somewhere up in the roof.
The FTDI board (the small red PCB) is only used during download, and is removed later. The LCD board is also removed later. The LCD is very cheap (less than $10) but it's a 3.3V part, and I'm running everything at 5V, so I built a small 'debug' board that has the LCD, level converter, and some status LEDs for use in RS485 debugging.
Coming back to the main board - a bunch of the digital I/O lines and analog input lines aren't commited yet - there's room on the board for things like driver transistors so I can use it to drive large LEDs, or relays for controlling lights etc, or sensors.
The first goal for this board is to get it to read a bunch of temperature sensors via the 1-wire bus, and transmit the values back to another node via RS485 for display and/or logging. The server PC should be able to read these values too.
So right now - I've got both of these boards connected via RS485, with one board reading from the DHT11 Temperature/Humidity sensor, enumerating any sensors it finds on the one-wire bus, and then polling them all regularly and sending the readings to the other node via RS485.
The protocol (when I last tested it) was successfully detecting collisons and garbled transmissions, so I had semi-reliable comms between the boards.
That's enough for now - what would you like to see next?
I can give details of the RS485 bus protocol I'm using, or some rough circuit diagrams of the boards - or maybe some details on the final application, or what devices I could interface to these boards?
Steve