VEML6075 UVA and UVB Light Sensor Driver in Rust

   

Today I present you a platform-agnostic rust driver for the VEML6075 UVA and UVB light sensor.
With this device you can also calculate the UV index.

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: VEML6075
Application note: Designing the VEML6075 into an Application

Using the driver

To use the device from Rust, you have to add the veml6075 crate to your project as well as a concrete implementation of the embedded-hal traits. For example if you are using the Raspberry Pi running Linux (see driver-examples for bare-metal hardware):

1
2
3
4
5
# Cargo.toml
...
[dependencies]
veml6075 = "0.2"
linux-embedded-hal = "0.3"

Here is an example program which will read the UVA, UVB and calculated UV index (source):

1
2
3
4
5
6
7
8
9
10
extern crate linux_embedded_hal as hal;
extern crate veml6075;
use veml6075::{Calibration, Veml6075};

fn main() {
let dev = hal::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);
}

I also created an example program that runs on the STM32F3Discovery board which continuously reads the measurement and prints it on an OLED display. You can find the application source code here.

In the driver-examples repository you can find further examples which you can adapt to do other things with this device.

Where to go from here?

There is much more information and example programs in the crate documentation.
Please give this driver a try and report any issues you may encounter in the issue tracker.
Feedback, suggestions and improvements are gladly welcome.

What’s next?

I have been writing many other platform-agnostic Rust drivers although I am slow to announce them here. If you want to know what I am currently working on you can follow me on github.

Thanks for reading and stay tuned!

Links: Source code - Crate - Documentation

Share