Jump to content


Arduino NFC send data on card tap

  • Please log in to reply
1 reply to this topic

#1 jim


    Advanced Member

  • Administrators
  • 3,385 posts

Posted 13 February 2015 - 07:19 PM

Hey guys

I am trying to send some data to my php script when a mifare classic card is tapped on my seeedstudio v2 NFC shield. I can read and write the data, now I would like to take that data and ship it over to a php script. does anyone know a way I could do that? I am open to other suggestions or methods to achieving this.

Before I got a pcduino, I was using an Arduino Uno with an adafruit nfc shield and Arduino's ethernet shield. The ethernet shield came with a library that allowed me to print and http request to the client. Here is my code that I used on the arduino uno.

#include <SPI.h>
#include <Ethernet.h>

#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>
#include <NfcAdapter.h>

PN532_I2C pn532_i2c(Wire);
NfcAdapter nfc = NfcAdapter(pn532_i2c);

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(198,189,195,46);

void setup(void) {
  Serial.println("NDEF Reader");

void loop(void) {
  Serial.println("\nScan a NFC tag\n");

  if (nfc.tagPresent())
    NfcTag tag = nfc.read();
    Serial.print("UID: ");Serial.println(tag.getUidString());

    if (tag.hasNdefMessage()) // every tag won't have a message

      NdefMessage message = tag.getNdefMessage();
      Serial.print("\nStudent Data Found!");
      if (message.getRecordCount() != 1) {

      // cycle through the records, printing some info from each
        NdefRecord record = message.getRecord(0);
        // NdefRecord record = message[i]; // alternate syntax

        // The TNF and Type should be used to determine how your application processes the payload
        // There's no generic processing for the payload, it's returned as a byte[]
        int payloadLength = record.getPayloadLength();
        byte payload[payloadLength];

        // Force the data into a String (might work depending on the content)
        // Real code should use smarter processing
        String payloadAsString;
        for (int c = 1; c < payloadLength; c++) {
          payloadAsString += (char)payload[c];
        Serial.print("  Payload (as String): ");

        // id is probably blank and will return ""
        String uid = record.getId();
        if (uid != "") {
          Serial.print("  ID: ");Serial.println(uid);

void sendData(String studentInfo){
  EthernetClient client;
  if(client.connect(server, 80)){
      Serial.println("Connected to ego...");
      client.print("GET /ego/addPointNFC.php?student=");
      client.print(" HTTP/1.1\r\n");
      client.println("HOST: localhost\r\n");
      Serial.println("Point Added!");                       
     Serial.println("Connection Failed.");

Everything worked great! I would like to achieve this same functionality on the pcduino, but this time using pcduino's wireless module.

Thank you!

#2 jim


    Advanced Member

  • Administrators
  • 3,385 posts

Posted 13 February 2015 - 07:19 PM

Hi there,

I'm very interested to hear your experience with the hardware you have mentioned. I have an Arduino Uno and Arduino's ethernet shield and I'm after buying the adafruit nfc shield (enroute by courier at the moment). I have an urgent project that requires these 3 pieces to work together - can you tell me your experiences with them and if they're reliable? Have you had any issues or conflicts with the mentioned hardware and any pitfalls to watch out for?

Thanks in advance!

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users