X10 Community Forum

🔌General Home Automation => Automating Your House => User Modified Devices => Topic started by: Noam on August 02, 2012, 10:43:08 PM

Title: Arduino-Based X10 control
Post by: Noam on August 02, 2012, 10:43:08 PM
Well, I just took another look at what's out there for interfacing an Arduino with a TW523 (which my XTB-IIR emulates).
It seems there have been a number of updates, including updates to the libraries to work with the newer versions (since 1.0) of the Arduino IDE.
I think I'll have to play with this again at home, and see where it gets me.
I spent a few hours this evening looking at Tom Igoe's X10 library for Arduino:
https://github.com/tigoe/x10
After a few hours of frustration, I finally got it working (It wasn't clear from most of the documentation that I needed a 10k resistor between the Zero Crossing line and +5v).
I was able to send simple on and off commands. However, I wasn't able to figure out the Extended Dim commands. I don't actually need them for my current project - turning my attic fan on and off in conjunction with my HVAC temperatures - but it would be nice to be able to send them if I need to.
The library has some "aliases" for things like "on" and "off," as well as "Extended Code". However, I can't figure out the syntax beyond that.
It looks like those aliases refer to specific binary values ("ON" sends "0b00101", and "OFF" sends "0b00111"), but I don't know what the equivalent binary code would be for the two parts of the extended dim commands. I ran out of time this evening to play with it, but I *think* I just need to convert the hex to binary, and try writing that.
Perhaps over the weekend.
Title: Arduino-Based X10 control
Post by: JeffVolp on August 03, 2012, 09:18:28 AM
After a few hours of frustration, I finally got it working (It wasn't clear from most of the documentation that I needed a 10k resistor between the Zero Crossing line and +5v).

The X10 Protocol document shows what is required to interface to the TW523/PSC05.  That is available here:

     http://jvde.us/info/X10_protocol.pdf

Don't ignore the clamping diodes like one manufacturer did if you want a robust interface.

There is also an extended code document (Google xtdcode.pdf or xtc798.doc).  The most common extended code is 62 bits long.  The CM15A transmits it as a doublet, which will be repeated by the XTB-IIR.

Note that the real TW523/PSC05 will not receive extended codes, but the XTB-IIR will.

Jeff
Title: Arduino-Based X10 control
Post by: Noam on August 03, 2012, 12:07:49 PM
After a few hours of frustration, I finally got it working (It wasn't clear from most of the documentation that I needed a 10k resistor between the Zero Crossing line and +5v).

The X10 Protocol document shows what is required to interface to the TW523/PSC05.  That is available here:

     http://jvde.us/info/X10_protocol.pdf

Don't ignore the clamping diodes like one manufacturer did if you want a robust interface.

There is also an extended code document (Google xtdcode.pdf or xtc798.doc).  The most common extended code is 62 bits long.  The CM15A transmits it as a doublet, which will be repeated by the XTB-IIR.

Note that the real TW523/PSC05 will not receive extended codes, but the XTB-IIR will.

Jeff
Jeff -
Thanks for your reply. I had already looked at the protocol documents, but I don't really understand them well enough yet. I took another look today, and I'm only slightly less lost.
I'd really love to find some examples of using Extended Dim commands with the library I'm using, but I haven't found any yet (While Google is my friend, it has been more like the friend who has to tell you the entire backstory on the history of restaurants, before telling you where they went for lunch yesterday).  B:(

I did find a second library here: http://code.google.com/p/arduino-x10/downloads/list , but that one looks a lot more complicated (although it can do a lot more, too). I had tried it last night, but only BEFORE I fixed my missing resistor issue. By the time I was able to send simple ON and OFF commands, I was too tired to go back and try the other library. That's on my list for this weekend.

I'm trying to decide if  want to have my current Arduino (the HVAC monitor) talk directly to the XTB-IIR, or have it talk to a second Arduino (by setting a pin high or low - using an opto-isolator would be smart), and then have the second one send the appropriate commands to the XTB-IIR. The advantages of using a second Arduino are: (1) I don't need to use as many pins on my already crowded HVAC monitor, and (2) I can add other things to the second one later on (like the "flag status" LED panel I've wanted to build for a while). I would almost be using the second Arduino like a really fancy programmable PowerFlash in that case (and if I were to add an Ethernet shield to it, now THAT would be a really cool project - I have to add that to my list!).

A third option would be to move the whole project (HVAC *and* X10) over to a Mega (I have one - that's what I've been using to build a "first draft" of anything I try), which would give me plenty of pins to use, as well as allow me to have enough extra pins to add in the Ethernet shield (or buy one these - which look REALLY cool! : http://www.freetronics.com/products/ethermega-arduino-mega-2560-compatible-with-onboard-ethernet ), and then rebuild my HVAC monitor shield on a Mega-compatible prototyping shield. I'd love to add the Ethernet capabilities at some point down the road (so the Arduino would post the data to the MySQL database via a PHP page on the server), but that's a long way off at this point.

Have any of the forum members (or non-member guests who want to become members to reply) played around with interfacing the Arduino and X10 via the TW523/PSC01/XTB-IIR, and would be willing to give me some code examples to work with?
Title: Arduino-Based X10 control
Post by: Noam on August 06, 2012, 12:10:19 AM
For those interested, here's an update on my Arduino/HVAC/X10 project:

Despite spending another hour or so on it, I was unable to send extended dim commands using the "simpler" library.
The more complicated one can do it (I think), but it is way more complicated for me to figure out how to adapt the examples to my needs at this time.
I decided to keep the project on a single Arduino Uno, for now. After a quick search, I learned that I can use the Analog pins as digital ones, simply by addressing them as digital pins. That gave me another 6 pins to use, which is plenty for now (until I decide to add Ethernet - but that's another story).
After doing a bit more testing on the Mega, including testing that it can talk to the XTB-IIR correctly over the analog pins (in digital mode), I bit the bullet, and attacked my carefully built HVAC project shield with the soldering iron. I had a bit of frustration because of the tight quarters (and the fact that the cheap prototyping shield I bought on eBay doesn't have an extra set of holes for each header pin), I finally had the 5 wires added to the board (4 for the X10 interface, one for a status LED I've been playing with - might as well solder a lead to the board for that, once I'm going in there).
Since I use the wires out of my spool of CAT5e cable for a lot of the hookups, I was careful to use the remaining 5 colors that weren't already in use on one of my jacks (I have three CAT5 jacks wired to the board for connecting to my furnace, 1-Wire bus, and humidity sensors), and I added the X10 communication (and that status LED pin) to the jack for the 1-Wire bus.
The next step is to run a CAT5e line from my patch panel over to the XTB-IIR with an RJ45 at one end, and an RJ11 at the other.
Then I can work on the code to turn my attic fan on and off when I need to adjust airflow in the house.
Title: Arduino-Based X10 control
Post by: pomonabill221 on August 06, 2012, 12:17:11 AM
Noam...
  Just a quick and probably stupid question.
What is a "shield"?
Sounds like you are really getting into your project!  I may be interested to find out what else you, or it, can do?
Title: Arduino-Based X10 control
Post by: dhouston on August 06, 2012, 07:36:30 AM
@Noam
My apologies for not getting the ZarduinoTM beta hardware to you. My health issues have kept me from making much progress on that - what time I've had has been spent on the mega hardware. It would have saved you a lot of trial and error as ZBasic has low-level X-10 functions built in.

This may help...
I don't think Smarthome's 1132 is still available but its documentation gives the bit patterns you need for both standard and extended commands. You will not need their handshaking codes but only the raw bits for the extended codes.

The X10 documentation is at...

Also...
has recommended circuits for interfacing OEM equipment to the PL513/TW523 which also apply to the PSC04, PSC05, TW7223 & XM10. At minimum you need a 4.7K pullup on both ZC and Data Out (i.e. from the TW523).
Title: Arduino-Based X10 control
Post by: Noam on August 06, 2012, 09:31:03 AM
@Noam
My apologies for not getting the ZarduinoTM beta hardware to you. My health issues have kept me from making much progress on that - what time I've had has been spent on the mega hardware. It would have saved you a lot of trial and error as ZBasic has low-level X-10 functions built in.

This may help...
  • http://www.smarthome.com/manuals/1132-A.pdf
I don't think Smarthome's 1132 is still available but its documentation gives the bit patterns you need for both standard and extended commands. You will not need their handshaking codes but only the raw bits for the extended codes.

The X10 documentation is at...
  • http://software.x10.com/pub/manuals/xtdcode.pdf

Also...
  • http://software.x10.com/pub/manuals/technicalnote.pdf
has recommended circuits for interfacing OEM equipment to the PL513/TW523 which also apply to the PSC04, PSC05, TW7223 & XM10. At minimum you need a 4.7K pullup on both ZC and Data Out (i.e. from the TW523).

Dave -
No worries on the beta hardware. I would never want my dream projects (most of which I'm not yet smart enough to accomplish) to ever interfere with your health (or anyone else's for that matter).

Thanks for sharing those links. I had seen the second and third, but the first one was new to me.
I think the problem I'm having stems from the library itself. I took a closer look at it with my limited programming skills. It looks like it isn't set up to properly send extended commands at all. For my current project (HVAC monitor being able to control the attic fan), I don't need Extended codes. The other library I found is more complicated, but it looks like it CAN handle extended codes (I haven't tested it yet, though). That would probably be what I would use if I ever decide to build myself an Arduino based PowerFlash/Universal module.

I was able to get it to send "simple" X10 commands (on, off - which is all I need right now). I did need the pullup resistor, which is what was missing during most of my first round of testing (and the cause of the frustration).

Does anyone know (kind of a rhetorical question, as I'm SURE Jeff knows  ;)) if I can hook up two devices to the TW523 (or the TW523 port on the XTB-IIR) at the same time, and have both devices able to talk to it bi-directionally? I would guess that two devices can receive from the TW523, but can two of them be set up to write to it as well?
If I do end up building myself a Powerflash/Universal module, I probably won't need two devices to talk to it at the same time (the HVAC monitor could talk to the PowerFlash), but it would be helpful during testing and development of such a project.

Thanks.
--Noam
Title: Re: Arduino-Based X10 control
Post by: Noam on August 06, 2012, 09:45:55 AM
Noam...
  Just a quick and probably stupid question.
What is a "shield"?
Sounds like you are really getting into your project!  I may be interested to find out what else you, or it, can do?
Bill -
A "shield" (in Arduino terms, at least), is a secondary card (call it a "daughter-board, if you want), that plugs into the top of the Arduino. Rather than trying to solder right to the Arduino's pins, or plugging in lots of messy wires to the headers, a shield lets you build your circuit separately, and simply plug it into the Arduino. (There are lots of "ready-made" shields out there, to do things like Ethernet, WiFi, 3G, Zigbee, motor control, etc).
Depnding on the pins that they use, many shields come with "stacking" headers, which allow you to piggyback one shield on top of another, all of them connecting back to the Arduino at the bottom (although I have seen projects where one shield interfaces with another directly).

It is relatively easy to make your own custom shield. If you know how to lay out and etch circuit boards, you can really make anything you want. Lacking that experience, I purchased a "prototyping" shield, which is essentially just a blank perfboard (there are some handy things like a 5v bus and a ground bus, as well as layouts for connecting a DIP IC, or an SMD one), with the headers pins to plug into the Arduino, and the headers to stack another shield on top).
Title: Re: Arduino-Based X10 control
Post by: dhouston on August 06, 2012, 03:00:50 PM
Does anyone know (kind of a rhetorical question, as I'm SURE Jeff knows  ;)) if I can hook up two devices to the TW523 (or the TW523 port on the XTB-IIR) at the same time, and have both devices able to talk to it bi-directionally? I would guess that two devices can receive from the TW523, but can two of them be set up to write to it as well?
It shouldn't be a problem as long as you don't try sending from both simultaneously which might result in collision-like garbage on the powerline which won't be reported by the TW523.
Title: Re: Arduino-Based X10 control
Post by: pomonabill221 on August 06, 2012, 03:20:54 PM
Noam...
  Just a quick and probably stupid question.
What is a "shield"?
Sounds like you are really getting into your project!  I may be interested to find out what else you, or it, can do?
Bill -
A "shield" (in Arduino terms, at least), is a secondary card (call it a "daughter-board, if you want), that plugs into the top of the Arduino. Rather than trying to solder right to the Arduino's pins, or plugging in lots of messy wires to the headers, a shield lets you build your circuit separately, and simply plug it into the Arduino. (There are lots of "ready-made" shields out there, to do things like Ethernet, WiFi, 3G, Zigbee, motor control, etc).
Depnding on the pins that they use, many shields come with "stacking" headers, which allow you to piggyback one shield on top of another, all of them connecting back to the Arduino at the bottom (although I have seen projects where one shield interfaces with another directly).

It is relatively easy to make your own custom shield. If you know how to lay out and etch circuit boards, you can really make anything you want. Lacking that experience, I purchased a "prototyping" shield, which is essentially just a blank perfboard (there are some handy things like a 5v bus and a ground bus, as well as layouts for connecting a DIP IC, or an SMD one), with the headers pins to plug into the Arduino, and the headers to stack another shield on top).
AH, I see!  I was confused about the term "shield", and it really is a daughter board of sorts!
Thanks for explaining it!
Title: Re: Arduino-Based X10 control
Post by: russellc on August 06, 2012, 10:15:52 PM
Hi, and greetings from Australia.

I don't want to muddy the waters, but I have a Home Security system based on the SC28 control console.  This unit runs the connected X10 devices in my house, and also receives the signals from the wireless door/window sensors.

Sadly, the LCD panel that provides the interface to the system has gradually lost many segments, to the point where it's not possible to make out what's going on in the house.

Since I have some experience with Arduino, and too much spare time (ask my wife), I thought I'd put some effort into replacing the controller with an Arduino.  I have bought an X10 3rd party interface module - XM10 is the part number here - and I can see a way forward using the X10 libraries available.

However, the wireless security devices - in this case 433MHz wireless reed sensors - present a different problem.  I can buy a 433MHz receiver shield for the Arduino, but Murphy dictates that the sensors will use a proprietary protocol.  Does anyone involved in this thread have any knowledge of how to receive and decode these signals?  It'd be nice if the universal remote used similar protocol, of course.

cheers,
RussellC
Title: Re: Arduino-Based X10 control
Post by: Noam on August 06, 2012, 11:39:20 PM
Well, I e-mailed the guy who wrote the X10 libraries, and asked about Extended Dim commands. He said that he didn't put it in there, so the library doesn't support it. He said I was welcome to add the support in for it, it might be pretty easy to do. Unfortunately, "Easy" for him probably is very different from "easy for me."

Looks like I'll have to either figure it out on my own, or just figure out how to use the more complicated libraries that are out there.

On a lighter note, I added in the X10 code to my HVAC controller program, and ran a wire from the XTB-IIR back to my "HVAC-duino". Everything tested fine (it was able to send the command). Now, I have to wait for the Smarthome switches to arrive, and install them. I won't fully be able to test the logic until the switches are installed.
Title: Re: Arduino-Based X10 control
Post by: Noam on August 06, 2012, 11:42:27 PM
However, the wireless security devices - in this case 433MHz wireless reed sensors - present a different problem.  I can buy a 433MHz receiver shield for the Arduino, but Murphy dictates that the sensors will use a proprietary protocol.  Does anyone involved in this thread have any knowledge of how to receive and decode these signals?  It'd be nice if the universal remote used similar protocol, of course.
RussellC -
Check out this Arduino thread:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1276569350

Also, check out these libraries, I think they have RF support in them (I don't know about security, but you could always e-mail the author, and ask:
http://code.google.com/p/arduino-x10/downloads/list
Title: Re: Arduino-Based X10 control
Post by: JeffVolp on August 07, 2012, 12:16:57 AM
Does anyone know (kind of a rhetorical question, as I'm SURE Jeff knows  ;)) if I can hook up two devices to the TW523 (or the TW523 port on the XTB-IIR) at the same time, and have both devices able to talk to it bi-directionally? I would guess that two devices can receive from the TW523, but can two of them be set up to write to it as well?

You can drive from more than one source if the outputs go tri-state when not active.  You could also diode OR them together, but make sure you still provide a good logic "1" when driving.

Jeff
Title: Re: Arduino-Based X10 control
Post by: dhouston on August 07, 2012, 07:40:37 AM
However, the wireless security devices - in this case 433MHz wireless reed sensors - present a different problem.  I can buy a 433MHz receiver shield for the Arduino, but Murphy dictates that the sensors will use a proprietary protocol.  Does anyone involved in this thread have any knowledge of how to receive and decode these signals?  It'd be nice if the universal remote used similar protocol, of course.
The RF security protocol is just slightly different from the standard RF protocol. Both are based on the NEC IR protocol which goes back 40+ years. See...
Battery-powered security devices also append a short indication of a low battery but I cannot recall the details off the top of my head. I just got out of the hospital and am still in recovery mode.

I lost a lot of my notes, code, etc. when I lost a NAS drive a couple of years ago but there is a link to a PicBasicPro example for receiving/sending the codes on the third page cited above.
Title: Re: Arduino-Based X10 control
Post by: dhouston on August 07, 2012, 09:44:09 AM
The August/September issue of The Shed magazine (New Zealand) http://www.theshedmag.co.nz/online/current-articles (http://www.theshedmag.co.nz/online/current-articles) has the first Arduino 101 article in an introductory level series of articles on the Arduino. They are written by Terry King of YourDuino.com http://arduino-direct.com/sunshop/ with whom I'm working on my ZarduinoTM designs http://davehouston.org/Zarduino.htm.
Title: Re: Arduino-Based X10 control
Post by: Noam on August 10, 2012, 02:20:55 PM
Here's another update:
My Smarthome Switches arrived on Tuesday afternoon. Unfortunately, my attic fan motor decided to call it quits on Tuesday morning.
I spent Tuesday evening removing the old motor, during which I found that the wiring wasn't done in the smartest way possible (the installer had run power first to the thermostat box, then put the switch (mounted in the closet below) on the the neutral line, not the hot - so the black wire running to the fan was always hot, even when the switch was off). Since I was planning on re-wiring anyway, this wasn't a major setback (not compared to the motor seizing up), but it still bothered me.
I found the right motor (from the same manufacturer) online, for around $60 shipped. My dad offered to head to Grainger on Wednesday, to see if they had an equivalent motor.
Sure enough, he was able to buy the motor on Wednesday for about the same $60, so I spent Wednesday evening installing the new fan and re-wiring the circuit. I needed to re-route the power first to the closet for the Smarthome switch, and then through a 3-way switch which gives me the ability to override the choice of "auto-thermostat" or "on" for testing, and then up to the fan (it is actually a shorter cable run to do it that way, too).

Everything is running again, and my first test of the Arduino-controlled attic fan worked like a charm yesterday.

[WARNING: Way too much detail below]
In a nutshell, my house was built about 50 years ago, and wasn't properly air-sealed between the house and the attic. As a result, my attic fan ends up pulling air from the house when it runs. As we replaced windows in the house, we closed up a lot of the "make-up air" intake, creating a slight negative pressure situation in the house. I know the proper fix is to properly air-seal the house, then add ventilation as needed. However, that solution is not within our budget at the moment. Anyway, the "negative pressure" problem causes the hot water heater to have to fight against the attic fan to draft the exhaust up the flue. The water heater eventually wins, but depending on the outside temperature, it can take longer than it is supposed to. When the fan is off, this doesn't occur. However, until the draft is established, that exhaust spills out of the gap between the water heater and the draft hood. (And yes, I have a CO detector nearby - it has never once been triggered by this, otherwise I would be addressing it differently).

So, the poor-man's interim solution (until I can properly air-seal the house and attic, and fix the ventilation), is to turn off the attic fan when the hot water heater kicks on, long enough to establish a draft.
So, the HVAC monitor (Arduino) checks the "spillover" temperature, and if it reached 100 degrees (a sign that the water heater burner is on, and a draft has not been established), it turns off the attic fan for 5 minutes. It then checks to make sure the draft is established (the "spillover" temp has dropped below 100 degrees), and turns the fan back on.

So, yesterday afternoon was my first "real world" test. The fan was on, and the water heater came on (the kids all took baths after playing outside - before dinner). The "spillover" temp started to rise rapidly. As soon as it hit 100 degrees, the fan turn off, the draft was established, and my "flue temp" (I have another sensor there) shot up as it was supposed to. 5 minutes later, the fan turned back on, and the draft wasn't affected.

Another reason for adding the "override-on" switch: When I do start fixing the air-sealing problem (there are some major gaps I can fix myself), I can test the effect it has (by using the water heater spillover as a guage), even if the attic isn't hot enough to trigger the fan.
Title: Re: Arduino-Based X10 control
Post by: pomonabill221 on August 10, 2012, 03:00:22 PM
The miss wiring of the fan is yet another confirmation to me that a "licensed electrician" doesn't always know what they are doing, or that they know the code!
  YIKES!!!  backdrafting the hot water heater (AND the space heater and clothes dryer if it is in the living space), is BAD BAD BAD!!!  BUT you know that this is the case and have a co detector monitoring the situation... GOOD!
And YES you need to seal the attic space from the living space!  My home was built in 1911, and the only appliance I have in the living space is the clothes dryer, but I keep the window cracked for makeup air and the door closed to the service porch.
  I have a whole house fan that I have used to find leaks and have sealed them up (pocket doors, walls in closets, old holes in the top plate where the knob and tube used to penetrate, windows, etc.).
  You might want to add a gable vent at the opposite end of the attic, if one doesn't exist already, to help ventilate the attic as well and keep the pressure differential down.
Title: Re: Arduino-Based X10 control
Post by: Noam on August 11, 2012, 09:42:14 PM
The miss wiring of the fan is yet another confirmation to me that a "licensed electrician" doesn't always know what they are doing, or that they know the code!
  YIKES!!!  backdrafting the hot water heater (AND the space heater and clothes dryer if it is in the living space), is BAD BAD BAD!!!  BUT you know that this is the case and have a co detector monitoring the situation... GOOD!
And YES you need to seal the attic space from the living space!  My home was built in 1911, and the only appliance I have in the living space is the clothes dryer, but I keep the window cracked for makeup air and the door closed to the service porch.
  I have a whole house fan that I have used to find leaks and have sealed them up (pocket doors, walls in closets, old holes in the top plate where the knob and tube used to penetrate, windows, etc.).
  You might want to add a gable vent at the opposite end of the attic, if one doesn't exist already, to help ventilate the attic as well and keep the pressure differential down.
I never said the fan was installed by a licensed electrician, and in fact I suspect it wasn't.
Our home was built in 1964, and all of our appliances are in the living space.
I have a 4-inch make-up air vent that I installed last summer through the wall into the laundry room (where the electric dryer, furnace, and water heater are). A gravity-damper (off-balance vertical flap - pivots open when there is a flow of air) opens as needed. However, that wasn't enough make-up air to counteract the pull of the attic fan (I still want to try ducting it over so it dumps out near the water heater, though).

I have gable vents at both ends of the attic, but I have a feeling the screens are both pretty clogged up. A few years ago, I cleaned the one I can reach from the inside, by literally poking open each of the holes in the screen with a bamboo skewer and a stiff brush. I need to find someone who can climb up and change both screens from the outside.
Title: Re: Arduino-Based X10 control
Post by: Noam on October 07, 2012, 10:01:01 AM
Here's another update:
My limited HVAC/X10 interfacing setup has been working nearly flawlessly (I had one case of a signal not going through - I think the CM15A burped that time when it was running the macro).
We're just about at the end of "attic fan" season, so I'm getting ready for the next project - I want to build an Arduino-based multiple input/output combination PowerFlash and Universal Module.
I'm not concerned with the "flash" function, but more with the ability to have a contact closure/release trigger an X10 command, and to be able to trigger a contact closure/release from an X10 command.
I really have no idea what I'm doing, so it will probably take me a while to get it working the way I want.