Use Seeeduino Arch (or Arch Pro) + NFC Shield to write a Mifare Classic tag
Dependencies: PN532 USBDevice mbed
main.cpp@3:59afaef9fb24, 2013-11-21 (annotated)
- Committer:
- yihui
- Date:
- Thu Nov 21 06:52:36 2013 +0000
- Revision:
- 3:59afaef9fb24
- Parent:
- 2:56402cae2c3c
remove USBDevice lib to reduce memory usage
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 | 3:59afaef9fb24 | 5 | #if 1 // Using Seeeduino Arch |
yihui | 3:59afaef9fb24 | 6 | #define LOG(args...) |
yihui | 2:56402cae2c3c | 7 | SPI spi(P1_22, P1_21, P1_20); // SPI(mosi, miso, clk) |
yihui | 3:59afaef9fb24 | 8 | PN532_SPI pn532spi(spi, P0_2); |
yihui | 2:56402cae2c3c | 9 | |
yihui | 2:56402cae2c3c | 10 | #else // Using Arch Pro |
yihui | 3:59afaef9fb24 | 11 | #define LOG(args...) pc.printf(args) |
yihui | 2:56402cae2c3c | 12 | Serial pc(USBTX, USBRX); |
yihui | 2:56402cae2c3c | 13 | SPI spi(P0_18, P0_17, P0_15); |
yihui | 2:56402cae2c3c | 14 | PN532_SPI pn532spi(spi, P0_6); |
yihui | 1:c5b5be0d6c5d | 15 | #endif |
yihui | 1:c5b5be0d6c5d | 16 | |
yihui | 2:56402cae2c3c | 17 | NfcAdapter nfc(pn532spi); |
yihui | 3:59afaef9fb24 | 18 | DigitalOut led1(LED1); |
yihui | 3:59afaef9fb24 | 19 | DigitalOut led2(LED2); |
yihui | 0:b81d113f3a83 | 20 | |
yihui | 0:b81d113f3a83 | 21 | int main() { |
yihui | 3:59afaef9fb24 | 22 | led1 = 1; |
yihui | 3:59afaef9fb24 | 23 | LOG("NFC Writer\n"); |
yihui | 0:b81d113f3a83 | 24 | nfc.begin(); |
yihui | 2:56402cae2c3c | 25 | while (1) { |
yihui | 3:59afaef9fb24 | 26 | LOG("\nPlace a formatted Mifare Classic NFC tag on the reader."); |
yihui | 2:56402cae2c3c | 27 | if (nfc.tagPresent()) { |
yihui | 3:59afaef9fb24 | 28 | led2 = 1; |
yihui | 2:56402cae2c3c | 29 | NdefMessage message = NdefMessage(); |
yihui | 2:56402cae2c3c | 30 | message.addUriRecord("http://seeedstudio.com"); |
yihui | 2:56402cae2c3c | 31 | bool success = nfc.write(message); |
yihui | 2:56402cae2c3c | 32 | if (success) { |
yihui | 2:56402cae2c3c | 33 | LOG("Success. Try reading this tag with your phone."); |
yihui | 2:56402cae2c3c | 34 | } else { |
yihui | 2:56402cae2c3c | 35 | LOG("Write failed."); |
yihui | 0:b81d113f3a83 | 36 | } |
yihui | 3:59afaef9fb24 | 37 | led2 = 0; |
yihui | 0:b81d113f3a83 | 38 | } |
yihui | 3:59afaef9fb24 | 39 | wait(5); |
yihui | 0:b81d113f3a83 | 40 | } |
yihui | 0:b81d113f3a83 | 41 | } |