• Stars
    star
    136
  • Rank 267,670 (Top 6 %)
  • Language
    C
  • License
    Apache License 2.0
  • Created about 5 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Library for communication with RFID / NFC cards using MFRC522 module

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

More Repositories

1

idfx

Tool for flash/monitor ESP-IDF and ESP8266_SDK apps on the WSL2 ⚡
Shell
92
star
2

esp-discord

C library for making Discord Bots 🤖 on the ESP32, packaged as ESP-IDF component
C
50
star
3

esp-smartconfig-dart

EspTouch and EspTouchV2 implementations of SmartConfig provisioning protocols. Plain Dart. All platforms.
Dart
45
star
4

esp-idf-vscode-boilerplate

Boilerplate for developing ESP-IDF applications using VS Code
CMake
34
star
5

wiattend

💳 RFID Attendance System realized using MFRC522 and ESP32
Lua
27
star
6

api32

🌐 HTTP Server and JSON REST framework in one. This is Lua library for simple way of creating JSON APIs for ESP32
Lua
21
star
7

esp-discord-examples

ESP32 Discord Bot 🤖 examples (ESP-IDF)
C
21
star
8

piezo32

🎵 Piezo buzzer Lua [NodeMCU] library
Lua
15
star
9

esp-dns-hijack-srv

Simple Esp32 DNS Hijack Server, packaged as ESP-IDF component
C
15
star
10

yt-tutorials

Repository used for tutorials that I make on my YouTube channel
C#
14
star
11

wiattend-srv

NodeJS server for RFID attendance system "wiattend"
JavaScript
8
star
12

esp8266-rfid-attendance

Attendance system realized using ESP8266 and RFID cards
Lua
7
star
13

esp-httpd-basic-auth

Wrapper around Httpd which purpose is to secure the Server with a Basic Authorization, packaged as ESP-IDF component
C
5
star
14

mqtt-client

C# MQTT Client Application
C#
5
star
15

rfid32

💳 Lua library for interfacing ESP32 with MFRC522 RFID Card Reader
Lua
4
star
16

wiattend-client

Client for Wiattend [ NodeJS ] Server
JavaScript
4
star
17

discord-rfid

Discord RFID Attendance System realized with ESP32 (esp-idf) and C# (WinForms)
C#
4
star
18

snake

🐍 Snake game written in Typescript
TypeScript
4
star
19

api32-net-client

.NET client for Api32 - NApi32
C#
3
star
20

loggerx

Tiny but powerful Dart logger
Dart
3
star
21

esp32-police-lights

🚓 Police lights effect using ESP32
Lua
3
star
22

docker-ssh

SSH Server Docker Image
Dockerfile
2
star
23

ws32

🔌 ESP32 Lua NodeMCU WebSocket Client Library
Lua
2
star
24

dc-motor-pwm-regulation

DC Motor PWM speed regulation and IR tachometer
C
1
star
25

rfid-server

Simple C# RFID Server
C#
1
star
26

cutils

🛠️ Set of compact and portable C utilities with the intention of being very fast, efficient and easy to use
C
1
star
27

words-and-synonyms

Spring boot Words and Synonyms application
Java
1
star