├── src ├── RDM6300.h └── RDM6300.cpp ├── README.md └── examples └── basic_example └── basic_example.ino /src/RDM6300.h: -------------------------------------------------------------------------------- 1 | /**/ -------------------------------------------------------------------------------- /src/RDM6300.cpp: -------------------------------------------------------------------------------- 1 | /**/ 2 | //this file is the property of yasir shahzad -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rdm6300 2 | A simple library to interface with RDM6300 RFID reader. 3 | 4 | ## Features 5 | * Fast and single tag reading, even if it held near the antenna for a while. 6 | * Using a single given GPIO pin or a `Stream`. 7 | * Can tell if the tag is still near the antenna. 8 | * Both hardware and software uart (serial) support on esp8266. 9 | * SAMD hardware uart (serial) support. 10 | * Both SoftwareSerial and [AltSoftSerial](https://github.com/PaulStoffregen/AltSoftSerial) support. 11 | 12 | ## Getting Started 13 | 14 | ### Hardware 15 | * RDM6300 module with matching antenna. 16 | * 125KHz RFID tags. 17 | * Microcontroller (arduino, esp8266, esp32...). 18 | 19 | ![rdm6300_connections](../master/doc/rdm6300_connections.png "rdm6300_connections") 20 | 21 | ### Software 22 | A simple RFID tag reader with textual serial output: 23 | [```examples/read_to_serial/read_to_serial.ino```](examples/read_to_serial/read_to_serial.ino) 24 | 25 | #### API 26 | * ```void begin(Stream *stream)``` - Initialize instance to read from a given stream. 27 | * ```void begin(int rx_pin, uint8_t uart_nr=1)``` - Initialize instance to read from a given pin. 28 | * ```void set_tag_timeout(uint32_t tag_timeout_ms)``` - sets the tag "valid" timeout, (300ms default) 29 | RDM6300 sends packet every 65ms when tag is near- better higher values for debouncing. 30 | * ```uint32_t get_tag_id()``` - Returns the tag_id as long as it is near, 0 otherwise. 31 | * ```uint32_t get_new_tag_id()``` - Returns the tag_id of a "new" near tag, 32 | following calls will return 0 as long as the same tag is kept near. 33 | * ~~```bool update()``` - Updates the internal values must be called repeatedly!~~ **deprecated!** 34 | * ~~```bool is_tag_near()``` - Returns whether a tag is held near.~~ **deprecated!** use ```get_tag_id()```. 35 | ## Enjoy!! 36 | A.E.TECH 37 | -------------------------------------------------------------------------------- /examples/basic_example/basic_example.ino: -------------------------------------------------------------------------------- 1 | #include 2 | //*********************************************************** 3 | //.................(DEFINING THE VARIABLE)................... 4 | //*********************************************************** 5 | 6 | unsigned char rx_data=0, flag[31], flag1=0; 7 | int id=0, id1=0; 8 | unsigned char card[]={" "}; 9 | //unsigned char card[]={"130049B044AE"}; 10 | //*********************************************** 11 | unsigned char card1[12]={'3','7','0','0','8','0','4','4','6','A','9','9'}; 12 | unsigned char card2[12]={'3','7','0','0','8','0','9','2','A','B','8','E'}; 13 | unsigned char card3[12]={'3','7','0','0','8','0','9','2','D','D','F','8'}; 14 | unsigned char card4[12]={'3','9','0','0','8','9','1','6','7','3','D','5'}; 15 | unsigned char card5[12]={'3','9','0','0','3','A','0','6','7','C','7','9'}; 16 | unsigned char card6[12]={'3','9','0','0','8','9','1','9','9','B','3','2'}; 17 | unsigned char card7[12]={'3','9','0','0','3','9','7','F','5','B','2','4'}; 18 | unsigned char card8[12]={'3','7','0','0','8','0','2','D','C','D','5','7'}; 19 | unsigned char card9[12]={'3','7','0','0','8','0','2','D','D','E','4','4'}; 20 | unsigned char card10[12]={'3','9','0','0','8','9','2','E','F','4','6','A'}; 21 | //*********************************************** 22 | unsigned char card11[12]={'3','9','0','0','8','9','2','F','F','A','6','5'}; 23 | unsigned char card12[12]={'3','9','0','0','3','A','0','7','7','8','7','C'}; 24 | unsigned char card13[12]={'3','9','0','0','3','8','B','9','3','4','8','C'}; 25 | unsigned char card14[12]={'3','9','0','0','3','8','A','3','3','E','9','C'}; 26 | unsigned char card15[12]={'3','9','0','0','8','9','2','8','9','4','0','C'}; 27 | unsigned char card16[12]={'3','7','0','0','7','E','7','C','6','D','5','8'}; 28 | unsigned char card17[12]={'3','7','0','0','8','0','3','7','4','5','C','5'}; 29 | unsigned char card18[12]={'3','7','0','0','8','0','1','5','D','8','7','A'}; 30 | unsigned char card19[12]={'3','7','0','0','8','0','8','7','7','9','4','9'}; 31 | unsigned char card20[12]={'3','7','0','0','8','0','9','2','E','E','C','B'}; 32 | //*********************************************** 33 | unsigned char card21[12]={'3','7','0','0','7','E','7','E','5','C','6','B'}; 34 | unsigned char card22[12]={'3','7','0','0','7','E','5','D','E','0','F','4'}; 35 | unsigned char card23[12]={'3','9','0','0','3','9','B','C','5','D','E','1'}; 36 | unsigned char card24[12]={'3','9','0','0','3','9','B','C','9','2','2','E'}; 37 | unsigned char card25[12]={'3','9','0','0','3','9','B','C','8','E','3','2'}; 38 | unsigned char card26[12]={'3','9','0','0','3','9','9','5','8','9','1','C'}; 39 | unsigned char card27[12]={'3','9','0','0','3','9','D','B','4','1','9','A'}; 40 | unsigned char card28[12]={'3','7','0','0','8','0','1','8','1','1','B','E'}; 41 | unsigned char card29[12]={'3','9','0','0','3','9','D','B','7','5','A','E'}; 42 | unsigned char card30[12]={'3','9','0','0','3','9','C','A','B','F','7','5'}; 43 | 44 | long time1,time2,far; 45 | /*------------------------------------------------*/ 46 | //pointers vs arrays 47 | unsigned char check(unsigned char *first, unsigned char *second, unsigned char add , unsigned char len) //first and second are the string decleared 48 | { 49 | unsigned char i=0; 50 | for(i=add;i 0){ 63 | time1=30; //300ms 64 | while(Serial.read()!= 2) //mean received some data and wait for the come of 2 for further processing. here 2 is start of message 65 | { //receivd some data wait for 2 detection unless data is coming and putting the data in garbege. 66 | // if there is no 2 and data has ended then check whether 300ms has passed or not from the data detection 67 | while(Serial.available() == 0) //if there is no data coming to the serial port 68 | { 69 | if(!time1){goto looop;} //after 300msec the timer1 will be equal to zero so the program will shift to the loop 70 | } 71 | } 72 | //*****************read card**************** 73 | for(far=0;far<12;far++) 74 | { 75 | time1=20; //mean we received some digits out of 12 if remaining digits never come then wait 200ms if again not then go to loop. 76 | while(!Serial.available()) //if there's nothing on the serial port 77 | { 78 | if(!time1){goto looop;} //after 200msec it will shift to the loop; 79 | } 80 | card[far]= Serial.read(); 81 | } 82 | //*****************mach card********** 83 | if(check(card,card1,3,12)){flag[1]=1;return 1;} 84 | else if(check(card,card2,3,12)){flag[2]=1;return 2;} 85 | else if(check(card,card3,3,12)){flag[3]=1;return 3;} 86 | else if(check(card,card4,3,12)){flag[4]=1;return 4;} 87 | else if(check(card,card5,3,12)){flag[5]=1;return 5;} 88 | else if(check(card,card6,3,12)){flag[6]=1;return 6;} 89 | else if(check(card,card7,3,12)){flag[7]=1;return 7;} 90 | else if(check(card,card8,3,12)){flag[8]=1;return 8;} 91 | else if(check(card,card9,3,12)){flag[9]=1;return 9;} 92 | else if(check(card,card10,3,12)){flag[10]=1;return 10;} 93 | else if(check(card,card11,3,12)){flag[11]=1;return 11;} 94 | else if(check(card,card12,3,12)){flag[12]=1;return 12;} 95 | else if(check(card,card13,3,12)){flag[13]=1;return 13;} 96 | else if(check(card,card14,3,12)){flag[14]=1;return 14;} 97 | else if(check(card,card15,3,12)){flag[15]=1;return 15;} 98 | else if(check(card,card16,3,12)){flag[16]=1;return 16;} 99 | else if(check(card,card17,3,12)){flag[17]=1;return 17;} 100 | else if(check(card,card18,3,12)){flag[18]=1;return 18;} 101 | else if(check(card,card19,3,12)){flag[19]=1;return 19;} 102 | else if(check(card,card20,3,12)){flag[20]=1;return 20;} 103 | else if(check(card,card21,3,12)){flag[21]=1;return 21;} 104 | else if(check(card,card22,3,12)){flag[22]=1;return 22;} 105 | else if(check(card,card23,3,12)){flag[23]=1;return 23;} 106 | else if(check(card,card24,3,12)){flag[24]=1;return 24;} 107 | else if(check(card,card25,3,12)){flag[25]=1;return 25;} 108 | else if(check(card,card26,3,12)){flag[26]=1;return 26;} 109 | else if(check(card,card27,3,12)){flag[27]=1;return 27;} 110 | else if(check(card,card28,3,12)){flag[28]=1;return 28;} 111 | else if(check(card,card29,3,12)){flag[29]=1;return 29;} 112 | else if(check(card,card30,3,12)){flag[30]=1;return 30;} 113 | } 114 | if(!time2){return 0;} //if the time2 is equal to zero then return the 0 115 | } //End of while(1) 116 | } //End of read_card() 117 | 118 | 119 | 120 | //**************************************** 121 | void setup() 122 | { 123 | //10000 = 10ms 124 | Timer1.initialize(10000); // set a timer of length 100000 microseconds (or 0.1 sec - or 10Hz => the led will blink 5 times, 5 cycles of on-and-off, per second) 125 | Timer1.attachInterrupt( timerIsr ); // attach the service routine here 126 | Serial.begin(9600); 127 | } 128 | 129 | void loop() { 130 | //********************************* 131 | 132 | id = read_card(); 133 | if(id != id1){ 134 | Serial.write(id); 135 | id1 = id; 136 | } 137 | //********************************* 138 | //for(int i=0;i<30;i++){flag[i] = 0;} 139 | 140 | } 141 | 142 | 143 | //*************************** 144 | void timerIsr() 145 | { 146 | if(time1 > 0){time1--;} 147 | if(time2 > 0){time2--;} 148 | } 149 | 150 | --------------------------------------------------------------------------------