Привет! У меня есть Arduino Mеga 2560 и 3 RFID сенсора. Каждый сенсор должен идентифицировать одну из 3-х кард и у меня с этим проблемы, потому что все примеры, которые мне удалось найти, с 10-битными метками (напрмиер https://github.com/tigoe/GettingStartedWithRFID/blob/master/ArduinoSketch03_2/ArduinoSketch03_2.ino), а у меня 13 бит. Как мне нужно изменить или добавить код или нужен какой то другой путь? Мне очень сложно это дается, поэтому решила попросить помощи. Спасибо! Сейчас мой код выглядит так Код (Text): #include <SoftwareSerial.h> unsigned char buffer[64]; // buffer array for data recieve over serial port int count=0; // counter for buffer array const int tagLength = 13; const int startByte = 0x0A; const int endByte = 0x0D; String matchingTag = "7100866EEB722"; void setup() { Serial.begin(9600); // the Serial port of Arduino baud rate. Serial1.begin(9600); // the Serial port of Arduino baud rate. Serial2.begin(9600); // the Serial port of Arduino baud rate. Serial3.begin(9600); // the SoftSerial baud rate Serial.println("RFID module started in Auto Read Mode, Waiting for Card..."); } void loop() { if (Serial1.available()) // if date is comming from softwareserial port ==> data is comming from SoftSerial shield { while(Serial1.available()) // reading data into char array { buffer[count++]=Serial1.read(); // writing data into array if(count == 64)break; } Serial.write(buffer,count); // if no data transmission ends, write buffer to hardware serial port clearBufferArray(); // call clearBufferArray function to clear the storaged data from the array count = 0; } if (Serial2.available()) // if date is comming from softwareserial port ==> data is comming from SoftSerial shield { while(Serial2.available()) // reading data into char array { buffer[count++]=Serial2.read(); // writing data into array if(count == 64)break; } Serial.write(buffer,count); // if no data transmission ends, write buffer to hardware serial port clearBufferArray(); // call clearBufferArray function to clear the storaged data from the array count = 0; // set counter of while loop to zero } if (Serial3.available()) // if date is comming from softwareserial port ==> data is comming from SoftSerial shield { while(Serial3.available()) // reading data into char array { buffer[count++]=Serial3.read(); // writing data into array if(count == 64)break; } Serial.write(buffer,count); // if no data transmission ends, write buffer to hardware serial port clearBufferArray(); // call clearBufferArray function to clear the storaged data from the array count = 0; // set counter of while loop to zero } } void clearBufferArray() // function to clear buffer array { for (int i=0; i<count;i++) { buffer[i]=NULL; } // clear all index of array with command NULL }
У меня 1 сканер должен распознавать 3 карты. И по ним определяет кто вошел. Реализовано просто. Можно использовать карты любой битности. Код (Text): //** Считываемый ключ unsigned char buffer[64]; //** Список зарегистрированных ключей unsigned char buffer1[64] = {'1','7','1','0','0','8','6','3','B','6','1','A','D','1'}; unsigned char buffer2[64] = {'1','7','1','0','0','8','6','3','B','6','0','A','C','1'}; unsigned char buffer3[64] = {'1','7','1','0','0','8','6','3','B','5','5','9','9','1'}; //** Список счетчиков для зарегистрированных ключей int RFIDcontCount1 = 0; int RFIDcontCount2 = 0; int RFIDcontCount3 = 0; void RFID() { if (SoftSerial.available()) // if date is comming from softwareserial port ==> data is comming from SoftSerial shield { while(SoftSerial.available()) // reading data into char array { buffer[RFIDcount]=SoftSerial.read(); // writing data into array // Дальше при совпадении каждого символа соответствующий счетчик увеличиваем на 1. //Если считанный символ совпадает с символом из буфера 1 (который прописали в начале кода), то первый счетчик увеличиваем на 1. if (buffer1[RFIDcount]==buffer[RFIDcount]) {RFIDcontCount1++;} else {RFIDcontCount1=RFIDcontCount1+0;} // По аналогии работаем с каждым из 3-х счетчиков. Для каждой карты 1 счетчик. if (buffer2[RFIDcount]==buffer[RFIDcount]) {RFIDcontCount2++;} else {RFIDcontCount2=RFIDcontCount2+0;} if (buffer3[RFIDcount]==buffer[RFIDcount]) {RFIDcontCount3++;} else {RFIDcontCount3=RFIDcontCount3+0;} if(RFIDcount == 64) break; RFIDcount++; } //** Теперь проверяем какой счетчик насчитал 12 совпадений (или сколько у вас их должно быть в зависимости от разрядности метки карты). //Если 1-й насчитал 12 совпадений, то приложена карта 1. if (RFIDcontCount1 == 12) { ...} if (RFIDcontCount2 == 12) { ...} if (RFIDcontCount3 == 12) { ...} // Если совпадений нет то ... if (RFIDcontCount1 != 12&RFIDcontCount2 != 12&RFIDcontCount3 != 12) { ...} // Далее скидываем все счетчики clearBufferArray(); // call clearBufferArray function to clear the storaged data from the array RFIDcount = 0; // set counter of while loop to zero RFIDcontCount1 = 0; RFIDcontCount2 = 0; RFIDcontCount3 = 0; } if (Serial.available()) // if data is available on hardwareserial port ==> data is comming from PC or notebook SoftSerial.write(Serial.read()); // write it to the SoftSerial shield } //** Очистка буфера void clearBufferArray() { for (int i=0; i < RFIDcount; i++) { buffer[i] = NULL; } }