Hello guys,
This is my first project with the photon. I am trying to build a totem of pollution for a school around my work place. I am using as sensor :
Shinyei PPD42
Grove Air quality sensor V1.3
Barometer sensor BME280
Sunlight sensor V1
And as shield
Spark battery shield and grove base shield.
The code is taken from the grove website, from the examples for arduino.
Most of the sensor give normal reading but for the past 3 days, I’m not able to make the Air quality sensor working.
Here is my .ino code
#include "AirQuality.h"
#include "application.h"
AirQuality airqualitysensor;
int current_quality =-1;
void setup()
{
Serial.begin(9600);
airqualitysensor.init(14);
}
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); // change this value if you use another A port
// airqualitysensor.counter=0;
// airqualitysensor.timer_index=1;
// PORTB=PORTB^0x20;
// }
// else
// {
// airqualitysensor.counter++;
// }
// }
Does this mean it worked before these three days or that you tried for three days and never got it to work?
BTW, where did you get the library from and how have you included it in your project?
What IDE are you using?
Also how have you wired the sensor and/or Grove Base Shield (which anyway)?
I was never able to make it work.
The libraries are from the official webpage of the sensor
and the wiring is done with the grove cable as in the example. I’ll put a picture soon.
The library needs some corrections and porting to the Particle platform as it uses inconsistend pin usage and also relies on 10bit ADCs while the Photon sports 12bit.
However, this library doesn’t really anything fancy. You should be able to dump it completely and just go with analogRead() and your own range checks.
Something like this, but you can/should omit the pinMode() for analogRead().
And after you got some reference readings (in the range 0…4095) this way you may want to add some categorisation to put the values in a more readable/understanable range:
@E404, Particle.variable() is only declared in setup() once. After that, any changes to that variable will be reflected when the variable is queried through the cloud.
You may want to add a Serial.print() statement to print out the value on a serial console to validate the value as well.
Also another small question from the I2C sensor am i limited to only 4 variables?
Because as you can see i have 2 I2C sensor and when i put both ino codes on one single one then it only outputs 4 variables, even though i have more then data .
I'm not sure what you mean by this. Perhaps showing your entire code would help. I'll have to look at the Grove code to get a sense of what is required.
I guess your Air Quality Sensor is the one stuck under the remote control, right?
If you want to make more than four values available you could use a string variable which contains all your desired values in one string.
But I think the limit of four has been lifted a while ago. I think someone had used 10 somewhere.
You should be able to find out wheter a variable could be registered by checking the return value of the Particle.variable() call. If it returns false it couldn’t be registered anymore (e.g. due to exceeding the limit of possible variables).
But the way you are using it won’t work.
You need to have a global variable to expose as Particle.variable() - things like String(SI1145.ReadVisible())) do not satisfy that demand.
You need a global double or a global String to receive the value in order to expose it to the cloud.
@E404, publish is limited to 1 publish per second or a burst of 4 with a 4 second pause before the next burst. You can publish a string contain the text for all your variables in a single statement instead. For example: