5 releases (2 stable)
Uses new Rust 2024
| 1.0.1 | Dec 4, 2025 |
|---|---|
| 0.1.2 | Nov 28, 2025 |
| 0.1.1 | Nov 28, 2025 |
| 0.1.0 | Nov 28, 2025 |
#396 in Embedded development
630KB
2.5K
SLoC
uhf-rfid
A Rust driver for M5Stack UHF RFID readers with support for multiple transport backends.
Features
- ESP32 UART support - Native UART transport for ESP32 using
esp-idf-hal - Desktop serial support - Serial port transport using the
serialportcrate - Full EPC Gen2 support - Tag polling, reading, writing, locking, and killing
- Advanced configuration - Region settings, RF link profiles, frequency hopping, and more
- Vendor extensions - NXP UCODE and Impinj Monza specific commands
Installation
Add to your Cargo.toml:
[dependencies]
uhf-rfid = "0.1"
Enable the appropriate feature for your platform:
# For desktop/Linux serial port
uhf-rfid = { version = "0.1", features = ["serial"] }
# For ESP32
uhf-rfid = { version = "0.1", features = ["uart-esp32"] }
Usage
Desktop (Serial Port)
use uhf_rfid::{UhfRfid, SerialTransport};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let transport = SerialTransport::new("/dev/ttyUSB0", 115200)?;
let mut rfid = UhfRfid::new(transport);
// Get firmware version
let version = rfid.get_firmware_version()?;
println!("Firmware: {}", version);
// Poll for a single tag
if let Some(tag) = rfid.single_poll()? {
println!("Found tag: {} (RSSI: {})", tag.epc, tag.rssi);
}
// Poll for multiple tags (100 inventory rounds)
let tags = rfid.multiple_poll(100)?;
for tag in tags {
println!("Tag: {}", tag.epc);
}
// Poll with callback for real-time processing (100 inventory rounds)
let count = rfid.multiple_poll_with_callback(100, |tag| {
println!("Discovered tag: {} (RSSI: {})", tag.epc, tag.rssi);
})?;
println!("Total tags found: {}", count);
Ok(())
}
ESP32 (UART)
use esp_idf_svc::hal::peripherals::Peripherals;
use uhf_rfid::{UhfRfid, UartTransport};
fn main() -> anyhow::Result<()> {
esp_idf_svc::sys::link_patches();
let peripherals = Peripherals::take()?;
let transport = UartTransport::new(
peripherals.uart1,
peripherals.pins.gpio17, // TX
peripherals.pins.gpio16, // RX
115200,
)?;
let mut rfid = UhfRfid::new(transport);
// Get firmware version
let version = rfid.get_firmware_version()?;
println!("Firmware: {}", version);
// Poll for tags
if let Some(tag) = rfid.single_poll()? {
println!("Found tag: {} (RSSI: {})", tag.epc, tag.rssi);
}
Ok(())
}
Supported Operations
- Polling: Single and multiple tag inventory
- Memory access: Read/write tag memory banks (EPC, TID, User, Reserved)
- Security: Lock and kill tags
- Configuration: TX power, region, channel, frequency hopping, baud rate
- Advanced: Select filtering, query parameters, RF link profiles
- Vendor-specific: NXP EAS, read protect; Impinj Monza QT
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Dependencies
~0–11MB
~83K SLoC