GithubHelp home page GithubHelp logo

eldruin / opt300x-rs Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 1.0 49 KB

Platform-agnostic Rust driver for the OPT300x ambient light sensors.

License: Apache License 2.0

Rust 100.00%
ambient-light-sensor light sensor als i2c rust rust-embedded embedded-hal-driver driver embedded

opt300x-rs's Introduction

Rust OPT300x Ambient Light Sensor (ALS) Driver

crates.io Docs Build Status Coverage Status

This is a platform agnostic Rust driver for the OPT300x ambient light sensor family using the embedded-hal traits.

This driver allows you to:

  • Read the measurement in lux or raw. See: read_lux().
  • Change into continuous measurement mode. See: into_continuous().
  • Read the conversion status. See: read_status().
  • Set the fault count. See: set_fault_count().
  • Set the interrupt pin polarity. See: set_interrupt_pin_polarity().
  • Set the comparison mode. See: set_comparison_mode().
  • Set the low and high limits. See: set_low_limit_raw().
  • Enable and disable end-of-conversion mode. See: enable_end_of_conversion_mode().
  • Get the manufacturer ID. See: get_manufacturer_id().
  • Get the device ID. See: get_device_id().

Introductory blog post

The devices

This driver is compatible with the devices OPT3001, OPT3002, OPT3004, OPT3006 and OPT3007.

The OPT3001 is a sensor that measures the intensity of visible light. The spectral response of the sensor tightly matches the photopic response of the human eye and includes significant infrared rejection.

The OPT3001 is a single-chip lux meter, measuring the intensity of light as visible by the human eye. The precision spectral response and strong IR rejection of the device enables the OPT3001 to accurately meter the intensity of light as seen by the human eye regardless of light source. The strong IR rejection also aids in maintaining high accuracy when industrial design calls for mounting the sensor under dark glass for aesthetics. The OPT3001 is designed for systems that create light-based experiences for humans, and an ideal preferred replacement for photodiodes, photoresistors, or other ambient light sensors with less human eye matching and IR rejection.

Measurements can be made from 0.01 lux up to 83k lux without manually selecting full-scale ranges by using the built-in, full-scale setting feature. This capability allows light measurement over a 23-bit effective dynamic range.

The digital operation is flexible for system integration. Measurements can be either continuous or single-shot. The control and interrupt system features autonomous operation, allowing the processor to sleep while the sensor searches for appropriate wake-up events to report via the interrupt pin. The digital output is reported over an I2C- and SMBus-compatible, two-wire serial interface.

The low power consumption and low power-supply voltage capability of the OPT3001 enhance the battery life of battery-powered systems.

Datasheets:

Application Guide:

Usage

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

In the following example an instance of the device OPT3001 will be created. Other devices can be created with similar methods like: Opt300x::new_opt3002(...).

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

use linux_embedded_hal::I2cdev;
use opt300x::{Opt300x, SlaveAddr};

fn main() {
    let dev = I2cdev::new("/dev/i2c-1").unwrap();
    let address = SlaveAddr::default();
    let sensor = Opt300x::new_opt3001(dev, address);
    let mut sensor = sensor.into_continuous().ok().unwrap();
    loop {
        let lux = sensor.read_lux().unwrap();
        println!("lux: {:2}", lux);
    }
}

Support

For questions, issues, feature requests, and other changes, please file an issue in the github project.

License

Licensed under either of

at your option.

Contributing

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

opt300x-rs's People

Contributors

eldruin avatar madmo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

ardelean-calin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.