Notatnik: Czytnik RFID na Arduino

Potrzebowałem zrobić czytnik RFID. Wykorzystałem Arduino, czytnik RFID z antenką od Seeedstudio oraz trochę kodu w Pythonie.

Sam czytnik podłączony do pinów 0 i 1 Arduino, dodatkowo dodałem buzer z generatorem w celu detekcji odczytu ID karty. Podłączyłem go po pin 10 Arduino przez rezystor.

RFID na Arduino

Arduino:

	
unsigned char p;
	
boolean printed = 0;
	
void setup()
{
Serial.begin(9600);
Serial.println("RFID");
}
	
void loop()
{
if (Serial.available()>0)
{
p = Serial.read();
if (p == 2)
{
while (p != 3)
{
delay(5);
p = Serial.read();
Serial.print(p);
tone(10, 31, 1000/8);
}
printed = 1;
delay(150);
}
}
if (printed)
{
Serial.println("\n----------");
printed = 0;
}
}
	

Klient:

	
#!/usr/bin/python2
# -*- coding: utf-8 -*-
	
import serial
import re
	
rfid = serial.Serial('/dev/ttyUSB0', 9600)
	
while 1:
raw = rfid.readline().strip()
code = re.search("[0-9]{25}", raw)
if code:
print "ID: ", code.group(0)
	

Wynik:

	
[artek@archbox Desktop]$ ./rfid.py
ID: 48xxxxxxxxxxxxxxxxxxx03
ID: 48xxxxxxxxxxxxxxxxxxx03
ID: 48xxxxxxxxxxxxxxxxxxx03
ID: 52xxxxxxxxxxxxxxxxxxx93
	

 

 

Ten wpis umieszczono w kategorii Arduino, Elektronika, Uncategorized i otagowano jako , , . Możesz dodać go do zakładek permalink. Dodaj komentarz lub dodaj odpowiedź (trackback): Trackback URL.

Skomentuj

Twój adres email nie zostanie opublikowany i nie będzie rozpowszechniany. Wymagane pola są oznaczone *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Turn on pictures to see the captcha *

Switch to our mobile site