LTR-303ALS
This is a platform-agnostic Rust driver for the LTR-303 Ambient Light Sensor
using embedded-hal
traits.
Tested with the following sensor(s): - LTR-303ALS-01
start_measurement()
data_ready()
get_status()
get_lux_data()
standby()
get_part_id()
and get_mfc_id()
On Linux using i2cdev: ```rust use linuxembeddedhal::I2cdev; use ltr303::{LTR303, LTR303Config};
fn main() { let dev = I2cdev::new("/dev/i2c-1").unwrap(); let mut sensor = LTR303::init(dev); let config = LTR303Config::default();
loop {
sensor.start_measurement(&config).unwrap();
while sensor.data_ready().unwrap() != true {
// Wait for measurement ready
}
let lux_val = sensor.get_lux_data().unwrap();
println!("LTR303 current lux phys: {}", lux_val.lux_phys);
}
}
On an ESP32-based development board:
```rust use embeddedhal::prelude::*; use espidfsys as _; use espidfhal::{delay::FreeRtos, i2c}; use espidf_hal::peripherals::Peripherals; use ltr303::{LTR303, LTR303Config};
fn main() { espidfsys::link_patches();
let _peripherals = Peripherals::take().unwrap();
// The i2c pins
let sda = _peripherals.pins.gpio4.into_input_output().unwrap();
let scl = _peripherals.pins.gpio6.into_output().unwrap();
let _cfg = i2c::config::MasterConfig::new().baudrate(10000.into());
let _i2c = i2c::Master::new(_peripherals.i2c0, i2c::MasterPins { sda, scl }, _cfg).unwrap();
let mut ltr303 = LTR303::init(_i2c);
let ltr303_config =
LTR303Config::default().with_integration_time(ltr303::IntegrationTime::Ms400);
loop {
ltr303.start_measurement(<r303_config).unwrap();
while ltr303.data_ready().unwrap() != true {
// Wait for measurement ready
}
let lux_val = ltr303.get_lux_data().unwrap();
println!("LTR303 current lux phys: {}", lux_val.lux_phys);
FreeRtos.delay_ms(3000_u32);
}
}
```