Dust sensor problems


#1

Goodmorning!

as a newbie python programmer i want to tinker with my pi2 with a grovepi+ attached and the Grove Dust sensor. I installed the needed software for the grovepi+. Doing sudo i2cdetect -y 1 gives

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- 04 -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         

(i have more sensors installed (and will install more) but want tot start with the dust sensor)

When i run grove_dust_sensor.py i get indentation errors… why and how do i solve this? I am using Python 2.7.9.
When i run grove_firmware_version_check.py i get the following:

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

Please help!

Scoobie


#2

Hi,
Can you first check the version of the firmware on the GrovePi by running:
sudo python ~/Desktop/GrovePi/Software/Python/grove_firmware_version_check.py. If you get v1.2.5, you are good. If not go to GrovePi/Firmware/Source/v1.2/grove_pi_v1_2_5 folder and run avrdude -c gpio -p m328p -U flash:w:grove_pi_v1_2_5.cpp.hex, then check the firmware version again and then try the example again.

-Karan


#3

Karan,

thank you for replying!

I tried the grove firmware check but got this error again:

Traceback (most recent call last):
File “/home/pi/Desktop/GrovePi/Software/Python/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

So i tried you’re second option and did the update. That went well (safemode: Fuses and no errors).
I tried the the firmware check again and got the same result back as before.

I’m no python expert but i read the error as if grovepi.py has a python error in it’s code. I can’t imagine that such would be true. Here the results form Python 2.7.9 and

Python 2.7.9 (default, Mar 8 2015, 00:52:26) [GCC 4.9.2] on linux2 Type "copyright", "credits" or "license()" for more information. >>> ================================ RESTART ================================ >>>

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

and

Python 3.4.2 (default, Oct 19 2014, 13:31:11) [GCC 4.9.1] on linux Type "copyright", "credits" or "license()" for more information. >>> ================================ RESTART ================================ >>> Traceback (most recent call last): File "/home/pi/Desktop/GrovePi/Software/Python/grove_firmware_version_check.py", line 37, in <module> import grovepi File "/home/pi/Desktop/GrovePi/Software/Python/grovepi.py", line 530 print data_back ^ SyntaxError: Missing parentheses in call to 'print' >>>

What am i doing wrong?

Thank’s for the help!

Scoobie


#4

I resolved the first part of my problem.

I removed the grovepi+ from the pi. Then i removed two other sensors from the grovepi so that just the dust sensor remained. I then replaced the grovepi+ on the pi and started up agian.

When i now run ‘grove_firmware_version_check.py’ it says without any error: (‘GrovePi has firmware version:’, ‘1.2.5’).

So when i run grove_dust_sensor.py now, i still get a Tab/space error: Inconsistent indentation detected. When i try to change this file (Select All and untabify region) it seems the folder permissions deny me to save the file. So i saved the file elsewhere and executed.

It runs ok but the readings are not:

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

and so on. Any thoughts anyone?

Thanks!


#5

Are you running this example and is the dust sensor connected to port 8. Is there anything else connected to the GrovePi or the Raspberry Pi and can you run this for a couple of minutes to see if it gives you a good reading.

-karan


#6

Hi Karan,

yes is use port 8 as it is required (sampling).
I have the gas sensor (mq9) attached and that one is running.

I left the code run for a while and it started to give actual readings :))

I added an extra print line in the original code:

import time
import grovepi
import atexit

atexit.register(grovepi.dust_sensor_dis)

print &quot;Reading from the dust sensor&quot;
grovepi.dust_sensor_en()
while True:
    try:
        [new_val,lowpulseoccupancy] = grovepi.dustSensorRead()
        if new_val:
            print lowpulseoccupancy
            print grovepi.dustSensorRead()
        time.sleep(5) 

    except IOError:
        print (&quot;Error&quot;)

This gives me:

0
[0, 16729088]
0
[0, 16727808]
Error
16727808
[1, 0]
16728320
[1, 0]
16728320
[1, 0]
16729088
[0, 16777215]
16728576
[0, 16777215]

These readings look strange to me. As i understand, the first bit is an indicator for a new value and the rest should be the measurement. In the first few readings, the first bit is 0 but it did measure a value (the part after the comma).
Then when the first bit is an 1, the reading after the comma differs from the one in the lowpulseoccupancy printline. How come?

Are the readings above anything like a normal reading? For when i take a peek at seeeds, i see readings like 350.00 pcs per 0.01cf. Those readings look nothing like the readings i do?

Thanks for any help!

Scoobs