Modifying serial message from Adafruit NFC shield

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
eco_bach
 
Posts: 5
Joined: Wed Jan 22, 2014 2:41 pm

Modifying serial message from Adafruit NFC shield

Post by eco_bach »

Using an Uno configured with an Adafruit RFID-NFC shield to send the UID values to a desktop game I am building.

Works fine. However, in addition to just the UID, I need to send 1 additional value, lets call it 'game choice'. This can be one of 3 values.
The message is sent obviously whenever a user scans their tag over 1 of 3 possible scan targets(game choices). This 'game choice' value would be hardcoded. The receiving end is a desktop Adobe AIR application. Using the ArduinoConnector native Extensionhttp://code.google.com/p/as3-arduino-connector
Can any experts suggest how I might modify the following to send this additional value?

Code: Select all

/**************************************************************************/
#include <Wire.h>
#include <Adafruit_NFCShield_I2C.h>

#define IRQ   (2)
#define RESET (3)  // Not connected by default on the NFC Shield

Adafruit_NFCShield_I2C nfc(IRQ, RESET);

void setup(void) {
  Serial.begin(115200);
  Serial.println("Hello!");

  nfc.begin();

  uint32_t versiondata = nfc.getFirmwareVersion();
  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.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);

  // configure board to read RFID tags
  nfc.SAMConfig();

  Serial.println("init");
}
void loop(void) {
  uint8_t success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
  uint8_t uidLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
  int nfcDEC;  
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);

  if (success) {


   nfc.PrintHex(uid, uidLength );
}
}

User avatar
Franklin97355
 
Posts: 23911
Joined: Mon Apr 21, 2008 2:33 pm

Re: Modifying serial message from Adafruit NFC shield

Post by Franklin97355 »

What are your scan targets? How do you know which target was selected?

eco_bach
 
Posts: 5
Joined: Wed Jan 22, 2014 2:41 pm

Re: Modifying serial message from Adafruit NFC shield

Post by eco_bach »

How do I know which target was selected?
Exactly. This is the reason I need to send the extra value!
There would be 3 arduinos+shields. 1 per game choice.

Each arduino would have a different(1of3) 'game choice' value hard coded.

It is this hardcoded value I need to pass-send in addition to the UID.

User avatar
Franklin97355
 
Posts: 23911
Joined: Mon Apr 21, 2008 2:33 pm

Re: Modifying serial message from Adafruit NFC shield

Post by Franklin97355 »

Just add a line in the print section like:

Code: Select all

 Serial.println("choice 1"); 

eco_bach
 
Posts: 5
Joined: Wed Jan 22, 2014 2:41 pm

Re: Modifying serial message from Adafruit NFC shield

Post by eco_bach »

Thanks.
But if I have 2 sequential messages isn't there the chance that on the receiving end, there might be some confusion as to which arduino device(game choice) is sending?


I forgot to mention that there will be 2 players. Each player will have 1 of 3 choices at any given time. Think digital rock-paper-scissors.

So in actuality 6 total arduinos.
3 possible game choices Player A
3 possible game choices player B

Based on my listed code, would there be some way to include the game choice as part of the UID hex value??

User avatar
Franklin97355
 
Posts: 23911
Joined: Mon Apr 21, 2008 2:33 pm

Re: Modifying serial message from Adafruit NFC shield

Post by Franklin97355 »

So send another variable, Player, choice, card ID.

eco_bach
 
Posts: 5
Joined: Wed Jan 22, 2014 2:41 pm

Re: Modifying serial message from Adafruit NFC shield

Post by eco_bach »

Thanks, yes had to simply modify PrintHex in
Adafruit_NFCShield_I2C.h

to accept an additional argument

User avatar
Franklin97355
 
Posts: 23911
Joined: Mon Apr 21, 2008 2:33 pm

Re: Modifying serial message from Adafruit NFC shield

Post by Franklin97355 »

Thanks, yes had to simply modify PrintHex in
Adafruit_NFCShield_I2C.h
to accept an additional argument
Could you explain why you chose to change it there rather in your code. Usually if you need to send more data you call the function more than once.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”