Hardware Reference
In-Depth Information
Listing 6-7 shows the code for simulating the RFID.
Listing 6-7. RFID Simulator
#include <SoftwareSerial.h>
void setup() {
Serial.begin(2400); // Hardware serial for Monitor 2400bps
pinMode(2,INPUT);
} // end void setup()
void loop() {
SoftwareSerial RFID = SoftwareSerial(8,9); // pin 8 noconnect, pin 9 transmit
RFID.begin(2400);
if(LOW == digitalRead(2)) { // does the sensor need to be active
RFID.write(10); // transmit header
RFID.write("HelloWorld"); // transmit Tag ID code
RFID.write(13); // transmit end
}
} // end void loop()
Verifying the Code
Get everything uploaded and connected, and start the serial monitor running at 2400 baud. The code for simulating
the RFID sensor sets up software serial at 2400 baud, and then waits for pin 2 to be low before sending the data
sequence. The data that is sent to the reader Arduino starts with a byte value of 10 and ends with a byte value of 13.
HelloWorld will then be printed to the serial monitor TAG code is: . HelloWorld just happened to be ten characters
and can be replaced with actual tag codes. Sometimes incoherent data will be printed. This is caused by the serial
not being synchronous. More code is needed to verify the data, but for this application, it just needs to get at least one
good RFID code to compare to the list of valid codes to perform an action.
I2C
The communication method I2C, also known as two-wire, is a synchronous serial communication method using
one wire for a clock signal and another wire for data. I2C is a cousin to basic serial, with a few differences in what the
hardware does during communications. Sensors that use this type of communication can handle a wide variety of
data, devices, and commands. Sensors that communicate via I2C can have multiple functions measuring multiple
activities on the same package. The sensor that will be simulated in this section is the SRF10 Ultrasonic Ranger Finder.
Its code is included in the Arduino IDE by selecting File Examples Wire SFRRange_reader, and should be
loaded on the Arduino to be used as the reader.
I2C data transfers happen on one wire, meaning that one only device can transmit at a time; however, more
than two devices can be connected together with just two wires. In most common I2C setups, there is one master
device that is the receiver of the data and the controller of what devices communicate. Arduino includes a library
that implements this communication, and for most basic setups, it works well, especially when used on the master
device. The library lacks a bit of finesse that is required when attempting to simulate the workings of an I2C
sensors, however.
Getting the best control to simulate sensors using I2C requires manipulating the hardware registers; this method of
setting up the I2C bus is a bit more complicated, but isn't difficult once you have a bit of understanding of the registers.
refer to section 22.5 in the atmega 328p data sheet (pages 223-247); this section gives an overview of the
i2C module included in the arduino's microcontroller.
Note
 
 
Search WWH ::




Custom Search