Hardware Reference
In-Depth Information
So far, you've only used the Arduino board as a serial pass-
through, but for this phase of the project, you'll control the
RFID reader using the I2C protocol. The Wire library that
comes with Arduino lets you control I2C devices. For the
main sketch, the Wire library commands will be wrapped
inside another library that's specifically for the RFID
reader. But to make sure things are working, and to see
I2C in action, try the sketch below. It sends a command to
the reader to ask for the firmware revision, and prints the
results to the Serial Monitor. You'll recognize some of the
SonMicro communications protocol in this sketch.
Read the Firmware
/*
SM130 Firmware reader
Context: Arduino
*/
#include <Wire.h>
This sketch reads the firmware of the
SM130 module.
void setup() {
// initialize serial and I2C:
Serial.begin(9600);
Wire.begin();
// give the reader time to reset:
delay(2000);
Serial.println("asking for firmware");
// open the I2C connection,
// the I2C address for the reader is 0x42:
Wire.beginTransmission(0x42);
Wire.write(0x01); // length
Wire.write(0x81); // command
Wire.write(0x82); // checksum
Wire.endTransmission();
// reader needs 50ms in between responses:
delay(50);
Serial.print("getting reply: ");
// wait for 10 bytes back via I2C:
Wire.requestFrom(0x42,10);
// don't do anything until new bytes arrive:
while(!Wire.available()) {
delay(50);
}
// when new bytes arrive on the I2C bus, read them:
while(Wire.available()) {
Serial.write(Wire.read());
}
// add a newline:
Serial.println();
}
void loop() {
}
 
Search WWH ::




Custom Search