Dust Sesnsor PMS5003

Dependencies:   DustSenzor NetServices ThingSpeakEthernet mbed

Fork of PMS5003 by marko puric

Committer:
mpuric
Date:
Wed Jun 28 18:36:09 2017 +0000
Revision:
14:48368d18a793
Parent:
13:5c98f1d10e70
added api doc

Who changed what in which revision?

UserRevisionLine numberNew contents of line
segundo 0:2419d81ee03d 1 #include "mbed.h"
tsoic 6:ebbde59c5a1d 2 #include "ThingSpeak.h"
mpuric 9:07f9279c30f7 3 #include "TextLCD.h"
mpuric 9:07f9279c30f7 4 #include "DustSenzor.h"
mpuric 9:07f9279c30f7 5
mpuric 9:07f9279c30f7 6 ThingSpeak ts("FI2NZGSOB8LSR8YX");
mpuric 14:48368d18a793 7 DustSenzor ds(p5, p9, p10); // set pin, uartTx pin, Rx pin
mpuric 14:48368d18a793 8 float value[6];
mpuric 14:48368d18a793 9 float finValue[3];
mpuric 14:48368d18a793 10 TextLCD_I2C lcd(&i2c_lcd, 0x7E, TextLCD::LCD16x2);
segundo 0:2419d81ee03d 11
segundo 0:2419d81ee03d 12 int main() {
mpuric 9:07f9279c30f7 13 float *ptr;
mpuric 9:07f9279c30f7 14 ts.connect();
mpuric 9:07f9279c30f7 15 wait(1);
mpuric 9:07f9279c30f7 16 while(1){
mpuric 9:07f9279c30f7 17 float res = ts.pull(282724, 1);
mpuric 9:07f9279c30f7 18 if(res == 1){
mpuric 9:07f9279c30f7 19 ds.start();
mpuric 9:07f9279c30f7 20 }
mpuric 9:07f9279c30f7 21 while( res == 1){
mpuric 9:07f9279c30f7 22 ptr = ds.read();
mpuric 14:48368d18a793 23
mpuric 14:48368d18a793 24 for( int i = 0; i < 6; i++)
mpuric 14:48368d18a793 25 value[i] = *(ptr + i);
mpuric 14:48368d18a793 26
mpuric 14:48368d18a793 27 finValue[0] = ( value[0] - value[2] ); // 0.3 - 1 um / m3
mpuric 14:48368d18a793 28 finValue[1] = ( value[2] - value[4] ); // 1 - 5 um / m3
mpuric 14:48368d18a793 29 finValue[2] = ( value[4] - value[5] ); // 5 - 10 um / m3
mpuric 14:48368d18a793 30
mpuric 14:48368d18a793 31 for ( int j = 0; j < 3; j++ )
mpuric 14:48368d18a793 32 ts.setField( finValue[j], j+1);
mpuric 14:48368d18a793 33
mpuric 9:07f9279c30f7 34 ts.putUp();
mpuric 9:07f9279c30f7 35 wait(15);
mpuric 9:07f9279c30f7 36 res = ts.pull(282724, 1);
mpuric 9:07f9279c30f7 37 }
mpuric 14:48368d18a793 38 ds.stop();
mpuric 9:07f9279c30f7 39 }
mpuric 9:07f9279c30f7 40 }
tsoic 6:ebbde59c5a1d 41