RFID reader: Rozdiel medzi revíziami
Z SensorWiki
(→Čítačka RFID kariet) |
(→Čítačka RFID kariet) |
||
(2 medziľahlé úpravy od rovnakého používateľa nie sú zobrazené.) | |||
Riadok 2: | Riadok 2: | ||
== Čítačka RFID kariet == | == Čítačka RFID kariet == | ||
[[Súbor:RFIDreader.jpg|left]] | [[Súbor:RFIDreader.jpg|left]] | ||
+ | |||
+ | |||
* Čo je to [http://en.wikipedia.org/wiki/Radio-frequency_identification RFID] (wikipedia.org) | * Čo je to [http://en.wikipedia.org/wiki/Radio-frequency_identification RFID] (wikipedia.org) | ||
Riadok 7: | Riadok 9: | ||
* [http://www.parallax.com/Portals/0/Downloads/docs/prod/audiovis/28140-28340-RFID%20Reader-v2.1.pdf Datasheet] (parallax.com) | * [http://www.parallax.com/Portals/0/Downloads/docs/prod/audiovis/28140-28340-RFID%20Reader-v2.1.pdf Datasheet] (parallax.com) | ||
* [http://www.gumbolabs.org/2009/10/17/parallax-rfid-reader-arduino/ Príklad s vysvetlivkami] (gumolabs.org) | * [http://www.gumbolabs.org/2009/10/17/parallax-rfid-reader-arduino/ Príklad s vysvetlivkami] (gumolabs.org) | ||
+ | |||
+ | |||
Aby sme sa vyhli zápasu o jediný sériový kanál procesora, pripojíme čítačku | Aby sme sa vyhli zápasu o jediný sériový kanál procesora, pripojíme čítačku | ||
Riadok 16: | Riadok 20: | ||
Arduino D8 to RFID SOUT | Arduino D8 to RFID SOUT | ||
Arduino GND to RFID GND | Arduino GND to RFID GND | ||
+ | |||
+ | |||
+ | Example code (modified source from [http://arduino.cc/playground/Learning/PRFID Arduino Playground]): | ||
+ | <source lang="c"> | ||
+ | #include <SoftwareSerial.h> | ||
+ | // Hardware connections | ||
+ | #define ENABLE 11 | ||
+ | #define SOUT rxpin | ||
+ | #define rxPin 8 | ||
+ | #define txPin 9 | ||
+ | // RFID reader SOUT pin connected to Serial RX pin at 2400bps to pin8 | ||
+ | |||
+ | int val = 0; | ||
+ | char code[10]; | ||
+ | int bytesread = 0; | ||
+ | |||
+ | void setup() | ||
+ | { | ||
+ | Serial.begin(9600); // Hardware serial for Monitor 2400bps | ||
+ | pinMode(ENABLE,OUTPUT); // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin | ||
+ | digitalWrite(ENABLE, LOW); // Activate the RFID reader | ||
+ | } | ||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | SoftwareSerial RFID = SoftwareSerial(rxPin,txPin); | ||
+ | RFID.begin(2400); | ||
+ | |||
+ | if((val = RFID.read()) == 10) | ||
+ | { // check for header | ||
+ | bytesread = 0; | ||
+ | while(bytesread<10) | ||
+ | { // read 10 digit code | ||
+ | val = RFID.read(); | ||
+ | if((val == 10)||(val == 13)) | ||
+ | { // if header or stop bytes before the 10 digit reading | ||
+ | break; // stop reading | ||
+ | } | ||
+ | code[bytesread] = val; // add the digit | ||
+ | bytesread++; // ready to read next digit | ||
+ | } | ||
+ | |||
+ | if(bytesread == 10) | ||
+ | { // if 10 digit read is complete | ||
+ | Serial.print("TAG code is: "); // possibly a good TAG | ||
+ | Serial.println(code); // print the TAG code | ||
+ | } | ||
+ | bytesread = 0; | ||
+ | delay(500); // wait for a second | ||
+ | } | ||
+ | } | ||
+ | |||
+ | </source> | ||
+ | |||
+ | [[Súbor:RFIDscreenshot.png]] |
Aktuálna revízia z 07:16, 3. október 2012
Čítačka RFID kariet
- Čo je to RFID (wikipedia.org)
- Product page (parallax.com)
- Datasheet (parallax.com)
- Príklad s vysvetlivkami (gumolabs.org)
Aby sme sa vyhli zápasu o jediný sériový kanál procesora, pripojíme čítačku na iný pin a využijeme knižnicu SoftwareSerial cez rxPin=8
Popis zapojenia (nie je v konflikte ani s LCDAppMod):
Arduino +5V to RFID Vcc Arduino D9 to RFID /ENABLE Arduino D8 to RFID SOUT Arduino GND to RFID GND
Example code (modified source from Arduino Playground):
#include <SoftwareSerial.h>
// Hardware connections
#define ENABLE 11
#define SOUT rxpin
#define rxPin 8
#define txPin 9
// RFID reader SOUT pin connected to Serial RX pin at 2400bps to pin8
int val = 0;
char code[10];
int bytesread = 0;
void setup()
{
Serial.begin(9600); // Hardware serial for Monitor 2400bps
pinMode(ENABLE,OUTPUT); // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
digitalWrite(ENABLE, LOW); // Activate the RFID reader
}
void loop()
{
SoftwareSerial RFID = SoftwareSerial(rxPin,txPin);
RFID.begin(2400);
if((val = RFID.read()) == 10)
{ // check for header
bytesread = 0;
while(bytesread<10)
{ // read 10 digit code
val = RFID.read();
if((val == 10)||(val == 13))
{ // if header or stop bytes before the 10 digit reading
break; // stop reading
}
code[bytesread] = val; // add the digit
bytesread++; // ready to read next digit
}
if(bytesread == 10)
{ // if 10 digit read is complete
Serial.print("TAG code is: "); // possibly a good TAG
Serial.println(code); // print the TAG code
}
bytesread = 0;
delay(500); // wait for a second
}
}