You are using staging server - a separate instance of the ESP Component Registry that allows you to try distribution tools and processes without affecting the real registry.

modnarlluf/rc522-mifare-ndef

0.0.1

Latest
uploaded 12 hours ago
RC522 component for SPI

Readme

## RC522-MIFARE-NDEF (ESP-IDF component)

C++ component to read Mifare 1k PICC with a RC522 module. 

## Usage

```c++
#include "esp_log.h"
#include "picc.hpp"
#include "rc522_mifare_ndef.hpp"
#include "driver/spi_master.h"
#include "driver/gpio.h"
#include "freertos/FreeRTOS.h"

static const auto *TAG = "MAIN";

extern "C" void app_main(void) {
    spi_bus_config_t buscfg = {};
    buscfg.miso_io_num = GPIO_NUM_4;
    buscfg.mosi_io_num = GPIO_NUM_5;
    buscfg.sclk_io_num = GPIO_NUM_6;
    buscfg.quadwp_io_num = -1;
    buscfg.quadhd_io_num = -1;
    buscfg.max_transfer_sz = 32;

    ESP_ERROR_CHECK(spi_bus_initialize(SPI3_HOST, &buscfg, SPI_DMA_CH_AUTO));

    RC522 rc522 = RC522(SPI3_HOST, GPIO_NUM_7, GPIO_NUM_15, GPIO_NUM_NC);
    rc522.init();

    rc522.antennaOn();
    while (true) {
        auto picc = PiccMifare();

        if (rc522.isNewPiccDetected(picc)) {
            ESP_LOGI(TAG, "New PICC detected");
            rc522.mifareDump(picc);

            ESP_LOGI(TAG, "Data size : %d", picc.getData().size());

            if (picc.isNdefFormatted()) {
                std::vector<NdefRecord> records;
                picc.getNdefRecords(records);

                ESP_LOGI(TAG, "Found %d records", records.size());

                for (NdefRecord &r: records) {
                    ESP_LOGI(TAG, "----------------");
                    ESP_LOGI(TAG, "Record type 0x%02X", r.getType());
                    ESP_LOGI(TAG, "Record type RTD 0x%02X", r.getTypeRtd());
                }
            } else {
                ESP_LOGI(TAG, "Not NDEF formatted");
            }

            vTaskDelay(pdMS_TO_TICKS(1000));
        }

        vTaskDelay(pdMS_TO_TICKS(100));
    }
}
```

Links

Supports all targets

To add this component to your project, run:

idf.py add-dependency "modnarlluf/rc522-mifare-ndef^0.0.1"

download archive

Stats

  • Archive size
    Archive size ~ 9.94 KB
  • Downloaded in total
    Downloaded in total 0 times
  • Downloaded this version
    This version: 0 times

Badge

modnarlluf/rc522-mifare-ndef version: 0.0.1
|