Use the inexpensive PPD42NS as a sensor to measure PM2.5 concentration. This outputs the detection result as Hi / Lo of digital output, and calculates the PM2.5 concentration by the predetermined formula. In this article, I used Pi4J as a Java GPIO module for Raspberry Pi 3B, and created a Java library [ppd42ns-driver] to obtain PM2.5 concentration from PPD42NS. ](Https://github.com/s5uishida/ppd42ns-driver) is an overview. However, the contents of Github are the same. For implementation details and sample usage, see [Github Code](https://github.com/s5uishida/ppd42ns-driver/blob/master/src/io/github/s5uishida/iot/device/ppd42ns/driver/PPD42NSDriver See .java).
Connect 5V, GND, PM2.5, Tx as follows. You can also refer to here.
Pins
of PPD42NS
Regarding the OS settings, the previous article "Easy monitoring of indoor environment-④ Obtain CO2 concentration from MH-Z19B with Java (serial communication / jSerialComm)- / 1754998f8f706c4c3314) ".
In order to use the Java library Pi4J that operates GPIO of Raspberry Pi 3B, a library called WiringPi is required. Install as follows.
# apt-get update
# apt-get install wiringpi
When using with Raspberry Pi 4B, install the latest version as follows. Please refer to here.
# wget https://project-downloads.drogon.net/wiringpi-latest.deb
# dpkg -i wiringpi-latest.deb
Make sure the version is 2.52.
# gpio -v
gpio version: 2.52
** As of October 2019, we have not confirmed official information on using Raspberry Pi 4B with Pi 4J and Wiring Pi combination. I've confirmed that it works easily, but some problems may occur. ** **
Below is a sample of how to use ppd42ns-driver. ** Note that it takes about 30 seconds for each measurement, so it takes about 30 seconds for the sensor data read ppd42ns.read ()
to return. ** **
import com.pi4j.io.gpio.Pin;
import com.pi4j.io.gpio.RaspiPin;
import io.github.s5uishida.iot.device.ppd42ns.driver.PPD42NSDriver;
import io.github.s5uishida.iot.device.ppd42ns.driver.PPD42NSObservationData;
public class MyPPD42NS {
private static final Logger LOG = LoggerFactory.getLogger(MyPPD42NS.class);
public static void main(String[] args) {
PPD42NSDriver ppd42ns = PPD42NSDriver.getInstance(RaspiPin.GPIO_10);
ppd42ns.open();
while (true) {
try {
PPD42NSObservationData data = ppd42ns.read();
LOG.info("[{}] {}", ppd42ns.getName(), data.toString());
} catch (IOException e) {
LOG.warn("caught - {}", e.toString());
}
}
// if (ppd42ns != null) {
// ppd42ns.close();
// }
}
}
For details of the data returned by ppd42ns.read ()
, see [Class](https://github.com/s5uishida/ppd42ns-driver/blob/master/src/io/github/s5uishida/iot/device/ See ppd42ns / driver / PPD42NSObservationData.java). You can get the concentration of PM2.5 in two units, pcs / 0.01cf
and μg / m ^ 3
.
This series consists of the following articles:
[2019.11.16] For the latest information on simple tools, please refer to here.
Recommended Posts