Crate max44009[][src]

Expand description

This is a platform agnostic Rust driver for the MAX44009 and MAX44007 ambient light sensors (ALS), based on the embedded-hal traits.

This driver allows you to:

  • Read lux measurement.
  • Set the measurement mode.
  • Set the configuration mode.
  • Set the integration time.
  • Set the current division ratio.
  • Read the integration time.
  • Read the current division ratio.
  • Enable/disable interrupt generation.
  • Check if an interrupt has happened.

The devices

The MAX44009 and MAX44007 ambient light sensors feature an I2C digital output that is ideal for a number of portable applications such as smartphones, notebooks, and industrial sensors. At less than 1μA operating current, the MAX44009 is the lowest power ambient light sensor in the industry and features an ultra-wide 22-bit dynamic range from 0.045 lux to 188,000 lux. Low-light operation allows easy operation in dark-glass applications. The on-chip photodiode’s spectral response is optimized to mimic the human eye’s perception of ambient light and incorporates IR and UV blocking capability. The adaptive gain block automatically selects the correct lux range to optimize the counts/lux.

Datasheets: MAX44007, MAX44009

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

Read lux

Import this crate and an embedded_hal implementation, then instantiate the device:

use linux_embedded_hal::I2cdev;
use max44009::{ Max44009, SlaveAddr };

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let address = SlaveAddr::default();
let mut sensor = Max44009::new(dev, address);
let lux = sensor.read_lux().unwrap();

Provide an alternative address

use linux_embedded_hal::I2cdev;
use max44009::{ Max44009, SlaveAddr };

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let a0 = true;
let address = SlaveAddr::Alternative(a0);
let mut sensor = Max44009::new(dev, address);

Enable interruptions and see if one has happened

use linux_embedded_hal::I2cdev;
use max44009::{ Max44009, SlaveAddr };

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = Max44009::new(dev, SlaveAddr::default());
sensor.enable_interrupt().unwrap();
if sensor.has_interrupt_happened().unwrap() {
    println!("Interrupt happened.");
}

Set the measurement mode to continuous

use linux_embedded_hal::I2cdev;
use max44009::{ Max44009, SlaveAddr, MeasurementMode };

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = Max44009::new(dev, SlaveAddr::default());
sensor.set_measurement_mode(MeasurementMode::Continuous).unwrap();

Read the parameters selected in automatic mode

use linux_embedded_hal::I2cdev;
use max44009::{ Max44009, SlaveAddr };

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = Max44009::new(dev, SlaveAddr::default());
let it  = sensor.read_integration_time().unwrap();
let cdr = sensor.read_current_division_ratio().unwrap();

Configure manually

  • Set configuration mode to manual.
  • Set current division ratio to 1/8.
  • Set integration time to 100ms.
use linux_embedded_hal::I2cdev;
use max44009::{ Max44009, SlaveAddr, ConfigurationMode,
                CurrentDivisionRatio, IntegrationTime };

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = Max44009::new(dev, SlaveAddr::default());
sensor.set_configuration_mode(ConfigurationMode::Manual).unwrap();
sensor.set_current_division_ratio(CurrentDivisionRatio::OneEighth).unwrap();
sensor.set_integration_time(IntegrationTime::_100ms).unwrap();

Structs

MAX44009 ambient light sensor driver.

Enums

Configuration mode

Current division ratio

All possible errors in this crate

Integration time

Measurement mode

Possible slave addresses