PMS5003 -- how to use?


#21

Tech Tip. programs like the win32disk imager, can make a backup image of your SD Card. Its just the reverse of flashing an image to it. It will create an image of your card and store it on your PC. Then if you do some other stuff, and screw things up (happens some times ;) ) you don’t have to start all over again from scratch. You just flash the image you saved back to the card. I don’t think etcher can do it though.


#22

I wanted to write a short something on where I am with my project. Thanks to everything above this post, the hardware is working. (Yay!) I’ve plugged in my BME680 sensor as well as the PMS5003 sensor and I’m able to run python programmes that get data coming out of both.

I put together a script that logs the data coming from the BME680 to start with, since that seemed easiest:

import bme680
from time import *

# setting up the sensor
sensor = bme680.BME680()

sensor.set_humidity_oversample(bme680.OS_2X)
sensor.set_pressure_oversample(bme680.OS_4X)
sensor.set_temperature_oversample(bme680.OS_8X)
sensor.set_filter(bme680.FILTER_SIZE_3)
sensor.set_gas_status(bme680.ENABLE_GAS_MEAS)

sensor.set_gas_heater_temperature(320)
sensor.set_gas_heater_duration(150)
sensor.select_gas_heater_profile(0)

with open("data.csv", "a") as log:
    while True:
        sensor.get_sensor_data()
        temp = sensor.data.temperature
        pressure = sensor.data.pressure
        humidity = sensor.data.humidity
        if sensor.data.heat_stable:
            airquality = sensor.data.gas_resistance
            log.write("{0},{1},{2},{3},{4}\n".format(strftime("%Y-%m-%d %H:%M:%S"), str(temp), str(humidity), str(pressure), str(airquality)))
            sleep(1)
        else:
            log.write("{0},{1},{2},{3},NaN\n".format(strftime("%Y-%m-%d %H:%M:%S"), str(temp), str(humidity), str(pressure)))
            sleep(1)

That runs until I CTRL-C out of the programme, at which point I can go an inspect data.csv to see what it measured.

I’m SSHing into a headless version of raspberry pi, but I haven’t figured out how to get the code to run in the background.

I tried python3 script.py&. That runs and gives me a PID number for the process, but when I kill the process I find I have nothing in data.csv. Any idea how to get this working as a background process? At some point I’d like to close out the ssh window / connection and still have the raspberry pi working throughout the day / night etc…

I have another (more complicated) question about the PMS5003 sensor and some code, but I’ll save that for later.


#23

What I do is lunch my python file on boot up via crontab
I run sudo crontab -e from terminal and add the following line at the end of the file.
@reboot python3 /home/pi/myfile.py &
/home/pi is where my file is.