PlatformIO Community

Can't build project using the Adafruit PN532 library with platformio, but will build just fine in the Arduino IDE

Hello, I’ve encountered a strange issue. I can’t seem to be able to build even the example sketch of the PN532 library from Adafruit. But if I try to compile the exact same code(same libraries too, copy pasted from the lib folder of platformio to the libraries folder of the arduino ide), it compiles without any issues. The sketch in question is the “readMirafe”. The following error is displayed when compiling the code:

In file included from src/main.cpp:4:
include/rfidModule.h: In function 'void read_card()':
include/rfidModule.h:25:85: error: no matching function for call to 'Adafruit_PN532::readPassiveTargetID(int, uint32_t [4], uint32_t*)'
     if (! nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, card_uid, &card_uid_length)) {
                                                                                     ^
In file included from include/rfidModule.h:4,
                 from src/main.cpp:4:
lib/Adafruit_PN532/Adafruit_PN532.h:171:8: note: candidate: 'bool Adafruit_PN532::readPassiveTargetID(uint8_t, uint8_t*, uint8_t*, uint16_t)'
   bool readPassiveTargetID(
        ^~~~~~~~~~~~~~~~~~~
lib/Adafruit_PN532/Adafruit_PN532.h:171:8: note:   no known conversion for argument 2 from 'uint32_t [4]' {aka 'unsigned int [4]'} to 'uint8_t*' {aka 'unsigned char*'}

Write

     if (! nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, (uint8_t*) card_uid, &card_uid_length)) {

instead.

Same error :confused:

In file included from src/main.cpp:4:
include/rfidModule.h: In function 'void read_card()':
include/rfidModule.h:30:96: error: no matching function for call to 'Adafruit_PN532::readPassiveTargetID(int, uint8_t*, uint32_t*)'
     if (! nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, (uint8_t*) card_uid, &card_uid_length)) {
                                                                                                ^
In file included from include/rfidModule.h:9,
                 from src/main.cpp:4:
lib/Adafruit_PN532/Adafruit_PN532.h:171:8: note: candidate: 'bool Adafruit_PN532::readPassiveTargetID(uint8_t, uint8_t*, uint8_t*, uint16_t)'
   bool readPassiveTargetID(
        ^~~~~~~~~~~~~~~~~~~
lib/Adafruit_PN532/Adafruit_PN532.h:171:8: note:   no known conversion for argument 3 from 'uint32_t*' {aka 'unsigned int*'} to 'uint8_t*' {aka 'unsigned char*'}
*** [.pio\build\esp32doit-devkit-v1\src\main.cpp.o] Error 1

Change the type of this variable from uint32_t card_uid_length; to uint8_t card_uid_length;.

The reference example has the correct types

but you have changed the UID buffer from a uint8_t array to a uint32_t array, and uid length too from uint8_t to uint32_t – that’s where your errors are coming from.

that fixed it, thanks!