{"id":5055,"date":"2015-02-01T01:55:39","date_gmt":"2015-02-01T00:55:39","guid":{"rendered":"http:\/\/blog.wenzlaff.de\/?p=5055"},"modified":"2021-11-22T17:15:05","modified_gmt":"2021-11-22T16:15:05","slug":"arduino-wie-koennen-rfid-tags-eingelesen-werden","status":"publish","type":"post","link":"http:\/\/blog.wenzlaff.de\/?p=5055","title":{"rendered":"Arduino: Wie k\u00f6nnen RFID Tags eingelesen werden?"},"content":{"rendered":"<p>Wie k\u00f6nnen RFID-Tags eingelesen werden?<\/p>\n<p>Das geht ganz einfach mit einem Arduino Nano und ein 125 kHz EM4100 RFID card reader module (RDM630 UART) das keine 5 Euro inkl. Versand kostet.<\/p>\n<p>Die Belegung des RFID-Readers:<br \/>\n<a href=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2015\/01\/Bildschirmfoto-2015-01-31-um-19.08.39.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2015\/01\/Bildschirmfoto-2015-01-31-um-19.08.39.png\" alt=\"RDM630\" width=\"545\" height=\"319\" class=\"aligncenter size-full wp-image-5065\" srcset=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2015\/01\/Bildschirmfoto-2015-01-31-um-19.08.39.png 545w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2015\/01\/Bildschirmfoto-2015-01-31-um-19.08.39-300x176.png 300w\" sizes=\"auto, (max-width: 545px) 100vw, 545px\" \/><\/a><br \/>\nDie PINs:<\/p>\n<pre class=\"lang:default decode:true \" >\r\n1\uff0ePin Definition \uff08WEIGAND26\uff09\uff1a 2. Pin definition \uff08TTL interface RS232 data format\uff09\uff1a\r\nP1\uff1a                                              P1\uff1a\r\nPIN1     DATA0                                  PIN1     TX                 \r\nPIN2     DATA1                                  PIN2     RX\r\nPIN3                                            PIN3  \r\nPIN4     GND                                    PIN4     GND\r\nPIN5     +5V(DC)                                PIN5     +5V(DC)\r\n\r\nP2:                                               P2:\r\n  PIN1     ANT1                                 PIN1     ANT1\r\n  PIN2     ANT2                                 PIN2     ANT2\r\n\r\nP3:                                              P3:\r\n  PIN1     LED                                  PIN1     LED\r\n  PIN2     +5V(DC)                              PIN2     +5V(DC)\r\n  PIN3     GND                                  PIN3     GND\r\n<\/pre>\n<p>Spec RDM630: Baud Rate: 9600bps,N,8,1, Frequenze: 125 kHz, DC 5V (+-5%), <50 mA, Empfangsbereich: 2 bis 5 cm, Checksum card 10byte Data mit XOR\n\nSo sieht der Aufbau aus:\n<a href=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2015\/01\/IMG_3395-e1422724782793.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2015\/01\/IMG_3395-e1422724782793.jpg\" alt=\"EM4100\" width=\"3264\" height=\"2448\" class=\"aligncenter size-full wp-image-5056\" srcset=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2015\/01\/IMG_3395-e1422724782793.jpg 3264w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2015\/01\/IMG_3395-e1422724782793-300x225.jpg 300w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2015\/01\/IMG_3395-e1422724782793-1024x768.jpg 1024w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2015\/01\/IMG_3395-e1422724782793-900x675.jpg 900w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/a><\/p>\n<p>Es sind nur 3 Verbindungen zwischen dem Arduino und dem RDM630 n\u00f6tig und zwar:<\/p>\n<pre class=\"lang:default decode:true \" >  \r\n  Arduino Nano: D6 auf PIN 1 des RDM630 (TX)\r\n               +5v auf PIN 5 des RDM630 (+5 Volt)\r\n               GND auf PIN 4 des RDM630 (GND)\r\n               \r\n               Antenne auf P2 PIN 1 und 2 des RDM630\r\n<\/pre>\n<p>Dann folgende Software <a href=\"https:\/\/github.com\/IT-Berater\/wenzlaff.de\/blob\/master\/arduino\/RFIDReader\/RFIDReader.ino\" title=\"rfidreader.ino\" target=\"_blank\" rel=\"noopener\">RFIDReader.ino<\/a> auf den Arduino laden, die den Vorteil hat, das die serielle Konsole frei bleibt.<\/p>\n<pre class=\"lang:c decode:true \" >\/*\r\n  RFIDReader \r\n  \r\n  Beschreibung: Dieses Programm liesst RFID-Tags von Transponer ein und ueberprueft die Checksumme (XOR)\r\n  und gibt die Nummer auf der Seriellen-Konsole aus wenn die Nummer erkannt wurde gefolgt von einem OK. \r\n  \r\n  Folgende Verbindungen sind noetig:\r\n  \r\n  Arduino Nano: D6 auf PIN 1 des RDM630\r\n               +5v auf PIN 5 des RDM630 (+5 Volt)\r\n               GND auf PIN 4 des RDM630 (GND)\r\n               \r\n               Antenne auf P2 PIN 1 und 2 des RDM630\r\n               \r\n  Serielle Konsole auf 57000 Baud stellen.\r\n  \r\n  Compile mit Arduino 1.5.8 IDE. Einstellung: Board Arduino Nano, Prozessor Arduino ATMega328, Programmer USBtinyISP\r\n  \r\n  Der Sketch verwendet 8.216 Bytes (26%) des Programmspeicherplatzes. Das Maximum sind 30.720 Bytes.\r\n  Globale Variablen verwenden 378 Bytes (18%) des dynamischen Speichers, 1.670 Bytes f\u00fcr lokale Variablen verbleiben. Das Maximum sind 2.048 Bytes.\r\n \r\n  Dieses Programm basiert auf dem Beispielprogramm von maniacbug https:\/\/maniacbug.wordpress.com\/2011\/10\/09\/125khz-rfid-module-rdm630\/\r\n  \r\n  Copyright (C) 2015 Thomas Wenzlaff http:\/\/www.wenzlaff.de\r\n \r\n   This program is free software: you can redistribute it and\/or modify\r\n   it under the terms of the GNU General Public License as published by\r\n   the Free Software Foundation, either version 3 of the License, or\r\n   (at your option) any later version.\r\n \r\n   This program is distributed in the hope that it will be useful,\r\n   but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r\n   GNU General Public License for more details.\r\n \r\n   You should have received a copy of the GNU General Public License\r\n   along with this program.  If not, see {http:\/\/www.gnu.org\/licenses\/}.\r\n *\/\r\n#include &lt;SoftwareSerial.h&gt;\r\n \r\n\/\/ Pin definitions\r\n\/\/ Specifies a function to call when an external interrupt occurs. Replaces any previous function that was attached to the interrupt. \r\n\/\/ Most Arduino boards have two external interrupts: numbers 0 (on digital pin 2) and 1 (on digital pin 3). \r\n\/\/ The Arduino Mega has an additional four: numbers 2 (pin 21), 3 (pin 20), 4 (pin 19), and 5 (pin 18). \r\nconst int rfid_irq = 0;\r\n\/\/ PIN 6 ist auf dem Nano der D6 oder der Pin 9 von rechts, wenn die Stecker rechts liegen\r\nconst int rfid_tx_pin = 6;\r\n\/\/ RX wird nicht benoetigt\r\nconst int rfid_rx_pin = 7;\r\n\/\/ Untertrueckung von Rauschen bzw. leer Ausgaben, evl. aendern\r\nconst long LEER = 16843009L;\r\n\/\/ Baud Rate zum Host PC, evl. aendern\r\nconst long baudRate = 57600L;\r\n \r\n\/\/ For communication with RFID module\r\nSoftwareSerial rfid(rfid_tx_pin, rfid_rx_pin);\r\n \r\n\/\/ Indicates that a reading is now ready for processing\r\nvolatile bool ready = false;\r\n \r\n\/\/ Buffer to contain the reading from the module\r\nuint8_t buffer[14];\r\nuint8_t* buffer_at;\r\nuint8_t* buffer_end = buffer + sizeof(buffer);\r\n \r\nvoid rfid_read(void);\r\n \r\nvoid setup(void)\r\n{\r\n  \/\/ Oeffnet die Serielle Verbindung zum Host PC um die Ausgabe der RFID-Tags zu sehen\r\n  \/\/ Geschwindigkeit kann angepasst werden\r\n  Serial.begin(baudRate);\r\n  Serial.println(\"Starte RFID-Reader V. 1.0 von wenzlaff.info\");\r\n \r\n  \/\/ Open software serial connection to RFID module\r\n  pinMode(rfid_tx_pin,INPUT);\r\n  \/\/ muss fest fuer das Modul auf 9600 stehen\r\n  rfid.begin(9600);\r\n  \r\n  Serial.println(\"OK\");\r\n  \r\n  \/\/ Listen for interrupt from RFID module. Fallingfor when the pin goes from high to low. \r\n  attachInterrupt(rfid_irq,rfid_read,FALLING);\r\n}\r\n\r\nvoid loop(void)\r\n{\r\n  if ( ready )\r\n  {\r\n    \/\/ Convert the buffer into a 32-bit value\r\n    uint32_t result = 0;\r\n    \r\n    \/\/ Skip the preamble\r\n    ++buffer_at;\r\n    \r\n    \/\/ Accumulate the checksum, starting with the first value\r\n    uint8_t checksum = rfid_get_next();\r\n    \r\n    \/\/ We are looking for 4 more values\r\n    int i = 4;\r\n    while(i--)\r\n    {\r\n      \/\/ Grab the next value\r\n      uint8_t value = rfid_get_next();\r\n      \r\n      \/\/ Add it into the result\r\n      result &lt;&lt;= 8;\r\n      result |= value;\r\n      \r\n      \/\/ Xor it into the checksum\r\n      checksum ^= value;\r\n    }\r\n    \r\n    \/\/ Pull out the checksum from the data\r\n    uint8_t data_checksum = rfid_get_next();\r\n    \r\n    \/\/ evl. die Nummer anpassen, oder die if abfrage loeschen\r\n     if (result != LEER){    \r\n      if ( checksum == data_checksum ){\r\n        Serial.print(result);\r\n        Serial.println(\" OK\");\r\n      }\r\n    }\r\n    \/\/ We're done processing, so there is no current value\r\n    ready = false;\r\n  }\r\n}\r\n \r\n\/\/ Convert the next two chars in the stream into a byte and\r\n\/\/ return that\r\nuint8_t rfid_get_next(void)\r\n{\r\n  \/\/ sscanf needs a 2-byte space to put the result but we\r\n  \/\/ only need one byte.\r\n  uint16_t result;\r\n \r\n  \/\/ Working space to assemble each byte\r\n  static char byte_chars[3];\r\n  \r\n  \/\/ Pull out one byte from this position in the stream\r\n  snprintf(byte_chars,3,\"%c%c\",buffer_at[0],buffer_at[1]);\r\n  sscanf(byte_chars,\"%x\",&amp;result);\r\n  buffer_at += 2;\r\n  \r\n  return static_cast&lt;uint8_t&gt;(result);\r\n}\r\n \r\nvoid rfid_read(void)\r\n{\r\n  \/\/ Only read in values if there is not already a value waiting to be\r\n  \/\/ processed\r\n  if ( ! ready )\r\n  {\r\n    \/\/ Read characters into the buffer until it is full\r\n    buffer_at = buffer;\r\n    while ( buffer_at &lt; buffer_end )\r\n      *buffer_at++ = rfid.read();\r\n      \r\n    \/\/ Reset buffer pointer so it's easy to read out\r\n    buffer_at = buffer;\r\n  \r\n    \/\/ Signal that the buffer has data ready\r\n    ready = true;\r\n  }\r\n  \r\n}\r\n<\/pre>\n<p>Compile mit der Arduino 1.5.8 IDE.<br \/>\n<figure id=\"attachment_5073\" aria-describedby=\"caption-attachment-5073\" style=\"width: 924px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2015\/02\/Bildschirmfoto-2015-01-31-um-20.15.25.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2015\/02\/Bildschirmfoto-2015-01-31-um-20.15.25.png\" alt=\"Arduino IDE\" width=\"924\" height=\"855\" class=\"size-full wp-image-5073\" srcset=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2015\/02\/Bildschirmfoto-2015-01-31-um-20.15.25.png 924w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2015\/02\/Bildschirmfoto-2015-01-31-um-20.15.25-300x278.png 300w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2015\/02\/Bildschirmfoto-2015-01-31-um-20.15.25-900x833.png 900w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/a><figcaption id=\"caption-attachment-5073\" class=\"wp-caption-text\">Arduino IDE<\/figcaption><\/figure><\/p>\n<p>Einstellung in der IDE:<br \/>\nBoard Arduino Nano, Prozessor Arduino ATMega328, Programmer USBtinyISP<br \/>\nSerielle Konsole auf 57000 Baud stellen<br \/>\nund einen RFID-Tag an die Antenne halten:<\/p>\n<figure id=\"attachment_5071\" aria-describedby=\"caption-attachment-5071\" style=\"width: 642px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2015\/02\/Bildschirmfoto-2015-01-31-um-20.10.51.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2015\/02\/Bildschirmfoto-2015-01-31-um-20.10.51.png\" alt=\"Serielle Konsole Arduino NANO RFIDReader\" width=\"642\" height=\"266\" class=\"size-full wp-image-5071\" srcset=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2015\/02\/Bildschirmfoto-2015-01-31-um-20.10.51.png 642w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2015\/02\/Bildschirmfoto-2015-01-31-um-20.10.51-300x124.png 300w\" sizes=\"auto, (max-width: 642px) 100vw, 642px\" \/><\/a><figcaption id=\"caption-attachment-5071\" class=\"wp-caption-text\">Serielle Konsole Arduino NANO RFIDReader<\/figcaption><\/figure>\n<p>Es wird eine Reichweite von ca. <strong>4 cm<\/strong> erreicht. Wenn die Antenne unter der Schreibtischplatte montiert wird, kann der RFID-Tag sicher gelesen werden, wenn der Tag oben drauf liegt (Anwesendheitskennung).<\/p>\n<p>Habt ihr eine Idee, wie die Reichweite vergr\u00f6\u00dfert werden kann?<br \/>\nOder einen guten Anwendungsfall? <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Wie k\u00f6nnen RFID-Tags eingelesen werden? Das geht ganz einfach mit einem Arduino Nano und ein 125 kHz EM4100 RFID card reader module (RDM630 UART) das keine 5 Euro inkl. Versand kostet. Die Belegung des RFID-Readers: Die PINs: 1\uff0ePin Definition \uff08WEIGAND26\uff09\uff1a 2. Pin definition \uff08TTL interface RS232 data format\uff09\uff1a P1\uff1a P1\uff1a PIN1 DATA0 PIN1 TX PIN2 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/blog.wenzlaff.de\/?p=5055\" class=\"more-link\"><span class=\"screen-reader-text\">\u201eArduino: Wie k\u00f6nnen RFID Tags eingelesen werden?\u201c <\/span>weiterlesen<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[220,562,538,79],"tags":[1840,2188,632,1936,1934,563,1935,291,1933],"class_list":["post-5055","post","type-post","status-publish","format-standard","hentry","category-anleitung","category-arduino","category-elektronik","category-programmierung","tag-antenne","tag-arduino","tag-arduino-nano","tag-card-reader","tag-em4100","tag-nano","tag-rdm630","tag-rfid","tag-rfid-tags"],"_links":{"self":[{"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=\/wp\/v2\/posts\/5055","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5055"}],"version-history":[{"count":0,"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=\/wp\/v2\/posts\/5055\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5055"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}