Use Seeeduino Arch (or Arch Pro) + NFC Shield to write a Mifare Classic tag
Dependencies: PN532 USBDevice mbed
main.cpp@2:56402cae2c3c, 2013-11-21 (annotated)
- Committer:
- yihui
- Date:
- Thu Nov 21 06:31:29 2013 +0000
- Revision:
- 2:56402cae2c3c
- Parent:
- 1:c5b5be0d6c5d
- Child:
- 3:59afaef9fb24
write a NDEF message to a tag
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yihui | 0:b81d113f3a83 | 1 | #include "mbed.h" |
yihui | 2:56402cae2c3c | 2 | #include "PN532_SPI.h" |
yihui | 2:56402cae2c3c | 3 | #include "NfcAdapter.h" |
yihui | 0:b81d113f3a83 | 4 | |
yihui | 1:c5b5be0d6c5d | 5 | #define LOG(args...) pc.printf(args) |
yihui | 1:c5b5be0d6c5d | 6 | |
yihui | 2:56402cae2c3c | 7 | #if 0 // Using Seeeduino Arch |
yihui | 2:56402cae2c3c | 8 | #include "USBSerial.h" |
yihui | 1:c5b5be0d6c5d | 9 | USBSerial pc; |
yihui | 2:56402cae2c3c | 10 | SPI spi(P1_22, P1_21, P1_20); // SPI(mosi, miso, clk) |
yihui | 2:56402cae2c3c | 11 | PN532_SPI pn532spi(spi, P0_2) |
yihui | 2:56402cae2c3c | 12 | |
yihui | 2:56402cae2c3c | 13 | #else // Using Arch Pro |
yihui | 2:56402cae2c3c | 14 | Serial pc(USBTX, USBRX); |
yihui | 2:56402cae2c3c | 15 | SPI spi(P0_18, P0_17, P0_15); |
yihui | 2:56402cae2c3c | 16 | PN532_SPI pn532spi(spi, P0_6); |
yihui | 1:c5b5be0d6c5d | 17 | #endif |
yihui | 1:c5b5be0d6c5d | 18 | |
yihui | 2:56402cae2c3c | 19 | NfcAdapter nfc(pn532spi); |
yihui | 2:56402cae2c3c | 20 | DigitalOut led(LED1); |
yihui | 1:c5b5be0d6c5d | 21 | |
yihui | 0:b81d113f3a83 | 22 | |
yihui | 0:b81d113f3a83 | 23 | int main() { |
yihui | 0:b81d113f3a83 | 24 | nfc.begin(); |
yihui | 2:56402cae2c3c | 25 | while (1) { |
yihui | 2:56402cae2c3c | 26 | if (nfc.tagPresent()) { |
yihui | 2:56402cae2c3c | 27 | NdefMessage message = NdefMessage(); |
yihui | 2:56402cae2c3c | 28 | message.addUriRecord("http://seeedstudio.com"); |
yihui | 0:b81d113f3a83 | 29 | |
yihui | 2:56402cae2c3c | 30 | bool success = nfc.write(message); |
yihui | 2:56402cae2c3c | 31 | if (success) { |
yihui | 2:56402cae2c3c | 32 | LOG("Success. Try reading this tag with your phone."); |
yihui | 2:56402cae2c3c | 33 | } else { |
yihui | 2:56402cae2c3c | 34 | LOG("Write failed."); |
yihui | 0:b81d113f3a83 | 35 | } |
yihui | 0:b81d113f3a83 | 36 | } |
yihui | 2:56402cae2c3c | 37 | wait(6); |
yihui | 0:b81d113f3a83 | 38 | } |
yihui | 0:b81d113f3a83 | 39 | } |