There are several places in recent firmware versions where there is debugging/testing code for the Grove dust sensor. My line numbers are in 1.2.7 as it is the most recent.
There is an "attachInterrupt" called on line 70 that gets called on startup. This is only supposed to be called when the Dust Sensor enable command (14) is sent:
void setup()
{
// Serial.begin(38400); // start serial for output
Wire.begin(SLAVE_ADDRESS);
Wire.onReceive(receiveData);
Wire.onRequest(sendData);
attachInterrupt(0,readPulseDust,CHANGE);
}
There are also two "digitalWrite" calls on lines 658 and 665. These shouldn't be here at all, they would make port D8 unusable when the Dust Sensor is used.
void readPulseDust()
{
t = millis();
l_status = digitalRead(2); // Represents if the line is low or high.
if(l_status)
{
digitalWrite(8,0);
// If the line is high (1), the pulse just ended
pulse_end = t;
}
else
{ // If the line is low (0), the pulse just started
pulse_start = t;
digitalWrite(8,1);
}
if(pulse_end > pulse_start)
{
duration = pulse_end - pulse_start;
lowpulseoccupancy = lowpulseoccupancy+duration; // Add to the pulse length.
pulse_end = 0; // If you don't reset this, you'll keep adding the pulse length over and over.
}
}
Found this by having a temperature sensor plugged into D2 and an LED plugged into D8. Polling the temperature sensor caused the LED to blink.
There are several places in recent firmware versions where there is debugging/testing code for the Grove dust sensor. My line numbers are in 1.2.7 as it is the most recent.
There is an "attachInterrupt" called on line 70 that gets called on startup. This is only supposed to be called when the Dust Sensor enable command (14) is sent:
There are also two "digitalWrite" calls on lines 658 and 665. These shouldn't be here at all, they would make port D8 unusable when the Dust Sensor is used.
Found this by having a temperature sensor plugged into D2 and an LED plugged into D8. Polling the temperature sensor caused the LED to blink.