Advertisement
pleasedontcode

"RFID Reader" rev_11

Jun 12th, 2024
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "RFID Reader"
  13.     - Source Code NOT compiled for: Arduino Mega
  14.     - Source Code created on: 2024-06-12 11:35:29
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* read info about tag which is closed to rfid. */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <SPI.h>
  25. #include <MFRC522.h>  //https://github.com/miguelbalboa/rfid
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30. void updateOutputs(void);
  31.  
  32. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  33. const uint8_t rfid_MFRC522_IRQ_PIN_D5 = 5;
  34.  
  35. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  36. const uint8_t rfid_MFRC522_RST_PIN_D4 = 4;
  37.  
  38. /***** DEFINITION OF SPI PINS *****/
  39. const uint8_t rfid_MFRC522_SPI_PIN_MOSI_D51 = 51;
  40. const uint8_t rfid_MFRC522_SPI_PIN_MISO_D50 = 50;
  41. const uint8_t rfid_MFRC522_SPI_PIN_SCLK_D52 = 52;
  42. const uint8_t rfid_MFRC522_SPI_PIN_CS_D53 = 53;
  43.  
  44. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  45. /***** used to store raw data *****/
  46. bool rfid_MFRC522_RST_PIN_D4_rawData = 0;
  47.  
  48. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  49. /***** used to store data after characteristic curve transformation *****/
  50. float rfid_MFRC522_RST_PIN_D4_phyData = 0.0;
  51.  
  52. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  53. MFRC522 mfrc522(rfid_MFRC522_SPI_PIN_CS_D53, rfid_MFRC522_RST_PIN_D4);  // Create MFRC522 instance
  54.  
  55. void setup(void) {
  56.   // Initialize serial communications with the PC
  57.   Serial.begin(9600);
  58.   while (!Serial);  // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  59.  
  60.   // Initialize the SPI library
  61.   SPI.begin();
  62.  
  63.   // Initialize the MFRC522
  64.   mfrc522.PCD_Init();
  65.   mfrc522.PCD_DumpVersionToSerial();  // Show details of PCD - MFRC522 Card Reader details
  66.  
  67.   // Print a message indicating readiness to scan RFID tags or cards
  68.   Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
  69.  
  70.   // Setup pin modes
  71.   pinMode(rfid_MFRC522_IRQ_PIN_D5, INPUT_PULLUP);
  72.   pinMode(rfid_MFRC522_RST_PIN_D4, OUTPUT);
  73.   pinMode(rfid_MFRC522_SPI_PIN_CS_D53, OUTPUT);
  74. }
  75.  
  76. void loop(void) {
  77.   // Refresh output data
  78.   updateOutputs();
  79.  
  80.   // Check for new cards
  81.   if (!mfrc522.PICC_IsNewCardPresent()) {
  82.     return;
  83.   }
  84.  
  85.   // Select one of the cards
  86.   if (!mfrc522.PICC_ReadCardSerial()) {
  87.     return;
  88.   }
  89.  
  90.   // Dump debug info about the card; PICC_HaltA() is automatically called
  91.   mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
  92. }
  93.  
  94. void updateOutputs() {
  95.   // Update the raw data to the physical pin
  96.   digitalWrite(rfid_MFRC522_RST_PIN_D4, rfid_MFRC522_RST_PIN_D4_rawData);
  97. }
  98.  
  99. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement