Expand description
A platform agnostic Rust driver for the Silicon Labs Si1145/46/47 ambient light sensor based on
the embedded-hal traits.
§Overview
The Si1145/46/47 is a low-power, reflectance-based, infrared proximity, ultraviolet (UV) index, and ambient light sensor with I2C digital interface and programmable event interrupt output.
§Usage
§Creation
Import the crate and the embedded-hal implementation to instantiate the device:
use linux_embedded_hal as hal;
use hal::{Delay, I2cdev};
use si1145::Si1145;
let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut si1145 = Si1145::new(dev, &mut Delay).unwrap();§Measurement
You can perform measurements of the ambient light lux and UV index whenever measurements are ready. The device is configured to automatically perform measurements at ~8ms/channel intervals.
use linux_embedded_hal as hal;
use hal::{Delay, I2cdev};
use embedded_hal::delay::DelayNs;
use si1145::Si1145;
#let dev = I2cdev::new("/dev/i2c-1").unwrap();
#let mut si1145 = Si1145::new(dev, &mut Delay).unwrap();
loop {
if si1145.measurement_read().unwrap() {
let lux = si1145.measure_lux().unwrap();
let uv_index = si1145.measure_uv_index().unwrap();
println!("Ambient light lux: {lux} lx, UV index: {uv_index:.2f}");
}
Delay.delay_ms(1000u16);
}