Skip to main content

Python3 Driver for SPS30 PM Sensor

Project description

SPS30 PM Sensor Driver for Python3

Dependencies

Only smbus2 other than Python.

Installation

pip3 install sps30

Usage

from sps30 import SPS30

sps = SPS30()

if sps.read_article_code() == sps.ARTICLE_CODE_ERROR:
    raise Exception("ARTICLE CODE CRC ERROR!")

if sps.read_device_serial() == sps.SERIAL_NUMBER_ERROR:
    raise Exception("SERIAL NUMBER CRC ERROR!")

sps.set_auto_cleaning_interval(seconds) # default 604800, set 0 to disable auto-cleaning

sps.device_reset() # device has to be powered-down or reset to check new auto-cleaning interval

if sps.read_auto_cleaning_interval() == sps.AUTO_CLN_INTERVAL_ERROR: # or returns the interval in seconds
    raise Exception("AUTO-CLEANING INTERVAL CRC ERROR!")

sps.start_measurement()

while not sps.read_data_ready_flag():
    print("New Measurement is not available!")
    if sps.read_data_ready_flag() == sps.DATA_READY_FLAG_ERROR:
        raise Exception("DATA-READY FLAG CRC ERROR!")

pm_value = sps.read_measured_values()

if pm_value == sps.MEASURED_VALUES_ERROR:
    raise Exception("MEASURED VALUES CRC ERROR!")
else:
    print ("PM2.5 Value in µg/m3: " + str(pm_value))

sps.stop_measurement()

sps.start_fan_cleaning() # enables fan-cleaning manually for 10 seconds (referred by datasheet)

TODO

For now, read_measured_values() method returns only PM2.5 value. All of other sensor values will be added ASAP.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

sps30-0.1-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

Details for the file sps30-0.1-py3-none-any.whl.

File metadata

  • Download URL: sps30-0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.3

File hashes

Hashes for sps30-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 510f32b9a6a976a44bf206e29d99580962a04c833664a7ecc0fb49e6f16c7599
MD5 592018c80ee9b5dd1b9669f02c687e8e
BLAKE2b-256 da34ba090a31fe28dcc20641c7c47cdfd949dd0a9e326700f5a5a89ca773245b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page