DavidOConnor:
Try this...
uint8_t len = NDEF().encode_TEXT((uint8_t *)"en", (uint8_t *)inData);
Aight so i made that change, and i did compile alright.
I made a change to my sucess print, which made it print whatever it printed to my NFC chip.
This gave me some pretty wierd results. i my guess would be that i can't just print inData like this?
Serial.println(success ? inData : "fail");
#include <Wire.h>
//I2C:
char inData[17]; // Allocate some space for the string
char inChar; // Where to store the character read
byte index = 0; // Index into array; where to store the character
#include <PN532_I2C.h>
#define IRQ 2
#define RESET 3
PN532 * board = new PN532_I2C(IRQ, RESET);
//end I2C -->
//SPI:
//#include <PN532_SPI.h>
//
//#define SCK 13
//#define MOSI 11
//#define SS 10
//#define MISO 12
//
//PN532 * board = new PN532_SPI(SCK, MISO, MOSI, SS);
//end SPI -->
#include <Mifare.h>
Mifare mifare;
//init keys for reading classic
uint8_t Mifare::useKey = KEY_B;
uint8_t Mifare::keyA[6] = {
0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7 };
uint8_t Mifare::keyB[6] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
uint32_t Mifare::cardType = 0; //will get overwritten if it finds a different card
#include <NDEF.h>
#define PAYLOAD_SIZE 236
uint8_t payload[PAYLOAD_SIZE] = {
};
void setup(void) {
Serial.begin(115200);
board->begin();
uint32_t versiondata = board->getFirmwareVersion();
if (! versiondata) {
Serial.println("err");
while (1); // halt
}
// Got ok data, print it out!
Serial.print("5");
Serial.println((versiondata>>24) & 0xFF, HEX);
// Serial.print("v: "); Serial.println((versiondata>>16) & 0xFF, DEC);
// Serial.println((versiondata>>8) & 0xFF, DEC);
// Serial.print("Supports "); Serial.println(versiondata & 0xFF, HEX);
if(mifare.SAMConfig()){
Serial.println("ok");
}
else{
Serial.println("er");
}
}
void loop(void) {
uint8_t * uid = mifare.readTarget();
if(uid){
Serial.println(Mifare::cardType == MIFARE_CLASSIC ?"Classic" : "Ultralight");
memset(payload, 0, PAYLOAD_SIZE);
while(Serial.available() > 0) // Don't read unless
// there you know there is data
{
if(index < 16) // One less than the size of the array
{
inChar = Serial.read(); // Read a character
inData[index] = inChar; // Store it
index++; // Increment where to write next
inData[index] = '\0'; // Null terminate the string
}
}
uint8_t len = NDEF().encode_TEXT((uint8_t *)"en", (uint8_t *)inData);
boolean success = mifare.writePayload(payload, len);
Serial.println(success ? inData : "fail");
}
delay(5000);
}
I tried writing 3 times.
I send this through serial.
1st time: I
2nd time: messed
3rd. time: up
this gave me this: Imgur: The magic of the Internet