Professional Documents
Culture Documents
This article will give you a simple solution to interface the FireCracker available from
http://www.x10.com/homepage.htm, to a PC using Microsoft’s Visual Basic 5 Professional
Edition or higher. You can order the FireCracker kit which comes with the FireCracker ,
an X-10 Transceiver , an X-10 Lamp Module, and a RF Remote.
X-10 technology is a new wave of home automation or control. You can turn any
appliance or lamp that plugs into a standard wall socket on or off. If you use a lamp
module you can even dim or brighten a lamp to the brightness that you desire. And you
can do all of this remotely, and without modifying your home's electrical system.
The way that X-10 works is what makes it so cool. There is no extra wiring to run
through your home to control these devices. The X10 Transceiver will receive RF signals
from either the FireCracker or the hand-held remote, and transmit data over the existing
power lines in your house. The X10 modules will pick this data off of the power lines and
turn the connected device on or off, or adjust brightness accordingly. Pretty cool, eh..?
The FireCracker is a small DB9 device that plugs into your PC’s serial port. It has an odd
protocol for communicating with the PC. The FireCracker uses the Data Terminal Ready
(DTR) and Ready To Send (RTS) lines to both power itself and read data from the PC.
This allows for pass-through capabilities. Since it does not use the standard port lines
you can still connect another device to the port as long as it does not use the DTR or RTS
lines. (However software may limit the number of programs using a single port.) Since
the FireCracker uses either the DTR or RTS lines for power you must keep one of these
lines high at all times to make sure that power is not lost.
The Protocol:
As mentioned earlier, the FireCracker uses an odd protocol to communicate with the PC.
There are four different states that can be depicted from the two port lines. When both
the DTR and RTS lines are high the FireCracker is in StandBy mode, and when both lines
are low the FireCracker is in Reset mode. To send a logic 1 to the FireCracker you must
toggle the DTR line low, and to send a logic 0 you must toggle the RTS line low. (See
the table below.)
RTS DTR
StandBy 1 1
Logic 1 1 0
Logic 0 0 1
Reset 0 0
Timing:
Each transmission is made up of 40 bits of data. First you must send a 16-bit header,
then 16 bits of data, and then an 8-bit footer. The header and footer always have the
same value, but the data changes as to which command you are sending to the
FireCracker.
The VB Side
Run Microsoft Visual Basic 5 Professional Edition or better. When the program starts you
should see a screen similar to the one below…
We will be making a standard executable so click on "Standard EXE" and then on the
"Open" button.
Now that you have selected to make a standard executable you should see a blank form
on the screen. Since we need to use the serial port to communicate with the FireCracker,
we need to add the Microsoft Comm Control.
Double click on the yellow phone and you should see an icon with the yellow phone pop
up on your blank form, as shown below…
Step 3: (Understanding the Comm Control DTR and RTS Enable Commands)
Usually when using the MSComm control you need to set the baud rate, parity, and
number of start and stop bits. However since the FireCracker does not use the standard
connections this is not necessary.
The MSComm control has two properties called DTREnable and RTSEnable. These are
Boolean properties and therefore only have two states, True and False. It so happens
that setting the DTREnable property to True sets the DTR line on the serial port to a
high state. And vice-versa, setting the DTREnable property to False sets the DTR line
on the serial port to a low state. The same goes for the RTSEnable property and the RTS
line.
Step 4: (Form_Load)
Above I mentioned that StandBy mode was when both the DTR and RTS lines are high.
So, when executing the project, the first thing that we want to do is set up the MSComm
control to use a specific port, enable the RTS and DTR lines, and finally open the port. In
Form1’s Load event you should have something like this….
Now we are going to make a couple small routines that will be the basis of how we send
logic 1 and logic 0 to the FireCracker (refer to the Timing diagram above). Below is the
code…
We have not made the Pause routine yet but what it does is pause for the number of
milliseconds that is passed to it. The FireCracker only needs .5 ms between states, but in
VB the smallest amount of time that we can pause is 1 ms, so this will have to do.
So now say that we want to send the header which has a value of D5AA Hex. We would
have to write 16 Send_1 and Send_0 commands, one for each bit. This is too
complicated..! So to ease the process how about making a routine that will send a whole
byte..! See the code and comments below…
So now the process of sending data is even easier. How about a few more simple
routines that will make your coding a little easier to read and follow…
The above subroutines do exactly what they say. The first one resets the FireCracker, the
second one sends the header bytes, and the third one sends the footer byte.
For this article I am not going to go too in depth and write the whole application for you.
I am just providing the tools for you to make your own FireCracker interface. However I
will show you how to control the two X10 Modules that came with the FireCracker kit.
Set the Transceiver (the one with the antenna) to House Code "A". By default this
module has a Unit Number of "1". Now set the lamp module that came with the kit to
House Code "A" and Unit Number "2".
After looking at the FireCracker datasheet (can download below) you will see the
following commands and corresponding values.
So now that we have that out of the way. Let’s build our program. On your form add four
command buttons as shown in the picture below…
Now set each command buttons properties as shown below…
Command1
Name – "A1_ON"
Caption – "A1 ON"
Command2
Name – "A2_ON"
Caption – "A2 ON"
Command3
Name – "A3_ON"
Caption – "A3 ON"
Command4
Name – "A4_ON"
Caption – "A4 ON"
Now all of the coding is complete..! Run your app and see if it works..!
Want more..?
Since this article only showed you how to control just two modules, I have written a class
for use in your applications. This class is complete with the entire House and Unit codes
built in. You just set the House Code, Unit Code, and execute an ON, OFF, DIM, or
BRIGHTEN command. This class comes complete with full source code and an example
project to get you started on your way to your home control and automation dreams..!
What can you do with this class..? With a little imagination you can control your whole
house. Turn on the coffee pot and lights in the morning, turn them off when it is time for
you to leave, have toast ready for you when you get out of bed, ...whatever you can
imagine. The possibilities are a endless..!
Click HERE to download the Visual Basic files for the FireCracker project.
Distibution:
You are free to use this class for both personal use and commercially. If you do make
something quite interesting with the class, please keep me in mind. Email me and tell me
what your imagination inspired you to create. And if you are generous enough, you can
send me a copy. ;-)
Visit our new remote-control store link below. We have the TWS-434 & RWS-434 RF
transmitters/receivers in-stock with plenty of Holtek remote control ICs, and infrared components to get
you started on other Remote Control projects