Go Down

Topic: Android ADK interfacing with NFC shield (Read 975 times) previous topic - next topic


We are trying to integrate the PN 532 NFC shield with the Android ADK.. Both the ADK and shield are fine. I was able to load the basic sketches and read ids, etc..
Now, I am trying to make a sketch that can read the Mifare cards and send the id to the ADK and then to the Android device. I am using the following code:

Code: [Select]
//Alfatek Systems NFC Shield Read using Niels Brouwers' MicroBridge library.
//Connect a tactile switch between D12 and reset

#include <SPI.h>
#include <Adb.h>
#include <max3421e.h>
#include <PN532.h>
#include <EEPROM.h>
#define PN532_CS 10

//CS of NFC is pin 10
PN532 nfc(PN532_CS);
// Adb connection.
Connection * connection;
// Elapsed time for ADC sampling. The rate at which ADC value is sent to Android device.
long lastTime;
// ID of the MiFare Card  
uint32_t id;
uint8_t idbk[5];

// Event handler for the shell connection.
void adbEventHandler(Connection * connection, adb_eventType event, uint16_t length, uint8_t * data)
 // Data packet contains one byte from Android to determine when to start reading NFC
     digitalWrite(53, HIGH);
     digitalWrite(6, HIGH);
 //  ADB::closeAll();
     //NFC Begins
       // look for MiFare type cards
       //Read the NFC Shield version
       uint32_t versiondata = nfc.getFirmwareVersion();
       //Warning for non-compatible NFC shields
       if (!versiondata) {
         Serial.print("Didn't find PN53x board");
         while (1); // halt
       // Got ok data, print it out!
       Serial.print("Found chip PN5");
       Serial.println((versiondata>>24) & 0xFF, HEX);
       Serial.print("Firmware ver. ");
       Serial.print((versiondata>>16) & 0xFF, DEC);
       Serial.println((versiondata>>8) & 0xFF, DEC);
       Serial.print("Supports ");
       Serial.println(versiondata & 0xFF, HEX);
       // configure board to read RFID tags and cards
       id =0;
       while (id==0)
         id = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A);
         if (id != 0) {
           Serial.print("Read card #");
 //      nfc.end();
       // Store the NFC ID read to the EEPROM
    digitalWrite(6, LOW);   // Change the state of LED to indicate NFC ready to read

void setup()
 //NFC Read Next Init
 pinMode(12, OUTPUT);
 digitalWrite(12, LOW);
 //Read the ID stored from EEPROM
 id = ((uint32_t) EEPROM.read(10)<<24) | ((uint32_t) EEPROM.read(11)<<16) | ((uint32_t) EEPROM.read(12)<<8)|((uint32_t) EEPROM.read(13));
 //Serial port debug purpose
 // Set Digital pin 6 (LED is connected) as output to indicate that NFC ready to be read.
 // Note start time
 lastTime = millis();
 // Initialise the ADB subsystem.  
 // Open an ADB stream to the phone's shell. Auto-reconnect. Use any unused port number eg:4568
 connection = ADB::addConnection("tcp:4568", true, adbEventHandler);  

void loop()
 uint32_t lgval=(uint32_t)10000000000.0;
 //Display the last ID read
 if ((millis() - lastTime) > 1000)

   Serial.print("Last ID Read: ");


   //Write the ID to Android
   lastTime = millis();
 // Poll the ADB subsystem.

The logic works like this.. Use the adb event handler when it gets a response from the Android device, initialize the NFC shield, read the id, and store in EEPROM.. To send the data to the Android device, basically read the last ID stored in the EEPROM and send it to the Android device.. The code is all good - but with one problem - after the RFID tag is read (the board detects the PN532 and reads the card id), it seems to hang - i have to do a reset to make it work. Please help on how to make it work without reset..

Thanks for your help.



I am using

http://linksprite.com/wiki/index.php5?title=NFC_PN532_Shield  http://linksprite.com/wiki/index.php5?title=NFC_PN532_Shield

It looks like the NFC shield is using the same set of SPI pins as the USB host chip on ADK. Do you have problem here?


Here's my email id: sb @ alfateksystems.com

Go Up