Crate veml6075

Source
Expand description

This is a platform agnostic Rust driver for the VEML6075 UVA and UVB light sensor, based on the embedded-hal traits.

This driver allows you to:

Introductory blog post

§The device

The VEML6075 senses UVA and UVB light and incorporates photodiode, amplifiers,and analog / digital circuits into a single chip using a CMOS process. When the UV sensor is applied, it is able to detect UVA and UVB intensity to provide a measure of the signal strength as well as allowing for UVI measurement. The VEML6075 provides excellent temperature compensation capability for keeping the output stable under changing temperature. VEML6075’s functionality is easily operated via the simple command format of I2C (SMBus compatible) interface protocol. VEML6075’s operating voltage ranges from 1.7 V to 3.6 V.

Datasheet:

Application note:

§Usage examples (see also examples folder)

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

§Read calibrated UVA, UVB and UV index

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

use linux_embedded_hal::I2cdev;
use veml6075::{Calibration, Veml6075};

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = Veml6075::new(dev, Calibration::default());
let m = sensor.read().unwrap();
println!("UVA: {:2}, UVB: {:2}, UVI: {:2}", m.uva, m.uvb, m.uv_index);

§Set integration time to 400ms

use linux_embedded_hal::I2cdev;
use veml6075::{Calibration, IntegrationTime, Veml6075};

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = Veml6075::new(dev, Calibration::default());
sensor.set_integration_time(IntegrationTime::Ms400).unwrap();

§Set high dynamic setting

use linux_embedded_hal::I2cdev;
use veml6075::{Calibration, DynamicSetting, Veml6075};

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = Veml6075::new(dev, Calibration::default());
sensor.set_dynamic_setting(DynamicSetting::High).unwrap();

§Change mode to active force (one-shot) and trigger a measurement

use linux_embedded_hal::I2cdev;
use veml6075::{Calibration, Mode, Veml6075};

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = Veml6075::new(dev, Calibration::default());
sensor.set_mode(Mode::ActiveForce).unwrap();
loop {
    sensor.trigger_measurement().unwrap();
    // wait until measurement is ready (integration time)
    let m = sensor.read().unwrap();
    println!("Measurements UVA: {:2}, UVB: {:2}", m.uva, m.uvb);
}

§Read raw measurements for UVA and UVB

use linux_embedded_hal::I2cdev;
use veml6075::{Calibration, Veml6075};

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = Veml6075::new(dev, Calibration::default());
let uva = sensor.read_uva_raw().unwrap();
let uvb = sensor.read_uvb_raw().unwrap();
println!("Measurements UVA: {}, UVB: {}", uva, uvb);

Structs§

Enums§