Easily monitor the indoor environment-⑩ Obtain temperature / humidity / atmospheric pressure from BME280 (substitute) with Java (I2C / Pi4J)-

Previously introduced in this article, the simple tool for monitoring environmental information provides temperature, humidity, and barometric pressure information Texas Instruments. Obtained from SensorTag CC2650. 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.

There are many temperature and humidity sensors in the world, and I honestly wonder which one to choose. Just then, I found helpful information, and as a result, Bosch's BME280 You have selected .com / products / environmental-sensors / humidity-sensors-bme280 /). It's affordable and can be obtained for hundreds of yen.

What is the BME280 sensor?

This sensor can measure temperature, humidity and barometric pressure. In addition, temperature seems to be mainly used to correct the measured value of atmospheric pressure, but since it is a good idea, the value itself is also used. The interface supports I2C and SPI, but I2C is used here. The I2C address can be either 0x76ʻor 0x77. Also, since there are two I2C buses for Raspberry Pi 3B or 4B, 0 and 1`, you can use up to four BME280s at the same time with Raspberry Pi 3B or 4B. rainy_bme280_floor.png

The created BME280 Java library (bme280-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 bme280-driver. In the sample code below, I2C bus = 1 and address = 0x76 are specified.

import com.pi4j.io.i2c.I2CBus;

import io.github.s5uishida.iot.device.bme280.driver.BME280Driver;

public class MyBME280 {
    private static final Logger LOG = LoggerFactory.getLogger(MyBME280.class);
    
    public static void main(String[] args) {
        BME280Driver bme280 = null;
        try {
            bme280 = BME280Driver.getInstance(I2CBus.BUS_1, BME280Driver.I2C_ADDRESS_76);
            bme280.open();
            
            while (true) {
                float[] values = bme280.getSensorValues();
                LOG.info("temperature:" + values[0]);
                LOG.info("humidity:" + values[1]);
                LOG.info("pressure:" + values[2]);
                
                Thread.sleep(10000);
            }
        } catch (InterruptedException e) {
            LOG.warn("caught - {}", e.toString());
        } catch (IOException e) {
            LOG.warn("caught - {}", e.toString());
        } finally {
            if (bme280 != null) {
                bme280.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 each sensor value on the dashboard and the ability to send it 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) (this time) ** The related Github is here.
  11. Get illuminance from BH1750FVI (substitute) in Java (I2C / Pi4J) The related Github is here.

Recommended Posts

Easily monitor the indoor environment-⑩ Obtain temperature / humidity / atmospheric pressure from BME280 (substitute) with Java (I2C / Pi4J)-
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 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 ~ ⑨ Get motion detection (HC-SR501 / RCWL-0516) in Java (GPIO / Pi4J) ~
Easily monitor the indoor environment ~ ⑧ Postscript ~
Easily monitor the indoor environment- (1) Motivation and concept-
Read temperature / humidity with Java from Raspberry Pi 3 & DHT11
Read barometric pressure and temperature with Java from Raspberry Pi 3 & BMP180
Easily monitor the indoor environment-⑥ Acquire operation information of industrial automation equipment in Java (OPC-UA / Eclipse Milo)-