| Crates.io | embedded-tfluna |
| lib.rs | embedded-tfluna |
| version | 0.2.0 |
| created_at | 2025-09-30 19:33:50.628999+00 |
| updated_at | 2025-10-08 09:54:02.002016+00 |
| description | Platform-agnostic Rust driver for the TF-Luna LiDAR distance sensor. |
| homepage | https://github.com/AnesBenmerzoug/embedded-tfluna/tree/main |
| repository | https://github.com/AnesBenmerzoug/embedded-tfluna/tree/main |
| max_upload_size | |
| id | 1861630 |
| size | 135,787 |
Platform agnostic Rust driver for the TF-Luna LiDAR distance sensor, based on the embedded-hal traits.
This library provides a no_std interface for interacting with the TF-Luna LiDAR distance sensor.
The TF-Luna supports both I2C and UART communication protocols. However, this library only supports I2C for now.
The TF-Luna's characteristics, taken from the user manual, are summarized in the following table:
| Description | Parameter value |
|---|---|
| Operating range | 0.2 ~ 8m1 |
| Accuracy | ±6cm@ (0.2-3m)2 ±2%@ (3m-8m) |
| Measurement unit | cm (Default) |
| Range resolution | 1cm |
| Field of View (FOV) | 0.2°2 |
| Framerate | 1~250Hz3 (100Hz default) |
| Weight | ≤ 5g4 |
| Power | ≤ 0.35W4 |
| Dimensions | 35mm x 21.25mm x 13.5mm4 |
| Communication | I2C and UART5 |
See the examples directory for examples of using the TF-Luna with different micro-controllers and boards.
#![no_std]
#![no_main]
#![deny(
clippy::mem_forget,
reason = "mem::forget is generally not safe to do with esp_hal types, especially those \
holding buffers for the duration of a data transfer."
)]
use defmt::info;
use embedded_tfluna::i2c::{Address, TFLuna};
use esp_hal::clock::CpuClock;
use esp_hal::delay::Delay;
use esp_hal::main;
use esp_hal::time::{Duration, Instant};
use esp_hal::{
i2c::master::{Config as I2cConfig, I2c},
time::Rate,
};
#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
loop {}
}
// This creates a default app-descriptor required by the esp-idf bootloader.
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
esp_bootloader_esp_idf::esp_app_desc!();
#[main]
fn main() -> ! {
rtt_target::rtt_init_defmt!();
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
let peripherals = esp_hal::init(config);
// I2C SDA (Data) Pin
let sda_pin = peripherals.GPIO8;
// I2C SCL (Clock) Pin
let scl_pin = peripherals.GPIO9;
let i2c_config = I2cConfig::default().with_frequency(Rate::from_khz(100));
let i2c = I2c::new(peripherals.I2C0, i2c_config)
.unwrap()
.with_sda(sda_pin)
.with_scl(scl_pin);
let mut tfluna: TFLuna<_, _> = TFLuna::new(i2c, Address::default(), Delay::new()).unwrap();
// Enable measurements
tfluna.enable().unwrap();
loop {
let measurement = tfluna.get_measurement().unwrap();
info!("Distance = {:?}", measurement.distance);
let delay_start = Instant::now();
while delay_start.elapsed() < Duration::from_millis(100) {}
}
}
defmt - Enable logging output using defmt and implement defmt::Format on certain types.
async - Enable asynchronous interface.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Operating range measured indoor based on a standard whiteboard with 90% reflectivity. ↩
This is the theoretical value, the real value may be different. ↩ ↩2
100Hz is the default value and only any factor (500/n, n can be any integer in [2, 500] e.g. 250Hz, 125Hz) of 500Hz are available. ↩
Taken from the TF-Luna's product page. ↩ ↩2 ↩3
The choice between the two is made based on how the 5th pin is connected. Ground for I2C and 3.3V for UART. ↩