User avatar
ripzay
Posts: 28
Joined: Thu Jul 19, 2012 9:32 am

RF Host-Slave Control For Home Automation

Thu Jul 19, 2012 9:55 am

Hi

While I realise that there are lots of products available off the shelf for this, my view is this: "If someone else can do it, I can too - even if it's not as good"

So.. my project is that of home automation.

There are three components to the project:

The Host
This will be a RasPi, with an off the shelf RS232 RF Transceiver module, I will write the software for this.
The host will send commands out to a number of slaves telling them what to do, and will recieve status updates from the slaves informing the host of what they have done.

The Slave
This is currently where my project has hit it's stumbling block.. (Microcontroller programming and associated circuitry is the one subject of electronics which I did not to very well at in college)

The slaves need to receive RS232 communication from a RF Transceiver matching that in the host.
When a command is received, this will output on a number of output pins and confirm the change with a status update over RS232 to the host.

The slaves will need to have an ID stored in some way (preferably in such a way that each individual slave doesn't have to be specifically programmed in software, maybe jumpers or DIP switch) so that it will only act on commands meant for it.

When a change is detected on a number of input pins, the slave will then push this change to it's output pins and send a status update over RS232 to the host.

IO Modules
The output modules will take the output logic from the slave and convert it to some desired output - be it dimming a light, or turning a stepper motor, or simply switching a relay.

Also, when the user interacts with the output module, the change will be sent into the slave's input pins to be communicated back to the host.

The idea behind this is so that I can manufacture a generic slave circuit and simply plugin in cheaper IO modules to change the purpose of the slave, even if the purpose of the IO module is simply a sensor - such as temperature.

In summary..

The host - I can manage myself
The IO modules - I can manage myself
The Slave - I don't know where to start... :(

Components chosen so far...
  • RasPi
I'm going to see if I can find my old electronics textbooks from college and start working on a specification for the comms framework, likely based on RSMB. I'll also do some high level diagrams to try and explain my wall of text above.

Any ideas or help would be appreciated (constructive or otherwise)
Cheers
ripzay

User avatar
ripzay
Posts: 28
Joined: Thu Jul 19, 2012 9:32 am

Re: RF Host-Slave Control For Home Automation

Thu Jul 19, 2012 12:24 pm

Having looked into this a little further - to keep the cost down for the 'Slave'... a good looking option for this would be PICAXE boards..

PICAXE-18M2 or PICAXE-20M2 chips will have enough IO pins to give me 8 input pins and 8 output pins as well as having serial IO for communication via the RF module.. this would make a total cost of approx £15 for the 'slave'.. which is nominal when compared to the off the shelf stuff, given the flexibility.

I've also just realised that this project could have other interesting side projects.. further RasPi's with the RF modules could essentially act as repeaters to extend range if required. and as soon as the RasPi Foundation start producing the screen interface boards, the host unit could quite quickly become a control panel for the home automation.. which would make it cheaper than the current off the shelf systems..

*fingers crossed*

Image

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 13092
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: RF Host-Slave Control For Home Automation

Thu Jul 19, 2012 12:48 pm

For this job, zigbee seems to be the best option to me.

The XBP24-AWI-001 (XBee-Pro) board is one of the more easy to use zigbee boards, but you could also look at some of the microchip based products.

User avatar
ripzay
Posts: 28
Joined: Thu Jul 19, 2012 9:32 am

Re: RF Host-Slave Control For Home Automation

Thu Jul 19, 2012 1:54 pm

mahjongg wrote:For this job, zigbee seems to be the best option to me.

The XBP24-AWI-001 (XBee-Pro) board is one of the more easy to use zigbee boards, but you could also look at some of the microchip based products.
Is there any reason you would use the XBee RF module over this one:

http://ciseco.co.uk/downloads/documents ... 20v1-6.pdf

The XBee is around £18 (or £26 for the pro), while the ciseco one is only £11.50.

From a quick glance over the datasheets they appear to do the same job, except for the XBee's mesh networking capabilities?

Cheers
ripzay

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 13092
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: RF Host-Slave Control For Home Automation

Thu Jul 19, 2012 4:40 pm

No, it was just that the Xbee-pro is a well known solution.

The most important thing is that the solution contains a complete software stack for the functionality you seek, and isn't just a simple radio transceiver.

User avatar
ripzay
Posts: 28
Joined: Thu Jul 19, 2012 9:32 am

Re: RF Host-Slave Control For Home Automation

Fri Jul 20, 2012 9:26 am

Well played to Ciseco, ordered a pair of XRF transceivers and a pair of their 'Slice of Pi' GPIO boards yesterday afternoon.. and they are on my desk at work this morning!

Image

I have two RasPi's so I am hoping to now be able to write the software for the host, and use my second Pi to emulate a slave until I work out what the most cost effective solution is for a microprocessor with my required IO.

Having read more on the PICAXE, they are looking quite good for this - simple programming language so i don't have to delve into pure ASM, and they also support eeprom over i2c, so i will be able to store the slave ID (and other variables) in eeprom which can reside on the IO module, and only use one IO pin, rather than using a DIP switch and losing 8 pins (for 256 addresses).

User avatar
ripzay
Posts: 28
Joined: Thu Jul 19, 2012 9:32 am

Re: RF Host-Slave Control For Home Automation

Sat Jul 21, 2012 9:33 pm

Some testing done with the RasPi's and the XRF modules.

I'm using the Raspbian 'Wheezy' image, and had to make some changes to allow my software to use the UART serial port on the GPIO pins.

The RF module uses /dev/ttyAMA0 for communication.. however, the default Raspbian image has this device mapped for use as a serial console...

To disable the serial console to allow my own software to use the port:

in /boot/cmdline.txt, remove the following bits from the string..

Code: Select all

console=ttyAMA0,115200 kgdboc=ttyAMA0,115200
in /etc/inittab, comment out the following line..

Code: Select all

T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
I was then able to run minicom and communicate between my two RasPi's over RF.

Now to write the Host software which will run as a daemon so that it can take input from various sources. and some dummy slave software which for now will run on the second RasPi.

Beakers
Posts: 5
Joined: Tue Jul 24, 2012 11:23 am

Re: RF Host-Slave Control For Home Automation

Tue Jul 24, 2012 11:26 am

This i brilliant, please do keep posting on how you get on.

I've only just ordered my Pi and automation really does appeal to me as my next hobby (proper change from pure web programming projects). I do however have zero electronics insight so every post you write lets me Google something and take a tiny step closer!
I have atleast 5 weeks to just read up on this as much as I can.

ingestre
Posts: 6
Joined: Mon Feb 27, 2012 2:45 pm

Re: RF Host-Slave Control For Home Automation

Wed Jul 25, 2012 2:04 pm

ripzay wrote:Now to write the Host software which will run as a daemon so that it can take input from various sources. and some dummy slave software which for now will run on the second RasPi.
I'd be interested in seeing what you come up with.

I've written a host daemon that talks via a coordinator Xbee to many slave Xbee modules and allows the Pi to :-
  • send commands
  • read DIO status
  • send/receive serial data
It currently works via a file system interface, but I'm sure there is a better way.....

User avatar
ripzay
Posts: 28
Joined: Thu Jul 19, 2012 9:32 am

Re: RF Host-Slave Control For Home Automation

Wed Aug 01, 2012 12:43 pm

Sorry I've been out of action over the last couple of weeks - Had my motorcycle stolen last week on top of dealing with the stressful purchase of my first house!

I have however written v.0.0.0.0.1 of my host software, and an some software which emulates a slave (currently runs on my second RasPi, and simulates human input as well as IO pins.

This is written with .NET, and running under mono at the moment - it's working well, but as soon as my concept is proven i will probably port it over to a native language of some description.

I will post another update as soon as I can!

User avatar
ripzay
Posts: 28
Joined: Thu Jul 19, 2012 9:32 am

Re: RF Host-Slave Control For Home Automation

Thu Aug 02, 2012 9:41 pm

Ok.. an update..

I've chosen some more components...

Host
This is already set up and working
  1. Raspberry Pi
  2. Slice of Pi
  3. Ciseco XRF

Slave
This should give me a Microcontroller with 7 input pins, 8 output pins, 2 human input pins, and a way to address the slave with 256 possible addresses.
  1. Ciseco XRF
  2. PICAXE 08M2
  3. Small switch mode power supply (240vac -> 9vdc)
  4. 5v Regulator to power Picaxe
  5. Diodes to drop 5v to 3.3v for XRF
  6. 1x MCP23008 I2C IO Expander + 8-way DIP switch for addressing
  7. 1x MCP23008 I2C IO Expander for 7 bit Output + 1 human input
  8. 1x MCP23008 I2C IO Expander for 7 bit Input + 1 human input
  9. 2x 8 pin headers
  10. Some resistors, capacitors.
Working on the schematic at the moment...

Image

... this is a first draft, and may have some innacuracies / components missing, i have yet to check whether any of the pins i am pulling up to 5v need protecting resistors in place.. obviously doesnt include the switch mode power suppy, regulator, or XRF component either at the moment.

i may also end up changing two of the 8 bit IO expanders for a 16 bit one (2x 8bit ports) to save space / simplify wire traces on the final version.

User avatar
ripzay
Posts: 28
Joined: Thu Jul 19, 2012 9:32 am

Re: RF Host-Slave Control For Home Automation

Thu Aug 02, 2012 10:13 pm

also - i am aware that i've connected the VSS / VDD pins on all the IC's backwards :D

User avatar
ripzay
Posts: 28
Joined: Thu Jul 19, 2012 9:32 am

Re: RF Host-Slave Control For Home Automation

Fri Aug 03, 2012 8:13 am

First draft of a single sided pcb for the slave module prototype...

Image

Top Left: PICAXE
Top Center: 5 way header to take this: XBBO
Top Right: IO Expander & 8-way header - 7 output pins, 1 human input pin (with interrupt to picaxe)
Bottom Right: IO Expander and 8-way header - 7 input pins, 1 human input pin (with interrupt to picaxe)
Bottom Left: IO Expander and 8-way DIP Switch - 256 possible addresses for slave modules.

There are some wire links in place to keep this a single sided pcb, and unfortunately a couple of them sit underneath an IC, i may make the pcb slightly longer or rework some of the traces to get around this.

Now.. any recommendations for getting a couple of these PCB's printed cheaply (i have no PCB production equipment of my own so would have to buy it all if i went down the photosensitive pcb route) ?

Is there anyone on these forums that could provide this service?

Cheers
Ben

len5622
Posts: 9
Joined: Tue Jan 10, 2012 9:04 am

Re: RF Host-Slave Control For Home Automation

Fri Aug 03, 2012 8:23 am

IMHO I would breadboard it all up -before- going to pcb....

User avatar
ripzay
Posts: 28
Joined: Thu Jul 19, 2012 9:32 am

Re: RF Host-Slave Control For Home Automation

Fri Aug 03, 2012 8:30 am

len5622 wrote:IMHO I would breadboard it all up -before- going to pcb....
I i totally agree - i find it easier to breadboard from a pcb drawing than a schematic (maybe that's just me)

unfortunately i have no breadboarding stuff either so that's on order - I appear to have misplaced it all (having not done any electronics work in a few years, I may have left it in the loft at my old home :()

I'm just putting feelers out that's all ;)

len5622
Posts: 9
Joined: Tue Jan 10, 2012 9:04 am

Re: RF Host-Slave Control For Home Automation

Fri Aug 03, 2012 9:25 am

Perhaps I would add that after breadboarding I would make up a prototype on 0.1" board using wirewrap wire. Then that becomes a usable 'pre-final' board. It's always the software step that gets me so I would delay going into final pcb layout till that's cracked.

I've used the Ciseco XRF boards with Arduino so would have gone towards an Arduino/AVR solution for the slave I/O but that's just a personal choice. Not sure why you need all that individual I/O at each slave location?

User avatar
ripzay
Posts: 28
Joined: Thu Jul 19, 2012 9:32 am

Re: RF Host-Slave Control For Home Automation

Fri Aug 03, 2012 3:01 pm

The amount of IO is purely to make the slaves as flexible as possible..

i can put ADC's on there to give me 128 degrees of accuracy (using 7 bits) for instance for monitoring temperature or position of something

the 2 human inputs gives me the possiblity of having an 'up' and a 'down' button for dimming lighting as another example.

and the 7 outputs.. for the reverse of the ADC.. giving me fine-grain control of digital potentiometers or. motors.. or.. whatever I want.

The SMPS would be optional depending on what the end-component is and will probably end up sitting on the IO module - for lighting / socket control SMPS, for DC applications, I can just use a DC-DC voltage converter.

This all makes sense to me.. but.. i'm the idiot who dreamt it all up, so it would! :D

User avatar
ripzay
Posts: 28
Joined: Thu Jul 19, 2012 9:32 am

Re: RF Host-Slave Control For Home Automation

Sat Aug 04, 2012 10:20 pm

Slightly Tidier, as well as correct schematic (i think!)

Image

len5622
Posts: 9
Joined: Tue Jan 10, 2012 9:04 am

Re: RF Host-Slave Control For Home Automation

Sun Aug 05, 2012 9:07 am

Don't know how you are handling the XRF but the earlier versions I have are 3v3 only so I would need level shifting resistors in the micro TX line. See the pdf you quoted http://ciseco.co.uk/downloads/documents ... 20v1-6.pdf

I did notice that Ciseco are also saying that the XRF is 5V tolerant input from v1.5 so maybe yours don't need them. For the sake of two resistors I think I would play it safe and include them (especially if there was a chance that -I- might swap XRF's about).

However you will still need 5V and 3V3 regulators. I have used Ciseco's XBBO - break out board which includes the resistors and also a 200mA 3v3 regulator for the XRF.
So you need a footprint for an adapter board or the raw XRF pins and whatever regulators and caps you decide on, on your pcb layout. Might as well go on the schematic for completeness.

User avatar
ripzay
Posts: 28
Joined: Thu Jul 19, 2012 9:32 am

Re: RF Host-Slave Control For Home Automation

Sun Aug 05, 2012 12:06 pm

You are correct.. And I ordered an xbbo on Thursday, it arrived on Friday and was all soldered together 20 minutes after I got home.. I am very impatient..

Currently waiting on my delivery from Farnell.. Including the mcp23008s, some breadboard and jumper wires.

Also waiting on my order from tech supplies containing a picaxe 08m2 starter kit

I have started writing the code for the picaxe but it is difficult to know how correct it is without beige able to test it with some hardware

User avatar
ripzay
Posts: 28
Joined: Thu Jul 19, 2012 9:32 am

Re: RF Host-Slave Control For Home Automation

Wed Aug 08, 2012 7:06 am

Ok.. all breadboarded up...

From left to right....

Output IO
Input IO
Address IO
Address DIP
XBBO + XRF Module
PICAXE-08M2

Sorry the photo is blurry - my phone appears to have autofocused in the wrong place, i'll get a better picture later.
Image

Now i just need to finish writing the code for the PIC!

User avatar
ripzay
Posts: 28
Joined: Thu Jul 19, 2012 9:32 am

Re: RF Host-Slave Control For Home Automation

Thu Aug 09, 2012 9:35 am

Ok.. breadboard testing / writing of the slave code is going ok.. but i hit a bit of a brick wall last night.

I've successfully got the DIP switch input giving the PIC a slave address

I've successfully got the human inputs mapping on to the i2c chip and data being sent back to the PIC

I've successfully got the 7 input pins on one I2C chip feeding input into the PIC

I have two stumbling blocks.

1: I can't seem to get the interrupts from the I2C chips to go high when the human input is pressed - they seem to be stuck at 5v, and no matter what i do i can't get them to change..

Reading the INTCAP register from the I2C is supposed to clear the interrupt as far as i can tell, but it doesn't seem to do anything.

2: I can't seem to get the output pins on the output I2C chip to go high - i've configured the pins as 1 input and 7 outputs, but whenever i write to the GPIO register on the chip, nothing happens, changes are not committed.

Anyone else had experience with I2C IO expansion chips before that might be able to point me in the right direction?

Cheers
ripzay

User avatar
ripzay
Posts: 28
Joined: Thu Jul 19, 2012 9:32 am

Re: RF Host-Slave Control For Home Automation

Mon Aug 13, 2012 9:59 pm

Some success!

I have made a slight error in my schematic - i need an or gate between my two interrupt lines from my i2c io chips to my pic... Oops..

For now in have temporarily made the human inputs work without interrupts by polling the i2c chips (less than ideal, but ill go and pick up an ic for the or gate in the next few days)

Anyway.. I have the human interrupts incrementing / decrementing the output ic (currently by 1 per cycle - holding the button down continues to increment / decrement)

I discovereed a potential issue with my rf code - if two slaves report back to the raspi st the same time, i am expecting the messages to clash...

Slave 1 sends AAAA
Slave 2 sends BBBB
Raspi receives ABABABAB

... Obviously bad... But i cant test this / come up with a solution until i have 2 slaves to play with to test my theory..so for now i am going to hope that my handshaking code gets around this...

My communication schema is as follows. (each part is 8 bits - 0 to 255) and will essentially be sent over serial rf as an ascii character

From Raspi to slave
Slaveid 0 is an invalid slave id and means all slaves
<slaveid><command><value>

Commands to include things like hello, on, off, set, report, ok

From slave to Raspi
<slaveid><command><value>

Commands to include thinfs like hello, report, ok

I will post a video or two when i have more to show.

User avatar
ripzay
Posts: 28
Joined: Thu Jul 19, 2012 9:32 am

Re: RF Host-Slave Control For Home Automation

Tue Aug 21, 2012 8:19 am

My very first home made PCB - not perfect but i've checkd it all over with a multimeter - there's just 2 locations where I will have to 'bridge a gap' in the traces

My slave code is all working, and my host code is getting there - i have gone with node.js - which should allow me to write a RESTful web service to control all my slaves - and therefore my house, from anywhere in the world.

Photo of my PCB...

Image

DaveY
Posts: 2
Joined: Wed Aug 22, 2012 2:57 pm

Re: RF Host-Slave Control For Home Automation

Wed Aug 22, 2012 3:00 pm

Really cool project - would like to try something like this - keep the updates coming!

Return to “Automation, sensing and robotics”