Turns out when you order RFID scanners off Ali Express the pins are not soldered on the board so you have to do it yourself. Keep in mind that I got these things about 2 years ago and I was a lot less skilled then than I am now. Turns out I was being over dramatic on this problem because this was actually pretty fun, helpful, and it taught me more about soldering. It was helpful because the manufacturer put two different types of header pins in the bag (straight and 90s) so you were able to put the ones your wanted on. Also fun fact, I used a dead bug I found on the ground to keep my board straight (See Figure 1.1)
RFID Arduino code is very hard. There is no piece of code on in the stupid library that says "Write this to the card". No no no. Instead they expect you to know everything about RFID. But, luckily the internet made a WriteToCard command and ReadCard command but it has to be pasted in every script that uses RFID. The code is picture below for the Read Card command (Figure 2.1). This is the exact same thing I copied from the internet when I was first getting my RFID going. I have made some changes to this code to help fix other RFID related problems but I will get to that in a later complaint box. If you want to understand more fully of how stupid reading and writing to a RFID card is, then check out this site: www.electronicshub.org/write-data-to-rfid-card-using-rc522-rfid/ (Prepare for a headache if you want to try to understand it for real... I dont understand most of it, I can just make it work)
void ReadDataFromBlock(int blockNum, byte readBlockData[]){
/* Authenticating the desired data block for Read access using Key A */
byte status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, blockNum, &key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK){
Serial.print("Authentication failed for Read: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else{
Serial.println("Authentication success");
}
/* Reading data from the Block */
status = mfrc522.MIFARE_Read(blockNum, readBlockData, &bufferLen);
if (status != MFRC522::STATUS_OK){
Serial.print("Reading failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else{
Serial.println("Block was read successfully");
}
This isn't really just a RFID thing but I'm going to complain about it anyway. There are 64 different strings of 16 digit numbers stored on a RFID card or tag. That's 1024 different numbers! The 16 digit number looks like 0000000000000000. Say I wanted to make the Arduino look at the 4th number in that string. I would have to tell the thing to look for the 3rd number because it counts the first number as 0. I think that's dumb but starting from 0 is a common thing in programming.
This one was a pretty easy fix but I thought it was stupid anyway. The problem is that after scanning a card and doing the task, I wouldn't be able to scan a card again until I restarted the Arduino. Turns out you need to tell the Arduino when you are done with that RFID data so it clears it and is ready for the next card. I did that with two lines of code like mfrc522.PICC_HaltA(); ... look how stupid that looks. they had to make RFID so freaking complicated.
There is no work around to this... so we have to work with it. Since the cards and tags are made cheaply in China, they are going to have errors. But, my big ol' Arduino code in (Figure 2.1) only tells the Serial data that there is an error. So it just continues trucking along in the code after it throws the error and the Arduino has no idea of what the card says. So to work around this I put a variable in the read code and the write code to tell the Arduino there was an error so it knows to not continue. You would think that the makers of the RFID library would try to make something to make it try again if it has an error but no.
So it turns out that the RFID cards and the RFID tags are the same thing to an Arduino. Both the cards and the tags code look like 0000000000000000 to an Arduino by default. I'm going to have to explain what I'm doing with that big 16 digit number so hang on. The first 7 digits are the task. I'm having 10 task but that's 3 long task and 4 short task (Long task means that you have to do the same task at two different locations). The first 3 digits are for long task and 4-7 are for the short task. When you have to do a task it will be 0 and when its done it will be 1. If its a long task that 1 will become a 2 after the second task gets done. Any who, I skipped a couple digits just incase I want to add more task later and went to digit 15 and if that's a 1 you are the imposter and if its a 0 you are the crewmate... The way I tell the cards from the tags is with that last digit. If its a 1 than it is a card and if its a 0 than it is a tag. I made this explanation way more complicated then it needs to be but my fix wouldn't of sounded that cool if I just said I changed the last digit to a 1.
Do you know what buffer size means? Me neither. Turns out that the code I used (that I copied off the internet) only allowed me to scan a tag 18 times before it vegged. By vegged I mean it remembered that 18th card that was scanned and every card scanned after that was the exact same as that 18th card. So I looked up that problem and it was the buffer size not allow it to go past 18. So after every scan it resets the buffer size now ¯\_(ツ)_/¯
ASCII stands for "All Sexual Content Is Interesting". Just kidding! I have no idea what it means. Googles definition is "American Standard Code for Information Interchange". I think my definition was better but that's not my only problem with ASCII. Here's my understanding of it. The creators wanted to make numbers confusing so instead of making 0 actually 0... they made it 48. Why? also 1 is not 1 but 49. Why? Any who, I was having trouble reading my RFID cards data because I was write my 16th digit in the card to be 1 and I told the Arduino to look out for that but it just wasn't. Turns out that instead of telling my Arduino to look for 1 I was supposed to make it look for 49. Stupid, I know, but it gets worse. Sometimes looking for 1 works and sometimes looking for 49 works so every time I want to look for a number on the card, I have to look for the number and the same number in ASCII form. So instead of if(number[15] == 1) I have to do if(number[15] == 1 or number[15] == 49). (That's not exactly what the code looks like but its close) If would want to understand more ASCII numbers see (Figure 8.1)
Just when I thought I had everything RFID figured out... I started building the scanners out of wood and started soldering stuff together and wired a big ol' Ethernet cord to it so i could hook it up easily and such. I got it all together and it worked! ...for the first 2 days. After that it started to not read the cards. Why on earth! I googled for help. RFID uses I2C (read as I squared C) for its serial communication. You know what serial communication is and I will show you. Have you ever heard of a USB? That stands for Universal Serial Bus. Its basically a way to transfer data and the way RFID does it is with a way called I2C. Fun fact I2C is very useful. Fun fact number 2. I2C has its downsides. Downside number 1 is that it has a max distance of a 50 CM wire. Otherwise it will frick up. I put a 25 FT wire on my scanner. Only 23.36 FT too long. Long story short, I had to unlengthen the cord.
I haven't ran into this problem yet but I plan on it in the future... I read online that RFID tags and cards have a limited number of scans before they are shot. The number is pretty big but the problem still has a place in the back of my mind. Its around 100,000 to 200,000 scans before the card is no longer usable. I believe that is because they are cheap cards but the more expense ones cost more.