My question is, what kind of output does this board use? I'm not sure what the code is doing to determine air quality. It uses the analog pin of the arduino so obviously it's reading an analog voltage, but they are using ISR routines and such to calculate the air quality.
Could someone give me lamens terms of what the code is doing to the analog output of the sensor to determine air quality?
I for one am not going to download unknown code from a repository: you want people to examine it, paste it into the thread or attach it in Additional Options.
So you are saying Github, one of the most widely used and accepted code repositories is going to do something malicious to your computer simply by viewing the code as txt in the web browser?
I'm saying that, if you want people to assist, adhere to the forum's sop of either posting your code inline, or attaching it. You're the one needing the help, not us; help us to help you.
I don't see anything that says I "must" paste all code in the post and not link to a code repository. It says "If you are posting code or error messages, use "code" tags". Since I am not posting code in the thread, I do not need to adhere to this instruction.
Specifically under section 11:
"If you are using a library that does not come with the IDE (in other words, you downloaded it from somewhere) please post a link to this library."
I posted a link to the library, and it's a well known and accepted code repository. You can view the code as plain txt in the web browser. I don't see any problem with my adherence to the rules.
I came across this thread a little while ago looking for some insight into Grove's thinking in the Air Quality Sensor code.
It was a shame to see this unresolved and since it is the first result in my search engine query for Grover Air Quality Arduino Timer I thought I might try and fill in the gaps.
The Air Quality 1.3v code can be found at the SEEED Studio GitHub. First off, in comparison to the GrovePi python equivalent, the original Air Quality Arduino example differs greatly. There is no usage of a timer or different thread in the python code, so the air quality sensor does not require time crucial sampling.
If you download the code via the Arduino IDE you might find you still have the old code (v 1.0.1) timer set in the .cpp file. It is absolutely not required. I get the impression someone at SEEED Studio had just discovered timers and wanted to start messing around with them.
Old AirQuality Sensor Example
#include"AirQuality.h"
#include"Arduino.h"
AirQuality airqualitysensor;
int current_quality =-1;
void setup()
{
Serial.begin(9600);
airqualitysensor.init(A0);
}
void loop()
{
current_quality=airqualitysensor.slope();
if (current_quality >= 0)// if a valid data returned.
{
if (current_quality==0)
Serial.println("High pollution! Force signal active");
else if (current_quality==1)
Serial.println("High pollution!");
else if (current_quality==2)
Serial.println("Low pollution!");
else if (current_quality ==3)
Serial.println("Fresh air");
}
}
ISR(TIMER2_OVF_vect)
{
if(airqualitysensor.counter==122)//set 2 seconds as a detected duty
{
airqualitysensor.last_vol=airqualitysensor.first_vol;
airqualitysensor.first_vol=analogRead(A0);
airqualitysensor.counter=0;
airqualitysensor.timer_index=1;
PORTB=PORTB^0x20;
}
else
{
airqualitysensor.counter++;
}
}
Inside the .cpp file the timers were set in the init() method.
TCCR1A = 0; //normal model
TCCR1B = 0x02; //set clock as 8*(1/16M)
TIMSK1 = 0x01; //enable overflow interrupt
Current Air Quality Sensor Code
#include "Air_Quality_Sensor.h"
AirQualitySensor sensor(A0);
void setup(void) {
Serial.begin(9600);
while (!Serial);
Serial.println("Waiting sensor to init...");
delay(20000);
if (sensor.init()) {
Serial.println("Sensor ready.");
}
else {
Serial.println("Sensor ERROR!");
}
}
void loop(void) {
int quality = sensor.slope();
Serial.print("Sensor value: ");
Serial.println(sensor.getValue());
if (quality == AirQualitySensor::FORCE_SIGNAL) {
Serial.println("High pollution! Force signal active.");
}
else if (quality == AirQualitySensor::HIGH_POLLUTION) {
Serial.println("High pollution!");
}
else if (quality == AirQualitySensor::LOW_POLLUTION) {
Serial.println("Low pollution!");
}
else if (quality == AirQualitySensor::FRESH_AIR) {
Serial.println("Fresh air.");
}
delay(1000);
}
This bears a greater resemblance to the original GrovePi code.
Hopefully that helps anyone else who stumbles across this.
In sum.
No, you don't need to set a ISR for the Grove Air Quality sensor