Crate isl29125

Source
Expand description

This is a platform agnostic Rust driver for the low-power digital RGB color light sensor with IR blocking filter using the embedded-hal traits.

This driver allows you to:

§The device

The ISL29125 is a low power, high sensitivity, RED, GREEN and BLUE color light sensor (RGB) with an I2C (SMBus compatible) interface. Its state-of-the-art photodiode array provides an accurate RGB spectral response and excellent light source to light source variation (LS2LS).

The ISL29125 is designed to reject IR in light sources allowing the device to operate in environments from sunlight to dark rooms. The integrating ADC rejects 50Hz and 60Hz flicker caused by artificial light sources. A selectable range allows the user to optimize sensitivity suitable for the specific application. In normal operation mode the device consumes 56μA, which reduces to 0.5μA in power-down mode.

The ISL29125 supports hardware and software user programmable interrupt thresholds. The Interrupt persistency feature reduces false trigger notification.

Datasheet: ISL29125

§Usage examples (see also examples folder)

To use this driver, import this crate and an embedded_hal implementation, then instantiate the device.

Please find additional examples using hardware in this repository: driver-examples

§Enable reading RGB and print the values

extern crate linux_embedded_hal as hal;
use isl29125::{Isl29125, OperatingMode};

let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = Isl29125::new(dev);
sensor
    .set_operating_mode(OperatingMode::RedGreenBlue)
    .unwrap();
loop {
    let m = sensor.read().unwrap();
    println!("R: {}, G: {}, B: {}", m.red, m.green, m.blue);
}

§Measure only the red color

extern crate linux_embedded_hal as hal;
use isl29125::{Isl29125, OperatingMode};

let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = Isl29125::new(dev);
sensor
    .set_operating_mode(OperatingMode::RedOnly)
    .unwrap();
loop {
    let red = sensor.red().unwrap();
    println!("Red: {}", red);
}
extern crate linux_embedded_hal as hal;
use isl29125::{
    Isl29125, OperatingMode, FaultCount, InterruptThresholdAssignment
};

let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = Isl29125::new(dev);
sensor
    .set_operating_mode(OperatingMode::GreenOnly)
    .unwrap();
let ita = InterruptThresholdAssignment::Green;
sensor.set_interrupt_threshold_assignment(ita).unwrap();
sensor.set_fault_count(FaultCount::Four).unwrap();
sensor.set_interrupt_thresholds(150, 8500).unwrap();
loop {
    while !sensor.status().unwrap().interrupt_triggered {}
    let green = sensor.green().unwrap();
    println!("Green: {}", green);
}

§Set the IR filtering

extern crate linux_embedded_hal as hal;
use isl29125::{Isl29125, IRFilteringRange};

let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = Isl29125::new(dev);
sensor
    .set_ir_filtering(IRFilteringRange::Lower(35))
    .unwrap();

Structs§

Isl29125
ISL29125 device driver
Measurement
Measurement result
Status
Status

Enums§

ConversionStatus
RGB conversion status
Error
All possible errors in this crate
FaultCount
Fault count
IRFilteringRange
IR filtering range
InterruptPinMode
Interrupt pin (INT) mode
InterruptThresholdAssignment
Interrupt threshold assignment
OperatingMode
Operating mode
Range
RGB data sensing range
Resolution
ADC resolution