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.
This sensor can measure illuminance. The interface is I2C, and the I2C address can be either 0x23ʻor
0x5c. 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.
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.
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.
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.
This series consists of the following articles:
Recommended Posts