$USD
  • EUR€
  • £GBP
  • $USD
PROJECTS Arduino

Android Things Driver for BH1750 Ambient Light Sensor

DFRobot Sep 04 2018 505

This driver supports ROHM BH1750 ambient light sensor.
 

 

Things used in this project

Hardware components

Technexion PICO-IMX7

DFRobot BH1750

Pimoni Rainbow HAT 

Servo Module(Generic)

Software apps and online services

Google Android Things

 

Story

BH1750 Driver for Android Things

This driver supports ROHM BH1750 ambient light sensor.

NOTE: These drivers are not production-ready. They are offered as sample implementations of Android Things user space drivers for common peripherals as part of the Developer Preview release. There is no guarantee of correctness, completeness, or robustness.

How to Use the Driver

Gradle Dependency

To use the bh3750 driver, simply add the line below to your project's build.gradle, where <version> matches the last version of the driver available on jcenter.

dependencies {   compile 'com.alvarowolfx.androidthings:driver-bh3750:<version>' }

Sample Usage

import com.alvarowolfx.androidthings.driver.bh3750.Bh3750; // Access the ambient light sensor: Bh3750 mBh3750; try {   mBh3750 = new Bh3750(i2cBusName); } catch (IOException e) {   // couldn't configure the device... } // Read the current light level: try {   float lightLevel = mBh3750.readLightLevel(); } catch (IOException e) {   // error reading light level } // Close the ambient light sensor when finished: try {   mBh3750.close(); } catch (IOException e) {   // error closing sensor

If you need to read sensor values continuously, you can register the BH1750 with the system and listen for sensor values using the Sensor APIs:

SensorManager mSensorManager = getSystemService(Context.SENSOR_SERVICE); SensorEventListener mListener = ...; Bh3750SensorDriver mSensorDriver; mSensorManager.registerDynamicSensorCallback(new SensorManager.DynamicSensorCallback() {   @Override   public void onDynamicSensorConnected(Sensor sensor) {       if (sensor.getType() == Sensor.TYPE_LIGHT) {           mSensorManager.registerListener(mListener, sensor,                   SensorManager.SENSOR_DELAY_NORMAL);       }   } }); try {   mSensorDriver = new Bh3750SensorDriver(i2cBusName);   mSensorDriver.registerLightSensor(); } catch (IOException e) {   // Error configuring sensor } // Unregister and close the driver when finished: mSensorManager.unregisterListener(mListener); mSensorDriver.unregisterLightSensor(); try {   mSensorDriver.close(); } catch (IOException e) {   // error closing sensor }

Sample Project
 

A sample project using the Android Things kit with iMX7D and Rainbow HAT. Basically shows the value of the light sensor on the alphanumeric display, addressable LEDs, and move a servo motor according to the actual value.

 

Schematic


 


 


REVIEW