Use Seeeduino Arch (or Arch Pro) + NFC Shield to write a Mifare Classic tag

Dependencies:   PN532 USBDevice mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "PN532_SPI.h"
00003 #include "NfcAdapter.h"
00004 
00005 #if 1                           // Using Seeeduino Arch
00006 #define LOG(args...)
00007 SPI spi(P1_22, P1_21, P1_20);  // SPI(mosi, miso, clk)
00008 PN532_SPI pn532spi(spi, P0_2);
00009 
00010 #else                           // Using Arch Pro
00011 #define LOG(args...)        pc.printf(args)
00012 Serial pc(USBTX, USBRX);
00013 SPI spi(P0_18, P0_17, P0_15);
00014 PN532_SPI pn532spi(spi, P0_6);
00015 #endif
00016 
00017 NfcAdapter nfc(pn532spi);
00018 DigitalOut led1(LED1);
00019 DigitalOut led2(LED2);
00020 
00021 int main() {
00022     led1 = 1;
00023     LOG("NFC Writer\n");
00024     nfc.begin();
00025     while (1) {
00026         LOG("\nPlace a formatted Mifare Classic NFC tag on the reader.");
00027         if (nfc.tagPresent()) {
00028             led2 = 1;
00029             NdefMessage message = NdefMessage();
00030             message.addUriRecord("http://seeedstudio.com");
00031             bool success = nfc.write(message);
00032             if (success) {
00033                 LOG("Success. Try reading this tag with your phone.");        
00034             } else {
00035                 LOG("Write failed.");
00036             }
00037             led2 = 0;
00038         }
00039         wait(5);
00040     }
00041 }