Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <SPI.h>
- #include <MFRC522_I2C.h>
- #define SDA_PIN 32
- #define SCL_PIN 33
- #define MFRC522_I2C MFRC522
- MFRC522 mfrc522(0x28);
- void dump_byte_array(byte *buffer, byte bufferSize) {
- for (byte i = 0; i < bufferSize; i++) {
- Serial.print(buffer[i] < 0x10 ? " 0" : " ");
- Serial.print(buffer[i], HEX);
- }
- Serial.print(" |");
- for (byte i = 0; i < bufferSize; i++) {
- if (buffer[i] >= 32 && buffer[i] <= 126) { // Check if the byte is a printable ASCII character
- Serial.print((char)buffer[i]);
- } else {
- Serial.print('.'); // Print a dot for non-printable characters
- }
- }
- Serial.print('|');
- }
- void setup() {
- Wire.begin(SDA_PIN, SCL_PIN);
- SPI.begin();
- mfrc522.PCD_Init();
- Serial.println("Scan a card...");
- }
- void loop() {
- // Look for new cards
- if (!mfrc522.PICC_IsNewCardPresent()) {
- return;
- }
- // Select one of the cards
- if (!mfrc522.PICC_ReadCardSerial()) {
- return;
- }
- // Show some details of the PICC (that is: the tag/card)
- Serial.print("Card UID:");
- dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
- Serial.println();
- Serial.println("Card Data:");
- int lineNumber = 0;
- for (byte block = 0; block < 255; block++) {
- byte buffer[18];
- byte size = sizeof(buffer);
- byte status = mfrc522.MIFARE_Read(block, buffer, &size);
- if (status != MFRC522::STATUS_OK) {
- Serial.print("MIFARE_Read() failed: ");
- Serial.println(mfrc522.GetStatusCodeName(status));
- }
- if (status == MFRC522::STATUS_TIMEOUT) {
- Serial.print("MIFARE_Read() failed: ");
- Serial.println(mfrc522.GetStatusCodeName(status));
- break;
- }
- Serial.print("[");
- if (block < 16) {
- Serial.print("0");
- }
- Serial.print(block, HEX);
- Serial.print("] ");
- dump_byte_array(buffer, 4); // idk why but only first 4 bytes are shiftted
- Serial.println();
- }
- Serial.println("Reading Finished");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement