|
Personal Digital Literacy
|
|
|
|
|
 |
 |
 |
TECH PROJECT #2
Interfacing a Linux laptop to household appliances.
Disclaimer: Hooking non-standard hardware up to PCs, especially anything connected to the mains supply, means you are prepared to take the risk of frying your PC, or even worse, you. I cannot accept responsibility for anyone going away and frying PC's or themselves. I am merely putting this information on the web, to show what is possible. Experiment at your own risk.
- Introduction.
- Equipment Used.
- The parallel port.
- Links.
Introduction.
Well, it just had to be done. Using a parallel port only for printing seemed a bit tame, so I started thinking about what else I could interface to a Linux box ? It took all of a few seconds for me to realise the answer was "Lots".
I needed to use my Linux laptop (Omnibook 800) for data acquisition of telemetry data from rocket launches, sensor data from static tests, and also as the launch control system for rockets, so I needed to interface to the parallel port. This got me thinking, if I was going to be interfacing to non-computer external hardware, why not interface to household appliances ?
Initially, basic on/off control of household appliances would present a worthy challenge I thought. That narrowed down the number of controllable household appliances to just about everything; Washing machine, lights, TV, VCR, Toaster, Blender, Thermostat, Fridge, Freezer. O.K. you could do this using X-10, but I wanted to be inventive.
Computer Hardware Used.
Interfacing Hardware Used.
- 1 x 25-way D-plug (male)
- Ribbon cable.
- Plugboard.
- A motley assortment of resistors.
- Ditto for relays.
- And for opto-isolators.
- And LEDs.
- And Transistors.
Interfacing Tools Used.
- Multimeter
- Soldering Iron, solder and de-solder braid.
| Pin Number | Purpose |
| 1 | Ground |
| 2 | TxD |
| 3 | RxD |
| 4 | RTS |
| 5 | CTS |
| 6 | DSR |
| 7 | GND |
| 8 | DCD |
| 9 | |
| 10 | |
| 11 | |
| 12 | DCD #2 |
| 13 | CTS #2 |
| 14 | Txd #2 |
| 15 | Tx Clock |
| 16 | RXD #2 |
| 17 | Rx Clock |
| 18 | |
| 19 | RTS #2 |
| 20 | DTR |
| 21 | Signal Quality Detect |
| 22 | Ring Detect |
| 23 | Data Rate Select |
| 24 | TX Clock |
| 25 | |
Software
The code neccessary for the input and output to the parallel port is trivial in C. Whilst C is not always the most user friendly of programming languages, in this case, the code is so small, that it is easy (hopefully) to understand. The plan of action was as follows:
- Write C code to read input/send output to hardware devices via the parallel port.
- Write browser interface to control the C code.
- Write a Tcl/Tk GUI interface, for non-browser GUI control of the C control code.
- Write a Java GUI interface, for control of the C control code.
- Write Java version of the C control code and integrate into the Java GUI code.
CONCLUSIONS
By the time the interfacing was done, the most important lesson learnt was that whilst it was an interesting learning experience, using X-10 for home automation, and more specifically, the CM12U RS-232 to X-10 interface module and some software in C, Java or Perl is far more productive in the long run.
Links
|
|
 |
|
#!/usr/bin/perl -w
use strict;
use CGI qw(:escape);
use CGI;
use lib qw(/home/rosborne/lib);
use Astro::Sunrise;
use Astro::MoonPhase;
use vars qw($query);
my $query = new CGI;
print $query->header();
#print "Content-type: text/html\n\n";
my $sec = 0;
my $mday = 0;
my $mon = 0;
my $year = 0;
my $wday = 0;
my $yday = 0;
my $isdst = 0;
my $tz = 0;
my $hr = 0;
my $min = 0;
my @days = ();
my @shortdays = ();
my @months = ();
my @shortmonths = ();
my $longyr = 0;
my @cnts;
my $filename;
my $found;
my $counts;
my $cnt;
my $page;
my $showcnt;
my $cnts;
my $blk;
my $sunrise;
my $sunset;
my ($MoonPhase,$MoonIllum,$MoonAge,$MoonDist,$MoonAng,$SunDist,$SunAng);
sub determine_date
{
@days = ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
@shortdays = ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
@months = ("January","February","March","April","May","June","July","August","September","October","November", "December");
@shortmonths = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
($sec,$min,$hr,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$longyr = $year + 1900;
if ($isdst == 1) {
$tz = "GMT";
} else {
$tz = "GMT";
}
}
sub display_date
{
print "$shortdays[$wday], $shortmonths[$mon] $mday, $longyr, ";
printf("%02d:%02d $tz\n", $hr, $min);
}
### Open File and Read All Data
open (FILE, "counts.txt");
@cnts = ;
close(FILE);
### Delete Old File Before ReWriting it with New Data
$filename = "counts.txt";
if (-e $filename) { unlink("$filename"); }
### Create and Open New File ReInput Old Data While Updating New
$found = 0;
open (NEWFILE,">counts.txt") || die $!;
foreach $cnts(@cnts) {
($page,$cnt,$blk) = split(/\|/, $cnts);
if ($page eq $ENV{'DOCUMENT_URI'}) {
$cnt++;
$showcnt = $cnt;
print NEWFILE "$page|$cnt| \n";
$found = 1;
}
else {
print NEWFILE "$cnts";
}
}
### First Time Counting the New Page
if ($found == 0) {
if ($ENV{'DOCUMENT_URI'} ne "") {
print NEWFILE "$ENV{'DOCUMENT_URI'}|1| \n";
$showcnt = 1;
}
}
&determine_date;
print "";
print "";
&display_date;
print "<\/STRONG><\/font>";
### Print the Count on the Page
print "";
print "($showcnt)";
print "<\/font>";
($sunrise, $sunset) = sunrise( $year, $mon, $mday, 0.1250, 51.3440, 0, 0 );
print "";
print " ", $sunrise;
print " ", $sunset;
print "<\/STRONG><\/font>";
($MoonPhase,$MoonIllum,$MoonAge,$MoonDist,$MoonAng,$SunDist,$SunAng) = &phase(time);
print "";
print " ";
printf("%02d\n", ($MoonPhase*100));
print "% ";
# print " Dist: ", $MoonDist;
print "<\/STRONG><\/font>";
print "<\/td><\/tr><\/table>";
|
home - space - research - links - contact me - colophon
Richard Osborne - 1995-2006 |
|
|