Choosing a protocol for Home Automation over RS485

Hi, I'm developing a home automation system for my home with many Arduino Pro Mini boards connected trough a rs485 bus. I need an application protocol running on top of rs485 that has some kind of addressing, an error correction and it's easy to use (I'm not an expert neither in electronics or communications).

By now I play with Modbus RTU protocol and the library for the Arduino (http://sites.google.com/site/jpmzometa/arduino-mbrt).

Is there something better than that? Maybe something that is made especially for the home automation scope, like BACnet, xAP, xPL? I need something that is already ported to Arduino.

Thanks in advance.

Anybody? :frowning:

For error detection, I'd be inclined to use a credit allocation flow control mechanism. Basically everything you send has a register/memory location and data to go with it. The first device (sending the data) sends an 'S' for send, the register/memory location, and then the data. The other device responds by sending 'A' for acknowledge, the register/memory address, and the data received. If the received package is different, or if there is no response in a predefined time, resend the package.

You could also look into the "wire" library, as the I2C protocal is for a bus.

Thanks. I think Modbus RTU do right what you say.

However I would like to use something more user-friendly, something ASCII based with possibly automatic addressing (DHCP style). There would be great if there was a xAP or xPL over serial connection, but every implementation I see is for Ethernet. I would like to use a widely used protocol for Home Automation, so I could use a HA software for interfacing with my hardware.

I think that you should have a close look at http://www.nxp.com/documents/application_note/AN10216.pdf

This is strongly supported by the Arduino by the "wire" library and is very easy to use.

You could try Modbus ASCII instead of Modbus RTU.

Modbus Ascii was developed for use with Modems and is a standard protocol.

From off the top of my head, you basically have a start character which is always Ascii character ":", then you have the modbus function, modbus address, then the data, number of bytes, LRC error check and then Carriage Return and Line Feed characters.

Its a bit more 'structured' than RTU as it has strict start and end characters, so you can have a bit of a pause in between and it wont effect the outcome, whereas if you have something like 1.5 clocks with no data in RTU then it discards it and waits for the next frame.

This is all off the top of my head so I may have made a bit of a mistake in the order of things, however it is roughtly correct.

It would not be hard at all to implement Modbus ASCII in the arduino.

Google it, you will find a ton of info.

Hope that is of some help

Here is one for example.

and here has a few examples

Optomux should also work.

Is the Arduino i2c wire library could work on multi-drop rs-485 network?

I need something very simple, but robust. Just an address and data fields in ASCII format is enough. The whole thing about Modbus that reads and writes registers is too complex for me. I come from the world of PHP and web developing and working with registers sounds scary to me...

Just make a protocol up then.
If its only going to be used for your own devices, and not interfaced to anything else with a specific protocol, then just make one up.

form a string that you print to the serial port, seperate each variable in the string with a comma or something. This is what I am currently doing for one of my projects.

I have a start character so the PC can easily fix onto the start of the string. My start character is the STX character which is HEX 0x02.

I then have the data I want, seperated with commas. ie DATA1,DATA2,DATA3

I then have two end characters to show its the end of the string, which are Carriage Return and Line Feed. 0x0D and 0x0A in hex.

Start and End characters make it very easy for the PC to lock onto each 'frame', so it gets the entire frame and not the end of one and the start of the next and try to perform some sort of calaculation on the data.

So basically I send a string like this:

Serial.print(byte(0x02));
Serial.print(Data1);
Serial.print(",");
Serial.print(Data2);
Serial.print(",");
Serial.print(Data3);
Serial.print(byte(0x0D));
Serial.print(byte(0x0A));

Hope that is of some help

James

Oh and to extend on the above, since you will no doubt have multiple devices as you wanted addressing, just put in a field that the Arduino fills in depending on which device it wants to talk to.

i.e. if you want to talk to device number 10

Serial.print(byte(0x02));
Serial.print(10);
Serial.print(",");
Serial.print(Data1);
Serial.print(",");
Serial.print(Data2);
Serial.print(",");
Serial.print(Data3);
Serial.print(byte(0x0D));
Serial.print(byte(0x0A));

and then on the receving end, assuming it will be an arduino you are talking to also, just have it read in the broadcasted data and if the first field is equal to 10, then that device acts on the data, otherwise it discards it.

Just an idea :slight_smile:

SNAP protocol is pretty simplistic. Solutions were created for the Basic Stamp so it should possible to migrate somthing to the more capable Arduino.

http://www.hth.com/snap/

I'm still looking for a suitable protocol for HA over RS485. Modbus RTU is too complicated for my needs. I need something simple, but robust and reliable. It would be best if there is an Arduino implementation also.

Maybe you will laugh to me, but how about using the Arduino's Xbee library? As far as I see it uses the hardware Serial port, RS485 too. It has many built in checks and is simple to use. It's a multi master protocol, which is something I like (not like Modbus). Is there something that is specific for the medium (wireless) that will not work on wired serial medium (RS-485)?

Have you seen this: