Hi, I bought Grove - 125KHz RFID Readers but I cannot read Mifare tags. is this player compatible with these tags?
We haven’t tested it.If the parameters match, they should be compatible.
Hi @Baozhu, I would like to connect the Grove - 125KHz RFID shield to the Wio Terminal, I made a level adaptation to connect the serial and with the example of connection with softserial everything works normally. Now I would like to create a Sketch with the wiegand protocol and the interrupts as per Dome RFID_Wiegand_INT. however, not knowing which pins accept interrupts, the example sketch does not work. I tried to use digitalPinToInterrupt by defining it on D2 and D3 “attachInterrupt (digitalPinToInterrupt (2), ISRreceiveData0, FALLING);” but even this did not give a positive result. Can you help me solve this problem?
Thank you
Gianfranco
Hi Baozhu, in addition to the previous message I wanted to tell you that I have also tried the code on Arduino Uno and even here the code does not seem to work.
Gianfranco
It looks really incompatible.
Hi @Baozhu, you didn’t give me an answer regarding interrupts. How can you use interrupts on WioTerminal? Is it possible to use the digitalPinToInterrupt function on Wio Terminal?
I wait for your instructions.
Thank you
Gianfranco
Hi @Baozhu, I was able to get the Grove - 125KHz RFID Reader Wiegand protocol to work with the Wio Terminal.
I am attaching the code I used starting from your example.
I hope it will be useful.
Regards
[details=Click to see the code]
#include <SoftwareSerial.h>
byte RFIDcardNum[4];
byte evenBit = 0;
byte oddBit = 0;
byte isData0Low = 0;
byte isData1Low = 0;
int recvBitCount = 0;
byte isCardReadOver = 0;
long rfidValue = 0; //rfidValue: used to store the value obtained from the RFID tag
long BufrfidValue = 0;
byte isCardRead = 0;
unsigned long lastDebounceCardRead = 0;
unsigned long debounceDelayCardRead = 10000;
SoftwareSerial rfid(3, 2); // RX Yellow,TX White
boolean waitingForKey = true; //waitingForKey: is used to identify if we are still waiting for a person to present a valid key or not
void Buzzer(int frq)
{
analogWrite(WIO_BUZZER, 128);
delay(frq);
analogWrite(WIO_BUZZER, 0);
}
boolean checkCard()
{
waitingForKey = true;
switch (rfidValue)
{
case 4450306: //Person #1 has a Tag that generates an rfidValue of 628.
Buzzer(1000);
waitingForKey = false; //setting the "waitingForKey" variable to FALSE - will allow us to break out of the while loop (instead of waiting for a full 10 seconds).
break;
case 4386916: //Person #2 has a Tag that generates an rfidValue of 651.
Buzzer(1000);
waitingForKey = false; //setting the "waitingForKey" variable to FALSE - will allow us to break out of the while loop (instead of waiting for a full 10 seconds).
break;
case 694: //Person #3 has a Tag that generates an rfidValue of 694.
Buzzer(1000);
waitingForKey = false; //setting the "waitingForKey" variable to FALSE - will allow us to break out of the while loop (instead of waiting for a full 10 seconds).
break;
case 658: //Person #4 has a Tag that generates an rfidValue of 658.
Buzzer(1000);
waitingForKey = false; //setting the "waitingForKey" variable to FALSE - will allow us to break out of the while loop (instead of waiting for a full 10 seconds).
break;
case 677: //Person #5 has a Tag that generates an rfidValue of 677.
Buzzer(1000);
waitingForKey = false; //setting the "waitingForKey" variable to FALSE - will allow us to break out of the while loop (instead of waiting for a full 10 seconds).
break;
default:
waitingForKey = true; //If a person has not been identified, keep waiting for the key/tag until the times runs out.
break;
}
if (waitingForKey)
{
return false;
}
else
{
return true;
}
}
void setup()
{
Serial.begin(115200);
pinMode(WIO_BUZZER, OUTPUT);
rfid.begin(9600); // the SoftSerial baud rate
while (!Serial)
; // wait for serial port to connect
attachInterrupt(digitalPinToInterrupt(2), ISRreceiveData0, FALLING); //data0/tx is connected to pin 2, which results in INT 0
attachInterrupt(digitalPinToInterrupt(3), ISRreceiveData1, FALLING); //data1/rx is connected to pin 3, which results in INT 1
Serial.println("Boot W");
lastDebounceCardRead = millis();
}
void loop()
{
//read card number bit
if (isData0Low || isData1Low)
{
// Serial.println("read card number bit");
if (1 == recvBitCount)
{ //even bit
evenBit = (1 - isData0Low) & isData1Low;
}
else if (recvBitCount >= 26)
{ //odd bit
oddBit = (1 - isData0Low) & isData1Low;
isCardReadOver = 1;
delay(10);
}
else
{
//only if isData1Low = 1, card bit could be 1
RFIDcardNum[2 - (recvBitCount - 2) / 8] |= (isData1Low << (7 - (recvBitCount - 2) % 8));
}
//reset data0 and data1
isData0Low = 0;
isData1Low = 0;
}
//print the card id number
if (isCardReadOver)
{
if (checkParity())
{
Serial.println();
// Serial.print(RFIDcardNum[2], HEX); //High byte
// Serial.print(RFIDcardNum[1], HEX); //Midle byte
// Serial.println(RFIDcardNum[0], HEX); //Low byte
rfidValue = (*((long *)RFIDcardNum));
if (BufrfidValue != rfidValue)
{
isCardRead = 1;
BufrfidValue = rfidValue;
}
else
{
isCardRead = 0;
BufrfidValue = rfidValue;
}
Serial.println(rfidValue);
}
if ((millis() - lastDebounceCardRead > debounceDelayCardRead))
{
lastDebounceCardRead = millis();
BufrfidValue = 0;
}
resetData();
if (isCardRead)
{
if (checkCard())
{
//TRUE = Person Identified within 10 seconds
Serial.println("Authorized Card");
}
else
{
Serial.println("Unauthorized Card");
Buzzer(300);
delay(100);
Buzzer(300);
}
}
}
}
byte checkParity()
{
int i = 0;
int evenCount = 0;
int oddCount = 0;
for (i = 0; i < 8; i++)
{
if (RFIDcardNum[2] & (0x80 >> i))
{
evenCount++;
}
}
for (i = 0; i < 4; i++)
{
if (RFIDcardNum[1] & (0x80 >> i))
{
evenCount++;
}
}
for (i = 4; i < 8; i++)
{
if (RFIDcardNum[1] & (0x80 >> i))
{
oddCount++;
}
}
for (i = 0; i < 8; i++)
{
if (RFIDcardNum[0] & (0x80 >> i))
{
oddCount++;
}
}
if (evenCount % 2 == evenBit && oddCount % 2 != oddBit)
{
return 1;
}
else
{
return 0;
}
}
void resetData()
{
RFIDcardNum[0] = 0;
RFIDcardNum[1] = 0;
RFIDcardNum[2] = 0;
RFIDcardNum[3] = 0;
evenBit = 0;
oddBit = 0;
recvBitCount = 0;
isData0Low = 0;
isData1Low = 0;
isCardReadOver = 0;
}
// handle interrupt0
void ISRreceiveData0()
{
//Serial.println("RicevoData da 0");
recvBitCount++;
isData0Low = 1;
}
// handle interrupt1
void ISRreceiveData1()
{
//Serial.println("RicevoData da 1");
recvBitCount++;
isData1Low = 1;
}
[/details]