Skip to content

Commit 6c51050

Browse files
committed
example
1 parent 6cd3681 commit 6c51050

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

examples/print_uuid/print_uuid.ino

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#include <Wire.h>
2+
#include <Adafruit_MFRC630.h>
3+
4+
/* Indicate the pin number where PDOWN is connected. */
5+
#define PDOWN_PIN (12)
6+
7+
/* Use the default I2C address */
8+
Adafruit_MFRC630 rfid = Adafruit_MFRC630(PDOWN_PIN);
9+
10+
/* Prints out len bytes of hex data in table format. */
11+
static void print_buf_hex(uint8_t *buf, size_t len)
12+
{
13+
for (uint8_t i = 0; i < len; i++)
14+
{
15+
Serial.print("0x");
16+
if (buf[i] < 16)
17+
{
18+
Serial.print("0");
19+
}
20+
Serial.print(buf[i], HEX);
21+
Serial.print(" ");
22+
}
23+
Serial.println(" ");
24+
}
25+
/*
26+
* This more concise loop show the minimim requirements to dump the first 1K
27+
* of memory from a Mifare Classic or Mifare Plus compatible card. No meaningful
28+
* error-handling or debug output is present here, so this code is intended
29+
* as a simple starting point for further work.
30+
*/
31+
bool radio_mifare1K_dump_minimal(void)
32+
{
33+
bool rc;
34+
35+
/* Put the IC in a known-state. */
36+
rfid.softReset();
37+
38+
/* Configure the radio for ISO14443A-106. */
39+
rfid.configRadio(MFRC630_RADIOCFG_ISO1443A_106);
40+
41+
/* Request a tag (activates the near field, etc.). */
42+
uint16_t atqa = rfid.iso14443aRequest();
43+
44+
/* Looks like we found a tag, move on to selection. */
45+
if (atqa)
46+
{
47+
uint8_t uid[10] = { 0 };
48+
uint8_t uidlen;
49+
uint8_t sak;
50+
51+
/* Retrieve the UID and SAK values. */
52+
uidlen = rfid.iso14443aSelect(uid, &sak);
53+
Serial.print("Found a tag with UUID ");
54+
for (uint8_t i = 0; i < uidlen; i++) {
55+
Serial.print(uid[i], HEX);
56+
Serial.print(" ");
57+
}
58+
Serial.println("");
59+
}
60+
}
61+
62+
/**
63+
*
64+
*/
65+
void setup() {
66+
Serial.begin(115200);
67+
68+
while (!Serial) {
69+
delay(1);
70+
}
71+
72+
Serial.println("");
73+
Serial.println("-------------------------------");
74+
Serial.println("Adafruit MFRC630 Mifare 1K Test");
75+
Serial.println("-------------------------------");
76+
77+
pinMode(LED_BUILTIN, OUTPUT);
78+
79+
/* Try to initialize the IC */
80+
if (!(rfid.begin())) {
81+
Serial.println("Unable to initialize the MFRC630. Check wiring?");
82+
while(1) {
83+
digitalWrite(LED_BUILTIN, HIGH);
84+
delay(50);
85+
digitalWrite(LED_BUILTIN, LOW);
86+
delay(50);
87+
}
88+
}
89+
}
90+
91+
void loop() {
92+
radio_mifare1K_dump_minimal();
93+
}

0 commit comments

Comments
 (0)