Native NFC Support

@eugene0501 Thanks for the fix which got me past my compile issues and I was able to deploy the NFC example app for testing. Unfortunately, I was not able to cause an NFC event using my Google Pixel 2 Android + NXP Tag Writer App.

I did add some debug statements to confirm my app was working. Notice the button press is working, but the NFC triggered event is never published.

The code I used with the feature/hal/nfc device os branch.

#include "application.h"
#line 1 "/Users/aaronroller/dev/projects/particle/nfc-test/src/nfc-demo.ino"

void nfc_event_handler(nfc_event_type_t type, nfc_event_t *event, void* ctx);
void setup();
void loop();
#line 2 "/Users/aaronroller/dev/projects/particle/nfc-test/src/nfc-demo.ino"

bool nfc_event_received = false;

void nfc_event_handler(nfc_event_type_t type, nfc_event_t *event, void* ctx) {
    switch (type) {
        case NFC_EVENT_FIELD_ON:  digitalWrite(D7, 1); break;
        case NFC_EVENT_FIELD_OFF: digitalWrite(D7, 0); break;
        case NFC_EVENT_READ:      digitalWrite(D7, 0); break;
        default: break;
    }
    nfc_event_received = true;
}
bool button_pressed = false;

void setup() {
    pinMode(BATT, INPUT);
    pinMode(D7, OUTPUT);
    digitalWrite(D7, 0);

    System.on(button_click, [](system_event_t ev, int clicks)->void {
        NFC.getNdefMessage()[0] = std::make_shared<TextRecord>("Update record - 1!", "en");
        NFC.getNdefMessage()[1] = std::make_shared<TextRecord>("Update record - 2!", "en");
        NFC.getNdefMessage()[2] = std::make_shared<TextRecord>("Update record - 3!", "en");
        NFC.getNdefMessage().addTextRecord("New record!", "en");

        NFC.stop();
        NFC.start(nfc_event_handler);
        button_pressed = true;
    });

    NFC.getNdefMessage().addTextRecord("Hello Particle!", "en");
    NFC.getNdefMessage().addUriRecord("particle.io", UriRecord::NFC_URI_HTTPS_WWW);
    NFC.getNdefMessage().addLauchAppRecord("no.nordicsemi.android.nrftoolbox");

    NFC.start(nfc_event_handler);
}

unsigned long time_voltage_last_sent = 0;

void loop() {
    if(millis() - time_voltage_last_sent > 60000) {
        float voltage = analogRead(BATT) * 0.0011224;
        
        Particle.publish("voltage", String::format("%.2f",voltage), PRIVATE);
        time_voltage_last_sent = millis();
    }

    if(button_pressed){
        button_pressed = false;
        Particle.publish("NFC", "button pressed...NFC records updated", PRIVATE);
    }

    if(nfc_event_received){
        nfc_event_received = false;
        Particle.publish("NFC", "NFC Event Received", PRIVATE);
    }
}

I’m using a seeedstudio.com NFC antenna hooked up to the only connector on the Xenon. I’ve already some Particle Antennas so I can try a different antenna.

Any other suggestions to try?

Thanks.

@schooltag Please try to change to Particle Antenna, the connector is on the back of the Xenon board, I tested NFC by using NFC Reader application on Android.

Yay! Same antenna, but I previously had it connected to the BT connector. Moving it to the back worked! I’m super excited to dig in.

1 Like

@eugene0501 Now that the code is working with an active NFC tag, is it possible to read a passive NFC tag?

I have several types of passive NFC tags like stickers, key fobs, transportation card, etc. One I know is an NXP ntag213, for example.

Such would require the Antenna to power the non-powered passive tag so the tag can emit the data back to the antenna, just as the Android phone does when reading these tags.

Testing the tags and looking at the Device OS NFC code I do not see an NFC_EVENT_WRITE event that would receive data from another tag, the opposite of the READ event that transferred data from the Xenon to the mobile phone.

The story I’m trying to implement is to have the Xenon read a passive NFC tag.

Thanks! Aaron

1 Like

I’m afraid we can’t, we only support emulating a NFC type2 tag, you can’t use it to read any tag. ¯(°_o)/¯

Gotcha. I would suggest updating the feature specifications to explain the limitation you can’t use it to read any tag. Right now it just says NFC-A radio, but I would suggest Acts as a passive NFC tag that can transfer data to a mobile app or something like that. I realize that is a different department so the note is for others listening.

Still very useful to allow a device administrator to the read the state of sensors with a mobile phone, etc. It just isn’t possible to know if anyone has visited the device…like security guards or students walking to school in my case.

I will be pursuing integrating an active NFC tag reader into the mesh products that can read a passive NFC Type 2 tag. Something like Solo Mifare for RFID. Any suggestions would be appreciated.

It’s worth noting I have clarified my use case with Particle engineers multiple times since last summer which led me here to continue the investigation since nobody could give an exact answer. Thanks @eugene0501 for flushing out the reality so I can focus on a solution that will work.

Thanks,

Aaron

3 Likes

Thanks for the clarification @eugene0501

I was wondering if reading or writing tags is a limitation of the nRF52840 chip or whether the lack of support is more of a software choice?

Thanks!

It’s a software choice, the NFC driver of SDK15.0 which is used in device OS is a beta version, it has changed a lot in the new SDK 15.3. We Implemented basic NFC function (Passive Tag, read-only mode) for the first phase.

1 Like

Please could you give me an update on the status of NFC support for Argon – any idea when this will be released as part of the standard Particle software (which I guess is “Wiring” as mentioned above) ?

@Pertspider, both BLE and NFC are being Alpha tested as we speak. I suspect a release candidate will be released very soon.

1 Like

OK that’s great news, thanks for the update !

1 Like

Awesome news !

1 Like

As a follow up, Particle documentation now explains the limitations appropriately.

Particle Gen 3 devices only support emulating an NFC tag. They cannot locate or communicate with tags themselves, or support protocols such as for NFC payments.

1 Like

Hei, thanks @schooltag for saving me a lot of time. Only this is very unfortunate that I discover now that there is no support to write something via NFC to a gen3 device. I will ask support about when and if they have this feature in the pipe line as it is crucial to my product. If anybody knows about the timeline before I get a response please let me know.

@doozMen, the limitations for NFC reading only is imposed by the hardware (nRF82540) and not by the DeviceOS so there will never be a way to write to the Gen3 devices via NFC. Instead, you should consider BLE for doing this, if at all possible.

1 Like

I had understood it to be a software limitation

BLE only is not sufficient, but for now we can focus on that. For the release we need NFC bidirectional. We are using a passive tag for battery free access. As we control security doors this is a must have. Thanks for clarifying and we will discuss options with the engineering team tomorrow then. Looks like we have to implement a separate reader then.

@Jak, you are correct it seems! From a Nordic DevZone 2017 posting:

The nRF52832 and nRF52840 devices have a built-in NFC radio which can be used for exposing data as a dynamic NFC tag (a tag with configurable data). This can be used as a standard tag type for storing a web link or a text, to launch apps on smartphones and tablets as well as for simple and secure BLE pairing (read more here). All these features are provided by the Type 2 Tag library in the nRF5 SDK. Starting from version 12.2 of the nRF5 SDK, we expanded the NFC software to support even more features. The new Type 4 Tag library does not only allow faster communication and exposing more data in the tag, but also provides the write functionality. So you can write data to the tag with an NFC Reader/Writer such as a smartphone. Furthermore, NFC Type 4 Tag is used in many secure transactions systems, e.g., payment systems, transport ticketing systems etc. Thus, it opens up new markets for the nRF52 Series with its combined NFC and BLE functionallity.

I will ping Particle to see if implementing Type 4 support is on their radar.

2 Likes

I have been using the MFRC522 extensively to read and write with the particle argon and xenon and Arduino boards. I suggest looking into those for a quick and easy and inexpensive alternate solution. The MFRC522 library examples will get you up and running quickly. Happy to help if you run into issues.

Aaron

Hey folks – thanks for the ping. We’re still looking to better understand use cases for NFC as it relates to Particle customer products, so if you have specific needs for NFC Type 4 support versus Type 2, let us know what those are.

1 Like