Hardware Reference
In-Depth Information
X10 device addresses have a two-tier structure. There are
16 house codes —labeled A through P—and within each
house code you can have 16 individual units. These are
assigned unit codes . Each X10 module has two click-wheels
to set the house code and the unit code. For this project,
get at least two appliance or lamp modules. Set the first
module to house code A, unit 1, and the second module to
house code A, unit 2.
More Serial Ports:
Software Serial
The Arduino's hardware serial connection (digital pins
0 and 1, labeled RX and TX) allow it to send and receive
serial data reliably, no matter what your code is doing,
because the processor has a dedicated UART (Universal
Asynchronous Receiver-Transmitter) module that listens
for serial all the time. What do you do when you need
to attach more than one asynchronous serial device to
your Arduino? The Arduino Mega 2560 has four UARTs,
but you may not need all that a Mega has to offer just to
get another serial port. This is where the SoftwareSerial
library comes in handy. SoftwareSerial allows you to use
two digital pins as a "fake" UART. The library can listen
for incoming serial on those pins, and transmit as well.
Because it's not a dedicated hardware UART, Softwa-
reSerial isn't as reliable as hardware serial at very high
or very low speeds, though it does well from 4800bps
through 57.6kbps. It can be very useful when you need
an extra port, or when you want to use the hardware
serial port for diagnostic purposes, as in this project.
Construction
The box for this project is similar to the ones for the Pong
clients in Chapter 5. In fact, it's made from the same
template, with the side heights and widths changed
slightly. There's only a single LED hole, and there's no
hole for the Ethernet jack (since there isn't one!). Instead,
there's a hole for the X10 cable to go through. Figure 9-12
shows the finished prototype, and a commercially available
version of an RFID door lock as well.
X
The first thing you
want to do is test
both parts of your circuit. This sketch
just reads from the RFID reader via a
software serial port, and writes what it
got to the hardware serial port. Open
the Serial Monitor and wave a tag or
two in front of the reader. You should
see their tag numbers show up in the
Serial Monitor. Write down your tags'
IDs—you'll need them later.
/*
RFID Reader
Context: Arduino
*/
#include <SoftwareSerial.h>
SoftwareSerial rfid(7,8);
Test the RFID
// 7 is rx, 8 is tx
void setup() {
// begin serial:
Serial.begin(9600);
rfid.begin(9600);
}
void loop() {
// read in from the reader and
// write it out to the serial monitor:
if (rfid.available()) {
char thisChar = rfid.read();
Serial.write(thisChar);
}
}
Search WWH ::




Custom Search