Easily monitor the indoor environment-⑪ Obtain the illuminance with Java from BH1750FVI (substitute)-(I2C / Pi4J)-

The simple tool for monitoring environmental information, which was previously introduced in this article, provides illuminance information Texas Instruments SensorTag CC2650. Get it from: //processors.wiki.ti.com/index.php/CC2650_SensorTag_User's_Guide). However, CC2650, which has been known worldwide for a long time as a BLE environment sensor tag, is discontinued, so it will be difficult to obtain it in the future. Therefore, I decided to support another sensor.

This time, ROHM's BH1750FVI was selected as the new illuminance sensor. It's affordable and can be obtained for hundreds of yen.

What is the BH1750FVI sensor?

This sensor can measure illuminance. The interface is I2C, and the I2C address can be either 0x23ʻor0x5c. Also, since there are two I2C buses for Raspberry Pi 3B or 4B, 0 and 1`, you can use up to four BH1750FVIs at the same time with Raspberry Pi 3B or 4B. rainy_bh1750fvi_floor.png

The created BH1750FVI Java library (bh1750fvi-driver) is available on Github. I also wrote the OS and sensor setting procedure. In addition, a simple tool for monitoring environmental information that incorporates this library is available on Github here.

Basic usage of Java library

Here is a simple usage of bh1750fvi-driver. In the sample code below, I2C bus = 1 and address = 0x23 are specified.

import com.pi4j.io.i2c.I2CBus;

import io.github.s5uishida.iot.device.bh1750fvi.driver.BH1750FVIDriver;

public class MyBH1750FVI {
    private static final Logger LOG = LoggerFactory.getLogger(MyBH1750FVI.class);
    
    public static void main(String[] args) {
        BH1750FVIDriver bh1750fvi = null;
        try {
            bh1750fvi = BH1750FVIDriver.getInstance(I2CBus.BUS_1, BH1750FVIDriver.I2C_ADDRESS_23);
            bh1750fvi.open();
                
            while (true) {
                float value = bh1750fvi.getOptical();
                LOG.info("optical:" + value);
                    
                Thread.sleep(10000);
            }
        } catch (InterruptedException e) {
            LOG.warn("caught - {}", e.toString());
        } catch (IOException e) {
            LOG.warn("caught - {}", e.toString());
        } finally {
            if (bh1750fvi != null) {
                bh1750fvi.close();
            }
        }
    }
}

It's simple to use like this. It was created using Pi4J, a Java library for using GPIO of Raspberry Pi.

Finally

A simple tool that incorporates this Java library has the ability to monitor sensor values on the dashboard and send them to the MQTT broker in JSON format.

Finally, the simple tool is available on Github here.

A series of articles

This series consists of the following articles:

  1. Motivation and Concept
  2. Catch Bluetooth LE advertisement signal with Java (Bluetooth LE / bluez-dbus) The related Github is here.
  3. Get temperature / humidity / illuminance etc. from TI SensorTag CC2650 with Java (Bluetooth LE / bluez-dbus) The related Github is here.
  4. Obtain CO2 concentration from MH-Z19B with Java (serial communication / jSerialComm) The related Github is here.
  5. Get PM2.5 concentration from PPD42NS in Java (GPIO / Pi4J) The related Github is here.
  6. Getting operational information of industrial automation equipment in Java (OPC-UA / Eclipse Milo) The related Github is here.
  7. Collect in a simple tool The related Github is here.
  8. Postscript
  9. Get motion detection (HC-SR501 / RCWL-0516) in Java (GPIO / Pi4J) Related Github is here (HC-SR501) and here (RCWL-0516) -0516-driver).
  10. Get temperature / humidity / barometric pressure from BME280 (substitute) in Java (I2C / Pi4J) The related Github is here.
  11. ** Get illuminance in Java from BH1750FVI (substitute) (I2C / Pi4J) (this time) ** The related Github is here.

Recommended Posts

Easily monitor the indoor environment-⑪ Obtain the illuminance with Java from BH1750FVI (substitute)-(I2C / Pi4J)-
Easily monitor the indoor environment-⑤ Obtain PM2.5 concentration from PPD42NS with Java (GPIO / Pi4J)-
Easily monitor the indoor environment-⑩ Obtain temperature / humidity / atmospheric pressure from BME280 (substitute) with Java (I2C / Pi4J)-
Easily monitor the indoor environment-④ Obtain CO2 concentration from MH-Z19B with Java (serial communication / jSerialComm)-
Easily monitor the indoor environment ~ ③ Get temperature / humidity / illuminance etc. from TI SensorTag CC2650 with Java (Bluetooth LE / bluez-dbus) ~
Easily monitor the indoor environment-② Catch the Bluetooth LE advertisement signal with Java (Bluetooth LE / bluez-dbus)-
Easily monitor the indoor environment ~ ⑧ Postscript ~
Easily monitor the indoor environment ~ ⑨ Get motion detection (HC-SR501 / RCWL-0516) in Java (GPIO / Pi4J) ~
Easily monitor the indoor environment- (1) Motivation and concept-
Easily monitor the indoor environment-⑦ Summarize in a simple tool-
Easily monitor the indoor environment-⑥ Acquire operation information of industrial automation equipment in Java (OPC-UA / Eclipse Milo)-
[Java] Set the time from the browser with jsoup
Monitor the internal state of Java programs with Kubernetes
[Note] Create a java environment from scratch with docker
Prepare the environment for java11 and javaFx with Ubuntu 18.4
Find the address class and address type from the IP address with Java
AWS Elastic Beanstalk # 1 with Java starting from scratch-Building a Java web application environment using the EB CLI-