VB - FireCracker Interface
This article will give you a simple solution to interface the FireCracker available from http://www.x10.com/homepage.htm, to a PC using Microsofts 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..?
About The FireCracker :
The FireCracker is a small DB9 device that plugs into your PCs 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.
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.)
There is no set timing for sending commands, however it is recommended to maintain a state for at least .5 ms.
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.
Header = 11010101 10101010 = D5 AA Hex
Footer = 10101101 = AD Hex
The VB Side
Step 1: (Start New Project)
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.
Step 2: (Load Comm Control)
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.
Now you should see a little yellow phone in the VB toolbar.
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 Form1s Load event you should have something like this .
Note: The Pause and Reset commands are explained below.
Step 5: (Helper Routines)
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.
In the General Declarations of your Form add this line
And add a subroutine called Pause
Step 6: (Writing A Simple Application)
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. Lets 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
Now your form should look like this
Now you need to add the code to each command button to send the header, then the data, and finally the footer. Sow add something like this
Now all of the coding is complete..! Run your app and see if it works..!
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..!
See below to download it.
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..!
About The Author:
My name is Jared Hoylman and am a EET student at DeVry in Columbus, OH scheduled to graduate in June 2000. I have been programming in VB for about 3 years and studying electronics for about the same. This is one of my first articles ever written to be placed on the web. If you have questions, comments, suggestions, or just want to say hi, you can email me at firstname.lastname@example.org. (I am not affiliated with X-10 or Microsoft in any way.)
Thanks for reading, and I hope you enjoyed it..!
Jared Hoylman - email@example.com
Click HERE to download the Visual Basic files for the FireCracker project.
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
Click HERE For