invalid conversion from 'byte' to 'const void*'

kasperhangard: well, i thought that inChar or inData would hold the characters? i suppose that isn't the case. how would i then take data from serial.read() and put it into payload?

Why use a middle man if the plan is to just copy everything into payload? Why not just stuff everything into payload instead of inData?

Arrch:

kasperhangard: well, i thought that inChar or inData would hold the characters? i suppose that isn't the case. how would i then take data from serial.read() and put it into payload?

Why use a middle man if the plan is to just copy everything into payload? Why not just stuff everything into payload instead of inData?

So how would i do this? i did fear that i would end up making a bunch of useless code, because of my very basic knowlegde of coding.

Please elaborate :)

Skip the memcpy and do this...

      uint8_t len = NDEF().encode_TEXT((uint8_t *)"en", inData);

DavidOConnor:
Skip the memcpy and do this…

      uint8_t len = NDEF().encode_TEXT((uint8_t *)"en", inData);

Hey David. thanks for your time. Is this what you had in mind?

#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", inData);
   
      boolean success = mifare.writePayload(payload, len);
      Serial.println(success ? "success" : "fail");
 }
 delay(5000);
}

It gives me

TrackR_Write.ino: In function ‘void loop()’:
TrackR_Write:100: error: invalid conversion from ‘char*’ to ‘uint8_t*’
TrackR_Write:100: error: initializing argument 2 of ‘uint8_t NDEF::encode_TEXT(uint8_t*, uint8_t*)’

What did i mess up? I can’t seem to find the error. :confused:

Before posting your code, use the auto format tool in the Arduino IDE: Tools > Auto Format.

Thanks a bunch. That is pretty cool! :slight_smile:

#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", inData);
    boolean success = mifare.writePayload(payload, len);
    Serial.println(success ? "success" : "fail");
  }
  delay(5000);
}

Try this…

 uint8_t len = NDEF().encode_TEXT((uint8_t *)"en", (uint8_t *)inData);

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: http://i.imgur.com/WtVGSN6.png

Not too sure what all your libraries are doing, but it looks like the string you are entering is being encoded. Thus it may expand in size. I suggest you read from the serial port into the payload array instead of inData. And use the payload array in your call to the encoding function.

DavidOConnor: Not too sure what all your libraries are doing, but it looks like the string you are entering is being encoded. Thus it may expand in size. I suggest you read from the serial port into the payload array instead of inData. And use the payload array in your call to the encoding function.

i don't think i need any encoding, so if it can make my code easier, i can live without it. would that help?

Also, How would i read into the payload array, as i haven't declared any index for payload?

I'm so sorry for being such a noob.

kasperhangard:

DavidOConnor: Not too sure what all your libraries are doing, but it looks like the string you are entering is being encoded. Thus it may expand in size. I suggest you read from the serial port into the payload array instead of inData. And use the payload array in your call to the encoding function.

i don't think i need any encoding, so if it can make my code easier, i can live without it. would that help?

Also, How would i read into the payload array, as i haven't declared any index for payload?

I'm so sorry for being such a noob.

 uint8_t len = NDEF().encode_TEXT((uint8_t *)"en", (uint8_t *)inData);
    boolean success = mifare.writePayload(payload, len);

I have no idea what the NDEF and mifare libraries are. However here we are (or should be) calling the encode_TEXT function and passing the result to the writePayload function. If you don't think you need to do that then don't do it.

How to read into the payload array? In your read loop, replace each reference to inData with payload. Change the number 16 to PAYLOAD_SIZE-1.

Rather than blundering around writing random nonsense, your time might be better utilised by obtaining a good C/C++ textbook, and reading it.

DavidOConnor:

kasperhangard:

DavidOConnor: Not too sure what all your libraries are doing, but it looks like the string you are entering is being encoded. Thus it may expand in size. I suggest you read from the serial port into the payload array instead of inData. And use the payload array in your call to the encoding function.

i don't think i need any encoding, so if it can make my code easier, i can live without it. would that help?

Also, How would i read into the payload array, as i haven't declared any index for payload?

I'm so sorry for being such a noob.

 uint8_t len = NDEF().encode_TEXT((uint8_t *)"en", (uint8_t *)inData);
    boolean success = mifare.writePayload(payload, len);

I have no idea what the NDEF and mifare libraries are. However here we are (or should be) calling the encode_TEXT function and passing the result to the writePayload function. If you don't think you need to do that then don't do it.

How to read into the payload array? In your read loop, replace each reference to inData with payload. Change the number 16 to PAYLOAD_SIZE-1.

AARRHHH Thanks a whole bunch! It works now! arh this is amazing! :D

michinyon: Rather than blundering around writing random nonsense, your time might be better utilised by obtaining a good C/C++ textbook, and reading it.

Please don't get me wrong. i am really trying to learn this. I am not just making these amazing forum guys do it for me. I have been using like 12 hours the last couple of days, just reading up on arduino, eventually peeking over at the forums. :)

string without the capital S gives me: 'string' does not name a type

Get a C book. Learn what a string is. It is a NULL-terminated [u]array of chars[/u].