forked from don/NDEF
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathWriteTag.ino
45 lines (36 loc) · 1.19 KB
/
WriteTag.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* Example Arduino code that writes a URL to the tag in NDEF format
* allowing a phone to read the tag and open to a browser.
* Success if your phone opens to this Github repo.
*/
#include "MifareUltralight.h"
#include <MFRC522.h>
#include <SPI.h>
#define SS_PIN 10
#define RST_PIN 6
using namespace ndef_mfrc522;
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
void setup() {
Serial.begin(115200); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
Serial.println(F("Hold a tag to the MFRC522 and look for success."));
}
void loop() {
// Look for new cards
if (!mfrc522.PICC_IsNewCardPresent())
return;
// Select one of the cards
if (!mfrc522.PICC_ReadCardSerial())
return;
NdefMessage message = NdefMessage();
String url = String("https://github.com/aroller/NDEF-MFRC522");
message.addUriRecord(url);
MifareUltralight writer = MifareUltralight(mfrc522);
bool success = writer.write(message);
if (success)
Serial.println(F("Success. Now read the tag with your phone."));
else
Serial.println(F("Failure. See output above?"));
delay(5000); // avoids duplicate scans
}