Difference between revisions of "WeMOS: D1 R1 mini RFID 2"

From OnnoWiki
Jump to navigation Jump to search
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
Sumber: https://blog.jeronimus.net/2018/03/rfid-and-wemos-d1-mini-1.html
+
Sumber: https://gist.github.com/alexey-bass/6b6e53e05d9a8d1468038ea78d536914
  
Tabel sambungan:
 
  
Signal MFRC522 WeMos D1 mini NodeMcu Generic
+
[[File:WEMOS-D1-mini-pin.png|center|300px|thumb]]
RST/Reset RST D3 [1] D3 [1] GPIO-0 [1]
 
SPI SS         SDA [3] D8 [2] D8 [2] GPIO-15 [2]
 
SPI MOSI MOSI D7 D7 GPIO-13
 
SPI MISO MISO D6 D6 GPIO-12
 
SPI SCK SCK D5 D5
 
  
  
Source
+
Install library
  
  #include "MFRC522.h"
+
* Download https://downloads.arduino.cc/libraries/github.com/miguelbalboa/MFRC522-1.4.11.zip
  #define RST_PIN 5 // RST-PIN for RC522 - RFID - SPI - Modul GPIO5
+
 
  #define SS_PIN 4 // SDA-PIN for RC522 - RFID - SPI - Modul GPIO4
+
mv MFRC522-1.4.11.zip ~/Arduino/libraries/
  MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
+
  cd ~/Arduino/libraries/
 +
unzip MFRC522-1.4.11.zip
 +
 
 +
Source OK
 +
 
 +
/**
 +
Useful links
 +
https://wiki.wemos.cc/products:d1:d1_mini
 +
  https://cdn-images-1.medium.com/max/1400/1*YKc8KpAfMrlhrOLmNjdRwQ.png (D1 full pinout)
 +
https://github.com/Jorgen-VikingGod/ESP8266-MFRC522
 +
https://github.com/miguelbalboa/rfid
 +
 
 +
d1 mini rc52 wiring
 +
  https://discourse-cdn-sjc1.com/business5/uploads/mydevices/original/2X/e/ecedba79dc05f2c0b02b7fba8b3da2681590a11a.jpg
 +
RST  - D3
 +
MISO - D6
 +
MOSI - D7
 +
SCK  - D5
 +
SDA  - D8
 +
*/
 +
 +
#include "ESP8266WiFi.h"
 +
#include <SPI.h>
 +
#include <MFRC522.h>
 +
 +
constexpr uint8_t RST_PIN =  0;          // Configurable, see typical pin layout above 18
 +
constexpr uint8_t SS_PIN =  15;        // Configurable, see typical pin layout above  16
 +
 +
  MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
 
   
 
   
 
  void setup() {
 
  void setup() {
   Serial.begin(115200);   // Initialize serial communications
+
   Serial.begin(115200);   // Initialize serial communications with the PC
   SPI.begin();         // Init SPI bus
+
  delay(1000);
   mfrc522.PCD_Init();    // Init MFRC522
+
  Serial.println("Setup");
 +
 
 +
  while (!Serial);    // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
 +
   SPI.begin();     // Init SPI bus
 +
   mfrc522.PCD_Init();   // Init MFRC522
 +
   mfrc522.PCD_DumpVersionToSerial();  // Show details of PCD - MFRC522 Card Reader details
 +
  Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
 +
  Serial.println("Setup done");
 
  }
 
  }
 
   
 
   
  void loop() {  
+
  void loop() {
 +
//  Serial.println("Loop...");
 +
 
 
   // Look for new cards
 
   // Look for new cards
 
   if ( ! mfrc522.PICC_IsNewCardPresent()) {
 
   if ( ! mfrc522.PICC_IsNewCardPresent()) {
     delay(50);
+
     //delay(50);
    return;
 
  }
 
  // Select one of the cards
 
  if ( ! mfrc522.PICC_ReadCardSerial()) {
 
    delay(50);
 
 
     return;
 
     return;
 
   }
 
   }
 +
 +
  // Select one of the cards
 +
  if ( ! mfrc522.PICC_ReadCardSerial()) {
 +
    //delay(50);
 +
    return;
 +
  }
 +
 
   // Show some details of the PICC (that is: the tag/card)
 
   // Show some details of the PICC (that is: the tag/card)
 
   Serial.print(F("Card UID:"));
 
   Serial.print(F("Card UID:"));
 
   dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
 
   dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
 
   Serial.println();
 
   Serial.println();
 +
 
 +
  // Dump debug info about the card; PICC_HaltA() is automatically called
 +
  //mfrc522.PICC_DumpToSerial(&(mfrc522.uid)); 
 +
 +
  delay(1000);
 
  }
 
  }
 
   
 
   
Line 47: Line 85:
 
     Serial.print(buffer[i], HEX);
 
     Serial.print(buffer[i], HEX);
 
   }
 
   }
  }
+
  }  
 +
 
 +
 
 +
 
 +
==Referensi==
 +
 
 +
* https://gist.github.com/alexey-bass/6b6e53e05d9a8d1468038ea78d536914

Latest revision as of 10:43, 1 June 2024

Sumber: https://gist.github.com/alexey-bass/6b6e53e05d9a8d1468038ea78d536914


WEMOS-D1-mini-pin.png


Install library

mv MFRC522-1.4.11.zip ~/Arduino/libraries/
cd ~/Arduino/libraries/
unzip MFRC522-1.4.11.zip

Source OK

/**
Useful links
https://wiki.wemos.cc/products:d1:d1_mini
https://cdn-images-1.medium.com/max/1400/1*YKc8KpAfMrlhrOLmNjdRwQ.png (D1 full pinout)
https://github.com/Jorgen-VikingGod/ESP8266-MFRC522
https://github.com/miguelbalboa/rfid
d1 mini rc52 wiring
https://discourse-cdn-sjc1.com/business5/uploads/mydevices/original/2X/e/ecedba79dc05f2c0b02b7fba8b3da2681590a11a.jpg
RST  - D3
MISO - D6
MOSI - D7
SCK  - D5
SDA  - D8
*/

#include "ESP8266WiFi.h"
#include <SPI.h>
#include <MFRC522.h>

constexpr uint8_t RST_PIN =  0;          // Configurable, see typical pin layout above 18
constexpr uint8_t SS_PIN =  15;         // Configurable, see typical pin layout above  16

MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance

void setup() {
  Serial.begin(115200);   // Initialize serial communications with the PC
  delay(1000);
  Serial.println("Setup");
  
  while (!Serial);    // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  SPI.begin();      // Init SPI bus
  mfrc522.PCD_Init();   // Init MFRC522
  mfrc522.PCD_DumpVersionToSerial();  // Show details of PCD - MFRC522 Card Reader details
  Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
  Serial.println("Setup done");
}

void loop() {
//  Serial.println("Loop...");
 
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    //delay(50);
    return;
  }
 // Select one of the cards
 if ( ! mfrc522.PICC_ReadCardSerial()) {
   //delay(50);
   return;
 }

  // Show some details of the PICC (that is: the tag/card)
  Serial.print(F("Card UID:"));
  dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
  Serial.println();
  
  // Dump debug info about the card; PICC_HaltA() is automatically called
  //mfrc522.PICC_DumpToSerial(&(mfrc522.uid));  
  delay(1000);
}

// Helper routine to dump a byte array as hex values to Serial
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);
  }
} 


Referensi