Hardware Reference
In-Depth Information
There's only a difference between these two shields when
you're communicating with the RFID reader via asynchro-
nous serial, because they use differing pins for that. When
you're communicating with the reader using I2C, as you
will later in the project, they're functionally identical.
If you're not using a shield, connect the SonMicro reader
to a USB-to-Serial adapter, as shown in Figure 9-13. Then
load the appropriate Arduino sketch below, and you're
ready to try the Processing sketch on the following pages.
X
This project was built using the TinkerKit RFID shield. It's
been tested on both, however.
bypass It (TinkerKit)
/*
TinkerKit RFID shield serial pass through
Context: Arduino
*/
This sketch passes data from a
SonMicro RFID reader on a TinkerKit
RFID shield to the Arduino's USB-
to-Serial adapter, bypassing the
microcontroller. When your board is
programmed this way, the Arduino
acts as a USB-to-Serial adapter for the
SonMicro reader.
void setup() {
}
void loop() {
}
/*
Spark Fun RFID shield serial pass through
Context: Arduino
*/
bypass It (Spark Fun)
This sketch passes data from a
SonMicro RFID reader on a Spark Fun
RFID shield to the Arduino's hardware
serial port, and vice versa. When
your board is programmed this way,
the Arduino acts as a USB-to-Serial
adapter for the SonMicro reader.
#include <SoftwareSerial.h>
// using pins 7 and 8 (7 is the Arduino's RX, 8 is TX)
SoftwareSerial rfid(7,8);
void setup() {
rfid.begin(19200); // set up software serial port
Serial.begin(19200); // set up serial port
}
void loop() {
// pass any hardware serial to the software serial:
if (Serial.available()) {
rfid.write(Serial.read());
}
// pass any software serial to the hardware serial:
if (rfid.available()) {
Serial.write(rfid.read());
}
}
 
Search WWH ::




Custom Search