ESP32 - AirTag Documentation
|
ESP32 BLE Central with RFID and LCD UI. More...
#include <Arduino.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEClient.h>
#include <BLEScan.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <SPI.h>
#include <MFRC522.h>
#include "BLEScanner.h"
#include "distance.h"
Macros | |
#define | SERVICE_UUID "275dc6e0-dff5-4b56-9af0-584a5768a02a" |
#define | BUTTON_CHAR_UUID "b51bd845-2910-4f84-b062-d297ed286b1f" |
#define | IMU_CHAR_UUID "0679c389-0d92-4604-aac4-664c43a51934" |
#define | BUZZER_PIN 42 |
#define | RESET_PIN 41 |
#define | RFID_PIN 40 |
#define | PIN_SCK 13 |
#define | PIN_MISO 11 |
#define | PIN_MOSI 12 |
#define | PIN_SS 14 |
#define | PIN_RST 10 |
Functions | |
void | BLEScannerTask (void *pvParameters) |
Task to scan for BLE peripherals. | |
void | distanceTask (void *pvParameters) |
Task to compute distance from RSSI. | |
void | UITask (void *pvParameters) |
Task to update LCD UI. | |
void | buttonTask (void *pvParameters) |
Task to handle button input. | |
void | RFIDTask (void *pvParameters) |
Task to handle RFID scanning and authorization. | |
void | resetButtonTask (void *pvParameters) |
Task to reset RFID and lock system. | |
LiquidCrystal_I2C | lcd (0x27, 16, 2) |
MFRC522 | rfid (PIN_SS, PIN_RST) |
bool | isAuthorized () |
Check if RFID UID is authorized. | |
void | setup () |
Arduino setup function. Initializes queues, peripherals, tasks, and starts FreeRTOS. |
Variables | |
TaskHandle_t | UITaskHandle |
TaskHandle_t | ButtonTaskHandle |
TaskHandle_t | RFIDTaskHandle |
QueueHandle_t | IMUQ |
QueueHandle_t | RSSIQ |
QueueHandle_t | disQ |
QueueSetHandle_t | uiSet = nullptr |
uint32_t | startTime |
byte | AUTH_UID [] = { 0x04, 0x81, 0x70, 0x0A, 0x9C, 0x14, 0x90 } |
Authorized UID for RFID access. |
ESP32 BLE Central with RFID and LCD UI.
This sketch implements an ESP32 BLE central device that:
#define BUTTON_CHAR_UUID "b51bd845-2910-4f84-b062-d297ed286b1f" |
Button characteristic UUID
#define BUZZER_PIN 42 |
GPIO pin for buzzer/button
#define IMU_CHAR_UUID "0679c389-0d92-4604-aac4-664c43a51934" |
IMU characteristic UUID
#define PIN_MISO 11 |
RC522 MISO pin
#define PIN_MOSI 12 |
RC522 MOSI pin
#define PIN_RST 10 |
RC522 reset
#define PIN_SCK 13 |
RC522 SCK pin
#define PIN_SS 14 |
RC522 chip select (SDA/SS)
#define RESET_PIN 41 |
GPIO pin for reset button
#define RFID_PIN 40 |
GPIO pin for RFID buzzer
#define SERVICE_UUID "275dc6e0-dff5-4b56-9af0-584a5768a02a" |
< BLE core (ESP32 Arduino core 3.x uses NimBLE backend) < I2C LCD library < I2C bus < SPI bus < RFID RC522 driver < Custom BLE scanning logic < Distance estimation from RSSI Service UUID
void BLEScannerTask | ( | void * | pvParameters | ) |
Task to scan for BLE peripherals.
BLE scanner task.
void buttonTask | ( | void * | pvParameters | ) |
Task to handle button input.
Button task.
void distanceTask | ( | void * | pvParameters | ) |
Task to compute distance from RSSI.
Distance estimation task.
bool isAuthorized | ( | ) |
Check if RFID UID is authorized.
true | if UID matches AUTH_UID |
false | otherwise |
LiquidCrystal_I2C lcd | ( | 0x27 | , |
16 | , | ||
2 | ) |
I2C LCD (16x2)
void resetButtonTask | ( | void * | pvParameters | ) |
Task to reset RFID and lock system.
Reset button task.
void RFIDTask | ( | void * | pvParameters | ) |
Task to handle RFID scanning and authorization.
RFID task.
void setup | ( | ) |
Arduino setup function. Initializes queues, peripherals, tasks, and starts FreeRTOS.
void UITask | ( | void * | pvParameters | ) |
Task to update LCD UI.
UI task.
byte AUTH_UID[] = { 0x04, 0x81, 0x70, 0x0A, 0x9C, 0x14, 0x90 } |
Authorized UID for RFID access.
TaskHandle_t ButtonTaskHandle |
Handle for button task
QueueHandle_t disQ |
Queue for distance values
QueueHandle_t IMUQ |
Queue for IMU moving flag
TaskHandle_t RFIDTaskHandle |
Handle for RFID task
QueueHandle_t RSSIQ |
Queue for RSSI values
uint32_t startTime |
Timer for RSSI sampling
QueueSetHandle_t uiSet = nullptr |
Queue set for UI multiplexing
TaskHandle_t UITaskHandle |
Handle for UI task