Skip to content
/ SDS011 Public

Python Interface with Nova Fitness SDS011 sensor, running multiple sensors at once

License

Notifications You must be signed in to change notification settings

binh-bk/SDS011

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SDS011

Python Interface with Nova Fitness SDS011 sensor, running multiple sensors at once. Built from the datasheet

Set up

  • SDS011 (or SDS018) connected with TTL UART adapter (5V)

How to use the script

  1. You connect all the SDS011 sensors to USB hub (via a UART adapter), then you can run all of them at once:
  • first get list of USB devices connected to the hub, and initiate each instance
  usbs = get_usb()
  processs = list()
  for port in usbs:
      p = SDS011(port=port, push_mqtt=False, interval=60)
      processs.append(p)
  • and then run the loop like this:
  while True:
      for p in processs:
          try:
              p.run_passive()
              # p.run_query()
          except Exception as e:
              print(f'Error: {p.name} with {e}')
              continue
  • by default, the data is saved to CSV file in each folder named after month and year
p = SDS011(port=port, save_data=False, interval=60)
  1. If the are different USB devices connected to the computer, then each USB port can be initiated:
p1 = SDS011(port='/dev/ttyUSB1', interval=60)
p2 = SDS011(port='/dev/ttyUSB3', interval=60)

and put them in a loop:

while True:
  for p in [p1, p2]:
    p.run_passive()
  1. There are two modes to collect data, besides active reading a). run_query() is for regularly reading data with fan is continously running, and thus only query data the duration defined by interval and b). run_passive() includes turning on the fan for 20 seconds, read data, and turn off the fan, and repeat cycle after each interval seconds

  2. If you have an MQTT server setup, then you need to specify the topic, routing, and authentication inside sds011/__init__.py file


# MQTT host, users
mqtt = '192.168.1.100'  # change this
topic = 'sensor/sds011' # and this
auth = {'username': 'mqtt_user', 'password': 'mqtt_password'} # and these two

and make sure to turn on the flag when instantiating:

p = SDS011(port=port, push_mqtt=True, interval=60)

Data analysis

  • analyze data by each sensor using different moving average (to smooth out the data)

- or plot PM2.5 and PM10

- or to compare several sensors at one (in which this script is very useful)

- or to simpify by only the mean and standard deviation from multiple sensors

Datasheet

  • Datasheet SDS011 online or in datasheet folder
  • Communication Protocol: check out datasheet folder

About

Python Interface with Nova Fitness SDS011 sensor, running multiple sensors at once

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages