Created
October 9, 2011 17:16
-
-
Save maniacbug/1273929 to your computer and use it in GitHub Desktop.
Simple example of reading the 125Khz RFID module RDM630
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SoftwareSerial.h> | |
// Pin definitions | |
const int rfid_irq = 0; | |
const int rfid_tx_pin = 6; | |
const int rfid_rx_pin = 7; | |
// For communication with RFID module | |
SoftwareSerial rfid(rfid_tx_pin, rfid_rx_pin); | |
// Indicates that a reading is now ready for processing | |
volatile bool ready = false; | |
// Buffer to contain the reading from the module | |
uint8_t buffer[14]; | |
uint8_t* buffer_at; | |
uint8_t* buffer_end = buffer + sizeof(buffer); | |
void rfid_read(void); | |
void setup(void) | |
{ | |
// Open serial connection to host PC to view output | |
Serial.begin(57600); | |
Serial.println("rfid_simple"); | |
// Open software serial connection to RFID module | |
pinMode(rfid_tx_pin,INPUT); | |
rfid.begin(9600); | |
// Listen for interrupt from RFID module | |
attachInterrupt(rfid_irq,rfid_read,FALLING); | |
} | |
void loop(void) | |
{ | |
if ( ready ) | |
{ | |
ready = false; | |
// Print the buffer | |
Serial.print("Reading: "); | |
const uint8_t* bp = buffer; | |
while ( bp < buffer_end ) | |
Serial.print(*bp++); | |
Serial.println(); | |
} | |
} | |
void rfid_read(void) | |
{ | |
// Read characters into the buffer until it is full | |
buffer_at = buffer; | |
while ( buffer_at < buffer_end ) | |
*buffer_at++ = rfid.read(); | |
// Signal that the buffer has data ready | |
ready = true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment