Dust Sensor in Python

Hi, I seriously can use some help! I have purchased a GrovePi and dust sensor for my daughter’s science fair, but I can’t get it to work. I have got to get some data for my daughter to tabulate and really need some help.

I have read through all of the Dexter forums, installed what I believe are the updates to the firmware, but when I try to run the python dust sensor package, I get error messages. Should I delete everything and start over?

Thank you in advance for any help you can provide!

@hallberg.brad,
We’ll help you out getting the dust sensor to work. Can you tell us which image are you using and what all have you tried. Which example did you try running. To which port were you trying to connect the sensor. What all sensors do you have with you. Can you post a few pictures of your setup.

Hi Karan, thank you for the fast follow up! Below is a picture of my setup. I am using a Raspberry Pi 2 with Raspbian Pixel OS. I have the sensor plugged into D8. I do not hear the sensor, or feel a vibration while it is connected (not sure if this is important).

I have followed the advice you have given on other Dexter threads, as well as this current discussion, and updated my GrovePi firmware from GitHub to the current version.

Also, using SSH, I have run a test just his morning and here is what I saw:

BEGIN
pi@raspberrypi:~/Desktop/GrovePi/Software/Python $ sudo python grove_dust_sensor.py
Reading from the dust sensor
0
0
0
END

It appears my sensor is detected by the Pi and getting some reading. I wonder if my Dust Sensor is in the optimal position to collect data?

Thank you so much for your help! If I can get a few reading for my daughter I will be her hero! :slight_smile:

@hallberg.brad,
Can you try using our Raspbian for Robots image, installation guide here. It is based on Raspbian and we have optimized it for our products and for ease of use. Can you run this script and let us know what it shows.

The sensor is an optical sensor you wont hear or see anything when it is working. We’ll try our best to get this working ASAP

Hi Karan, so I got a new SD card and loaded Raspbian for Robots by following the link you provided. I have also updated the entire directory.

Also, I have checked the firmware and got the following response:
pi@dex:~/GrovePi/Software/Python $ sudo python grove_firmware_version_check.py
GrovePi has firmware version: 1.2.7

I attempted to operate the Dust Sensor plugged into GrovePi port D8 and received the following data:
pi@dex:~/GrovePi/Software/Python $ sudo python grove_dust_sensor.py
Reading from the dust sensor
0
0
Error
0
0
0
0

I feel like I should be getting something other than "0’.

Thank you again for helping me along. The science fair data is due this Friday so hopefully we can figure this out and start our collection process.

@hallberg.brad,
I am not really sure what is going wrong with the sensor. When and from where did you buy it from. Can you run the example for ~5 mins and see if the values change.

Can you try rolling back to an older firmware and check if it works for you. Goto this folder on the pi:

GrovePi/Firmware/Source/v1.2/grove_pi_v1_2_2

and run :

avrdude -c gpio -p m328p -U flash:w:grove_pi_v1_2_2.cpp.hex

after this, run the firmware check script to make sure that you are on 1.2.2 and then try the dust sensor example again to see if it works.

Karan, sorry for the long delay! We swithed up the project in order to meet our deadline. But…I have been able to load the older firware you listed and get data. I burned a small sheet of paper to encourage particles. I have not tried to reload the latest firmware to determine if the issue is the firware, or the sensor, but may do so in the future. For now, I need a break! :slight_smile:

@hallberg.brad,
Great to hear that it owrked for you and really sorry that it took this much of a time to get working. Do send us more information if you use the sensors again.

Hi @hallberg.brad,

Make sure you use our latest firmware 1.2.7, if you dont have it then you can run sudo python /home/pi/Desktop/GrovePi/Firmware/firmware_update.sh. Please have your Dust sensor connected to Port D2, it works only on this port and we have changed the documentation here. Thanks a lot for bringing it to our notice, please let us know if this helps.

-Shoban

Hello All,

It seems using Firmware 1.2.7 on the official image for GrovePi still does not work on the Dust Sensor.
I contacted support who told me it would work with the Raspberry Pi and GrovePi+ before I purchased it.
I don’t even get zero values returned when running the line:
sudo python grove_dust_sensor.py

I only get one line printed which is “Reading from the dust sensor”.

No other values have printed on screen in nearly 15 minutes.
I have tried to use both D8 port which documentation said to use, and D2 port which the python code had commented to use. Neither appear to work.

I am using a Raspberry Pi 3 with the newer GrovePi+ board that support Windows IoT. I am using lynux.

I have seen many posts with this issue which all seem to eventually get resolved. But none of their solutions have worked yet. I have spent about 3 hours diagnosing this now with the latest attempt coming up on 20 minutes run time on port D2.

Thank you for your help.

Cheerio,
Cormac

Hi @dctoday,

I’ve also got firmware version 1.2.7 on my GrovePi + Raspberry Pi 3 duo it seems to be working.
Take a look at the following reply I came up from another thread. Is that the script you’re also calling?

Note: Click on the down-looking arrow around the quoted text to see the full answer from that other thread

Thank you!

Hi @RobertLucian,

Thank you for your reply.
Unfortunately it still does not work. Also yes I’m using the default script that’s provided.
I’m baffled at how to proceed? @Shoban, can dexter industries provide any advice please?

Cheerio,
Cormac

May I also add this issue link where it seems the bug tag was removed but the issue never resolved as firmware 1.2.7 is the latest. I just tried updating it there and it confirmed this.

Just to add that when I downgraded the firmware to 1.2.6 I was then getting readings but a lot of zeros would appear among the values when running the default grove_dust_sensor.py script.

Yet no values would loud if trying to run another script I have that pulls data from multiple sensors, so I downgraded to firmware 1.2.5 but alas to no avail.

I have come across this which also seems relevant: GrovePi analog sensors fail with dust sensor [NOT SOLVED]

So it seems this dust sensor has been poorly tested for the GrovePi+ given the level of issues that not only me but the dozens of websites I’ve come across online have detailed.

Hey @dctoday I wanted to hop in here. I setup Raspbian for Robots on a Pi 3, updated the firmware:
~/Dexter/GrovePi/Firmware $ sudo bash firmware_update.sh
and ran the dust sensor example:
~/Dexter/GrovePi/Software/Python $ sudo python grove_dust_sensor.py
and also received normal readings.

image

A few things to double check:

  • This is the example program.
  • The example runs on the D2 port.
  • The example takes only 30 seconds to run.
  • I am using the Grove Dust Sensor. To be clear, that’s part number SEN12291P.

A little more on the dust sensor: it’s labeled PPD42 and here’s a picture
DSC_2534

If you’re sure you’re doing exactly the same thing, using the same sensor I would do the following:

  1. Check that the GrovePi+ is working properly. You can run the command sudo python grove_firmware_version_check.py and you should see a valid firmware version (mine is 1.2.7).
  2. If that works and you get a good response, your GrovePi is fine and it’s a problem with the sensor.
    Contact Seeed for a replacement sensor.

Hi @JohnC,

Thank you for your reply.
I upgraded the firmware back to 1.2.7 and plugged only the Dust Sensor into D2. (We bought multiple so I know the sensor is not faulty)
My readings were then as below which looks much better:
5052
31
260
189
362
302
etc…

The issue it seems is that I had setup all sensors and then ran scripts against each one and then ran a combined script which is failing to give unique results.

My setup:
Raspberry Pi 3 (Model B)
GrovePi+ (Windows IoT Version)
Firmware 1.2.7
Operating System official dexter image fully updated
http://wiki.seeed.cc/Grove-Temperature_and_Humidity_Sensor_Pro/ - Digital – D4

http://wiki.seeed.cc/Grove-Water_Sensor/ - Digital – D3

http://wiki.seeed.cc/Grove-Air_Quality_Sensor_v1.3/ - Analogue – A0

http://wiki.seeed.cc/Grove-Gas_Sensor-MQ2/ - Analogue – A1

http://wiki.seeed.cc/Grove-Gas_Sensor-MQ9/ - Analogue – A2

http://wiki.seeed.cc/Grove-Dust_Sensor/ - Digital – D2

Are you able to replicate my setup and see if you run into the same issues please?

import grovepi
import math
import time
import datetime
import atexit


######################################

# Temperature and Humidity Sensor Pro


def getTemp():

    DHT_Sensor_Port = 4  # Sensor connected to digital port D4
    # Temperature and Humidity Sensor Type
    # Grove Base Kit comes with the blue sensor while we use a white pro sensor.
    blue = 0    # The Blue colored sensor. DHT11
    white = 1   # The White colored Pro sensor. DHT22 (High-precision)

    [temp,humidity] = grovepi.dht(DHT_Sensor_Port,white)  
        
            

    return temp, humidity


######################################

# Water Sensor

def getWater():

    Water_Sensor_Port = 3  # Sensor connected to digital port D3
    grovepi.pinMode(Water_Sensor_Port,"INPUT")
    waterReading = grovepi.digitalRead(Water_Sensor_Port)

    return waterReading

######################################

# Air Quality Sensor v1.3

def getAirQuality():

    Air_Sensor_Port = 0  # Sensor connected to analog port A0
    grovepi.pinMode(Air_Sensor_Port,"INPUT")
    airReading = grovepi.analogRead(Air_Sensor_Port)
    
    return airReading

######################################

# Gas Sensor MQ2 - Combustible Gas, Smoke

def getMQ2():

    MQ2_Sensor_Port = 1  # Sensor connected to analog port A1
    grovepi.pinMode(MQ2_Sensor_Port,"INPUT")
    gasMQ2Reading = grovepi.analogRead(MQ2_Sensor_Port)

    # Calculate gas density - large value means more dense gas
    densityMQ2 = (float)(gasMQ2Reading / 1024)

    return gasMQ2Reading, densityMQ2

######################################

# Gas Sensor MQ9 - Carbon Monoxide, Coal Gas, Liquefied Gas

def getMQ9():

    MQ9_Sensor_Port = 2  # Sensor connected to analog port A2
    grovepi.pinMode(MQ9_Sensor_Port,"INPUT")
    gasMQ9Reading = grovepi.analogRead(MQ9_Sensor_Port)

    # Calculate gas density - large value means more dense gas
    densityMQ9 = (float)(gasMQ9Reading / 1024)

    return gasMQ9Reading, densityMQ9

######################################

# Dust Sensor

def getDust():

    #Dust sensor connected to digital port D2 - the only port it will work with
    atexit.register(grovepi.dust_sensor_dis)
    grovepi.dust_sensor_en()
    # The dust sensor takes 30 seconds to update the new values
    # the fist byte is 1 for a new value and 0 for old values
    # second byte is the concentration in pcs/0.01cf

    [new_val,lowpulseoccupancy] = grovepi.dustSensorRead()

    return new_val, lowpulseoccupancy

######################################


#Read above sensors in loop
while True:

    print ("----------------------")
    
    dateString = '%d/%m/%Y %H:%M:%S'
    print datetime.datetime.now().strftime(dateString)

    #Temperature & Humidity
    [temp,humidity] = getTemp();
    if math.isnan(temp) == False and math.isnan(humidity) == False:
        print("Temperature = %.02fc Humidity = %.02f%%"%(temp, humidity))


    #Water
    water = getWater();
    #print "Water Detected? = ", water

    
    if water == 0:
       print ("Water Sensor Dry")
    elif water == 1:
       print ("Water Detected")
    else:
       print ("Check Water Sensor")


    #Air Quality
    air = getAirQuality();

    if air > 700:
       print ("High pollution")
    elif air > 300:
       print ("Low pollution")
    else:
       print ("Air is fresh")

    print "Air Quality = ", air


    #MQ2 - Combustible Gas, Smoke

    [gasMQ2Reading,densityMQ2] = getMQ2();
    print("MQ2 Reading = %.02f MQ2 Density = %.02f%%"%(gasMQ2Reading, densityMQ2))


    #MQ9 - Carbon Monoxide, Coal Gas, Liquefied Gas

    [gasMQ9Reading,densityMQ9] = getMQ9();
    print("MQ9 Reading = %.02f MQ9 Density = %.02f%%"%(gasMQ9Reading, densityMQ9))


    #Dust

    [new_val,lowpulseoccupancy] = getDust();
    if new_val:
        print(lowpulseoccupancy)

    #Time between sensor readings (seconds)
    time.sleep(10)




We have a PR waiting on this issue.
It may fix what you’re encountering.

I’ll be back with an answer as soon as I get on it.

Thank you!

Hi everyone,

It seems that this issue still isn’t resolved with firmware version 1.2.7. Can anyone give an update on this?

Hi @d_cyphert,

Just saw the PR is still open. We’ll try the following days to approve it and hence bump up the version number.

Though, I have to mention, I never personally had an issue with this sensor - so I never encountered the issue described above.

Thank you!