Giter Site home page Giter Site logo

cristianmazzettimartin / esp-idf-rc522 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from abobija/esp-idf-rc522

0.0 0.0 0.0 102 KB

C library for interfacing ESP32 with MFRC522 RFID card reader, packaged as ESP-IDF component

License: MIT License

C 99.59% CMake 0.41%

esp-idf-rc522's Introduction

esp-idf-rc522

C library for interfacing ESP32 with MFRC522 RFID card reader.

Library currently just reads serial number of RFID tags, which is enough for most applications.

How to use

This directory is an ESP-IDF component. Clone it (or add it as submodule) into components directory of the project.

Example

This is basic example of scanning RFID tags.

#include <esp_log.h>
#include <inttypes.h>
#include "rc522.h"

static const char* TAG = "rc522-demo";
static rc522_handle_t scanner;

static void rc522_handler(void* arg, esp_event_base_t base, int32_t event_id, void* event_data)
{
    rc522_event_data_t* data = (rc522_event_data_t*) event_data;

    switch(event_id) {
        case RC522_EVENT_TAG_SCANNED: {
                rc522_tag_t* tag = (rc522_tag_t*) data->ptr;
                ESP_LOGI(TAG, "Tag scanned (sn: %" PRIu64 ")", tag->serial_number);
            }
            break;
    }
}

void app_main()
{
    rc522_config_t config = {
        .spi.host = VSPI_HOST,
        .spi.miso_gpio = 25,
        .spi.mosi_gpio = 23,
        .spi.sck_gpio = 19,
        .spi.sda_gpio = 22,
    };

    rc522_create(&config, &scanner);
    rc522_register_events(scanner, RC522_EVENT_ANY, rc522_handler, NULL);
    rc522_start(scanner);
}

FAQ

How to use I2C instead of SPI?

Set the property .transport of the config structure to RC522_TRANSPORT_I2C and choose GPIOs for data (.i2c.sda_gpio) and clock (.i2c.scl_gpio):

rc522_config_t config = {
    .transport = RC522_TRANSPORT_I2C,
    .i2c.sda_gpio = 18,
    .i2c.scl_gpio = 19,
};

How to use halfduplex in SPI transport?

Set the .spi.device_flags property of the config to SPI_DEVICE_HALFDUPLEX. Other device flags (SPI_DEVICE_*) can be set here as well by chaining them with bitwise OR (|) operator.

rc522_config_t config = {
    .spi.host = VSPI_HOST,
    .spi.miso_gpio = 25,
    .spi.mosi_gpio = 23,
    .spi.sck_gpio = 19,
    .spi.sda_gpio = 22,
    .spi.device_flags = SPI_DEVICE_HALFDUPLEX,
};

How to attach RC522 to existing SPI bus?

Let's say that spi bus VSPI_HOST has been already initialized, and rc522 needs to be attached to that bus. That can be accomplished with the next configuration. Property .spi.bus_is_initialized is required to be set to true in order to inform library to not initialize spi bus again.

NOTE: Property .spi.bus_is_initialized will be deprecated in the future once when this issue is resolved.

rc522_config_t config = {
    .spi.host = VSPI_HOST,
    .spi.sda_gpio = 22,
    .spi.bus_is_initialized = true,
};

Author

GitHub: abobija
Homepage: abobija.com

License

MIT

esp-idf-rc522's People

Contributors

abobija avatar abdellah2288 avatar huhaifan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.