Skip to content

Instantly share code, notes, and snippets.

@asanka-code
Forked from maniacbug/rfid_simple.pde
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asanka-code/224f98951f5f73ceda25 to your computer and use it in GitHub Desktop.
Save asanka-code/224f98951f5f73ceda25 to your computer and use it in GitHub Desktop.
#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