RFID Electron and GPS tracker


I’m connecting a RFID to electron and I also have a ASSET TRACKER V2.

When I connecting RFID on the ASSET Tracker board, it does not work and doesn’t send the scan events.

What am I doing wrong, please help.


#include <MFRC522.h>
#include <AssetTracker.h>

#define SS_PIN      A2
#define RST_PIN     D2

int transmittingData = 1;

MFRC522 mfrc522(SS_PIN, RST_PIN);	// Create MFRC522 instance.

// Creating an AssetTracker named 't' for us to reference
AssetTracker t = AssetTracker();

void setup() {
    Particle.publish("setup", "1");

void loop() {


    // Proceed only if card scanned
    if ( ! mfrc522.PICC_IsNewCardPresent()) {
    if ( ! mfrc522.PICC_ReadCardSerial()) {
    String cardID = "";
    for (byte i = 0; i < mfrc522.uid.size; i++) {
        cardID += String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : "");
        cardID += String(mfrc522.uid.uidByte[i], HEX);

    // Log.info("Scan Completed: " + cardID);
    Particle.publish("rfid_scan", cardID);
    // Send GPS
    if (t.gpsFix()) {
        // Only publish if we're in transmittingData mode 1;
        if (transmittingData) {
            // Short publish names save data!
            Particle.publish("G", t.readLatLon(), 60, PRIVATE);

Does the library sample work?

Yes, if I remove the Asset Tracker, it works fine.

One reason might be that the accelerometer on the AssetTracker also uses SPI and the two settings may not be compatible.
You could either use SPI.beginTransaction() or move your RFID reader to SPI1

But if you want to go down the rabbit hole, you could look at the implementation of both libraries and figure out what exactly is the reason and work around that.

BTW, we usually recommend using AssetTrackerRK library as it it more advanced and reliable than the somewhat dated AssetTracker library.

SPI.beginTransaction() - did not work just using the electron without connecting the AssetTracker so I’m using SPI.begin()

how do I use SPI1? I changed the connectors to SPI1 but doesn’t the code needs to say it has to initialize for SPI1 somewhere?

I’m very new to this, appreciate your help.

It’s a pitty, but MFRC522 lib is not kitted out with a constructor that allows to choose another SPI interface. Neither does is support transactions.

Maybe if you file an issue on the GitHub repo @peekay123 may be so kind to update the library that way :wink:

You also cannot use pin A2 for the MFRC522 SS pin. It’s already used for the AssetTracker LIS3DH SS pin, so you need to select a different pin. Any free GPIO can be used (assuming it’s connected properly).