GrovePi analog sensors fail with dust sensor [NOT SOLVED]

M2, I’m ready to do what you just did. I wonder if you can run just the Dust Sensor, solo (no other sensors used in the code). That would be very telling.

@M2 @bigbuilder: The dust sensor returns values only once every 30 seconds or longer, other wise it just returns 0. If the first number is 1, that indicates that the there is a new value coming from the dust sensor. Can you try this out and see if it’s any better: https://github.com/karan259/GrovePi/blob/master/Software/Python/grove_dust_sensor.py . You should run it for a couple of minutes. Right now it returns low pulse occupancy in the last 30 seconds. There is a forumla to find the concentration from the low pulse occupancy. If the low pulse occupancy works well, I’ll add the code for finding the concentration.

Do you get a lot of nan’s with the dust sensor. Can you post the output with a couple of nan’s and the data before and after it.

-Karan

Just to clarify what Karan said: the dust sensor itself, the actual sensor, will only return values about once every 30 seconds. It varies. But if you want to know more about this, please check the datasheet, linked above int he comments. You’re not being limited by the GrovePi or the Pi, but the dust sensor.

@karan, @John. We appreciate all your work on this. However, I just want to point out that since the update to the new firmware, using the program Karan posted above, this is all I get:

Reading from the dust sensor
0
0
0
0
0
0
0
0
Error
0
0

This goes on for hours… only the dust sensor program is running. It ran all night, and in the morning… still 0…

@karan, I don’t get any nans, just zeroes. As for the Air Quality, and the DHT, I do get nans, but no more 'random" stuff, but I need to test them some more. However, I think your other code fixes took care of the other two sensors. Thank You! I plan on downgrading the firmware tomorrow, and see if I get back my old values to make sure I didn’t break the dust sensor. I will let you know as soon as I get a chance to do that.

@bigbuilder: The GrovePi worked great for me when I had just a barometer sensor hooked up. Ran for weeks recording to an SQLite database. But, I was hoping to get a dust sensor, temp & humidity, and air quality all going at once. Is that what you are working on?

Thank you everyone for working on this.

update:

Downgraded firmware to 1.2.4: Sensor is back to where it was: Sample output from grove_dust_sensor from main repository:
Reading from the dust sensor
10297
17062
62
Error
62
14445
62

Sample output from https://github.com/karan259/GrovePi/blob/master/Software/Python/grove_dust_sensor.py:
Reading from the dust sensor
6074
62
62
Error
62

So, there is something odd with the 1.2.5 firmware that disables the dust sensor on my system. If I use 1.2.5, the dust sensor output is always 0 as stated in previous post.

@karan, I am using the older GrovePi, not the newer GrovePi+. Is that why we are getting different results? I’ve looked back through all the postings, and I don’t see any mention that this makes a different. I bought two a very long time ago. The one I have been testing seems to upgrade to the newer firmwares just fine.

So, my setup is:
Raspberry Pi 2 Model B V1.1 (software fully updated)
GrovePi (I don’t see a version number on it, but mine looks like this image: http://www.dexterindustries.com/wp-content/uploads/2014/01/fw_upload.jpg)
Dust Sensor: PPD42 (this one: http://www.seeedstudio.com/depot/Grove-Dust-Sensor-p-1050.html)
DHT Sensor: Temp&Humidity Sensor Pro version 1.2
Air Quality: Version 1.2

Software: I have several directories. One directory I cloned github.com/karan259/GrovePi/ and I also have a directory for the normal GrovePi repository. But the main repository does not have the newer firmware, nor the update to grovepi.py. Is this correct? I have updated the grovepi.py in the main repository before running tests. I have been testing both locations…

Any suggestions? If I have misunderstood a previous post, please let me know.

Thanks for all your help.

Hey,
Which port are you connecting the dust sensor to? It only works when it’s connected to port D2.

-Karan

Karan, don’t you mean it only works when connected to D8?

Or did you change that in your new firmware?

@karan, what?!?

According to the wiki here:
http://www.seeedstudio.com/wiki/Grove_-_Dust_sensor

port D8 must be used.

Also, in the file grove_dust_sensor.py, line 38, it says Port 8 only.
In the file you sent here: https://github.com/karan259/GrovePi/blob/master/Software/Python/grove_dust_sensor.py it says Port 8?

Are all 3 places of documentation wrong? I have been using Port D8. Are you sure port D2 is correct?

Hey Guys,
Sorry for the confusion. I ended up rewriting the whole thing from scratch to make it work without causing unnecessary delays in the code.

How Seeed does it with the their Arduino code is that they use the pulseIn() function to measure the length when the pulse from the sensor goes low. This works only on D8 port but the problem with this is that everything pauses on the firmware when pulseIn() is running which can be from 10ms to 500ms or more.

How we ended up using it was with the D2 port on the GrovePi. We can assign the D2 port to look for interrups like change in pin state and write an ISR to do some calculations. So when the pin goes low, we just save a timestamp and when it goes it we save the timestamp. With this we calculate the length of the low pullse occupancy signal from the CO2 sensor. The advantage of this approach is that it only takes a few microseconds to do the calculation, but we had to write it from scratch. You can check out the code and compare it with the Seeed code to see the difference: https://github.com/karan259/GrovePi/blob/master/Firmware/Source/v1.2/grove_pi_v1_2_5/grove_pi_v1_2_5.ino#L544-L568 and https://github.com/karan259/GrovePi/blob/master/Firmware/Source/v1.2/grove_pi_v1_2_5/grove_pi_v1_2_5.ino#L708-L730.

I have tested the pulse duration but testing it with a logic analyzer to see if both the software and the logic analyzer report the same length and they do, but I have just tested it on the sensor that I have so it would be great if you guys can test and let me know if you face any problems.

Sorry for the confusion. I’ll update the docs on the python code so that it says the same.

Hope that this helps.

-Karan

@Karan, thanks for update, and all the work you are putting in this.

I updated to 1.2.5 again and ran the program https://github.com/karan259/GrovePi/blob/master/Software/Python/grove_dust_sensor.py

Here are the results:
Reading from the dust sensor
3060750
97
172
1568
329
151
170
0
171
117
361
0
79
0
235

If I understand what you had said before, this “returns low pulse occupancy in the last 30 seconds”. So we still need to convert this to concentration, correct?

I am curious though, are you seeing such difference in values with your sensor?

And just to make sure we are on the same page, I can just clone your repository here: https://github.com/karan259/GrovePi/ and that should contain the update to firmware, grovepi.py, and grove_dust_sensor.py, correct?

Hey M2,
Looks like the sensor is indeed returning values. Everything looks correct. Can you run the grove_firmware_version_check.py to make sure that you are running 1.2.5.

You will have to calculate the conc from the lowoccupancy values. The wiki here: http://www.seeedstudio.com/wiki/Grove_-_Dust_sensor shows how you calculate the conc: ratio = lowpulseoccupancy/(sampletime_ms*10.0); // Integer percentage 0=>100 concentration = 1.1*pow(ratio,3)-3.8*pow(ratio,2)+520*ratio+0.62; // using spec sheet curve

I think the first value looks a bit odd but other looks fine. The values on my sensor look a bit more consistent.
Reading from the dust sensor
10416
1782
2481
1864
2141
2224
1146
2291
1642
1311

I think the best thing to do would be plot it over a few hours and see how good it is.

-Karan

Hi everyone I’m feeling like a total NOOB. Anyway - have been following this thread and what I can gather is the reason my Dust Sensor isn’t giving me any values is the same reason as many on this thread. To solve it seems

  1. Upgrade to 1.2.5 firmware
  2. Connect to D2 rather than D8
  3. Try again

I’m using a RPI B.
Where I’m stuck is the firmware piece. I successfully upgraded to 1.2.2 using the auto scripts and went to Karan’s

however when I followed the commands to get ino installed when I run
sudo ino init -t grovepi

I get the following errors:
Traceback (most recent call last):
File “/usr/local/bin/ino”, line 6, in <module>
main()
File “/usr/local/lib/python2.7/dist-packages/ino/runner.py”, line 76, in main
args.func(args)
File “/usr/local/lib/python2.7/dist-packages/ino/commands/init.py”, line 46, in run
‘.’, ignore=lambda *args: [‘manifest.ini’])
File “/usr/local/lib/python2.7/dist-packages/ino/commands/init.py”, line 56, in copytree
names = os.listdir(src)
OSError: [Errno 2] No such file or directory: ‘/usr/local/lib/python2.7/dist-packages/ino/templates/grovepi’

Is there another way to get version 1.2.5 firmware onto my GrovePi so that I can test the interrupt driven version in order to get my dust sensor working? Any assistance appreciated.

Thanks

JP

@pieater

I turn off the pi, connect a jumper as shown here:
http://www.dexterindustries.com/GrovePi/get-started-with-the-grovepi/updating-firmware/

Turn it back on, change to the v1_2_5 directory, then run the following command.

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

However, you may want to wait to hear from karan to be sure.

As for the D2 versus the D8, that only is needed if you are using the repository from karan.

@karan: I have been using your new firmware, and code, and now have 4 sensors going at once, but I do have to have a delay of at least a minute between each one. I still get the occasional 0, IOError, or other mishap, but when I record them to a database, they seem to overall pretty good. I have not calibrated the dust sensor yet… but when I’m done, I will keep the thread updated.

Hmm

I must have done something wrong - I have the GrovePi+ which ‘appears’ not to need the jumper. Following the instructions I now get the following error with version check:

pi@dex ~/Desktop/GrovePi/Software/Python $ sudo python grove_firmware_version_check.py
Traceback (most recent call last):
File “grove_firmware_version_check.py”, line 40, in <module>
print (“GrovePi has firmware version:”, grovepi.version())
File “/home/pi/Desktop/GrovePi/Software/Python/grovepi.py”, line 258, in version
return “%s.%s.%s” % (number[1], number[2], number[3])
TypeError: ‘int’ object has no attribute ‘getitem

I ftp’ed the grove_pi_v1_2_5.cpp.hex file to the right directory and ran the:

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

command… I’ll go back and re-follow all the firmware upgrade instructions… Thanks in advance though.

Tried to run this command to clone a copy of the firmware locally:

sudo git clone https://github.com/DexterInd/GrovePi/tree/master/Firmware/Source/v1.2/grove_pi_v1_2_5

thinking then I’d go and execute the flash command from there, however got the following error:

Cloning into ‘grove_pi_v1_2_5’…
error: The requested URL returned error: 403 while accessing https://github.com/DexterInd/GrovePi/tree/master/Firmware/Source/v1.2/grove_pi_v1_2_5/info/refs
fatal: HTTP request failed

hmmm

Can you try cloning the whole repo: sudo git clone https://github.com/DexterInd/GrovePi.git. I don;'t think it’s possible to clone a portion of the repo.

-Karan

Thanks for the reply. However just managed to upgrade to 1.2.5, simply went to the following folder:

/home/pi/Desktop/GrovePi/Firmware/Source/v1.2/grove_pi_v1_2_5

ran this command

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

and checked - all good. Thanks now testing the dust sensor.

So far just getting readings of zero

@pieater: which port did you use? D2 or D8? Also, as @HumanCell talked about before, there is a “correct” orientation that seemed to help mine be more consistent. It needs to be facing up, which makes no sense without a picture, so in the cases of mine, I have it orientated so that the wires coming out of the sensor are pointing down. So, the sensor I am using is being help up in the air with a paperclip until I get a chance to 3D print something to hold it. :slight_smile:

FYI: I am using the original GrovePi, and the sensor I am using is a PPD42

Thanks for that I did have the orientation so that the writing on the motherboard was the right way up and the leads were on the bottom.
I tried the other orientation just in case.
I’m using a GrovePi+ with a RPI B and I was testing on D8 but tried D2 anyway, also yes I am using the PPD42 grove dust sensor.

I’ll keep testing.