Ismael Omar
/
completesensor
test
main.cpp@0:2f70df382411, 2015-09-28 (annotated)
- Committer:
- ismaelo
- Date:
- Mon Sep 28 09:32:33 2015 +0000
- Revision:
- 0:2f70df382411
new
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ismaelo | 0:2f70df382411 | 1 | #include "mbed.h" |
ismaelo | 0:2f70df382411 | 2 | #include "TMP006.h" |
ismaelo | 0:2f70df382411 | 3 | |
ismaelo | 0:2f70df382411 | 4 | #define Address 0x80 |
ismaelo | 0:2f70df382411 | 5 | |
ismaelo | 0:2f70df382411 | 6 | // for dust sensor |
ismaelo | 0:2f70df382411 | 7 | DigitalOut myled(LED1); |
ismaelo | 0:2f70df382411 | 8 | DigitalOut ledPower(D8); |
ismaelo | 0:2f70df382411 | 9 | AnalogIn analog_value(p15); |
ismaelo | 0:2f70df382411 | 10 | |
ismaelo | 0:2f70df382411 | 11 | int samplingTime = 280;//280 microseconds |
ismaelo | 0:2f70df382411 | 12 | int deltaTime = 40;//40 us to give total pulse width of 0.32ms |
ismaelo | 0:2f70df382411 | 13 | int sleepTime = 9680;//LED off for 9680 us to take 1 measurement per second |
ismaelo | 0:2f70df382411 | 14 | |
ismaelo | 0:2f70df382411 | 15 | float dustDensityCN = 0,dustDensitySharp = 0, voMeasured=0, voCalc=0; |
ismaelo | 0:2f70df382411 | 16 | |
ismaelo | 0:2f70df382411 | 17 | // end dust sensor |
ismaelo | 0:2f70df382411 | 18 | |
ismaelo | 0:2f70df382411 | 19 | TMP006 sensor(p9, p10, Address); |
ismaelo | 0:2f70df382411 | 20 | |
ismaelo | 0:2f70df382411 | 21 | int main() |
ismaelo | 0:2f70df382411 | 22 | { |
ismaelo | 0:2f70df382411 | 23 | while(1) { |
ismaelo | 0:2f70df382411 | 24 | //printf("ObjTemp: %f \r \n", sensor.readObjTempC(Address)); |
ismaelo | 0:2f70df382411 | 25 | //printf("RawDieTem: %f \r \n", sensor.readRawDieTemperature(Address)); |
ismaelo | 0:2f70df382411 | 26 | printf("DieTemp: %f \r \n", sensor.readDieTempC(Address)); |
ismaelo | 0:2f70df382411 | 27 | |
ismaelo | 0:2f70df382411 | 28 | // dust sensor stuff starts from here |
ismaelo | 0:2f70df382411 | 29 | myled = !myled; |
ismaelo | 0:2f70df382411 | 30 | ledPower=0; // power on the LED. Pull-down to activate |
ismaelo | 0:2f70df382411 | 31 | wait_us(samplingTime); |
ismaelo | 0:2f70df382411 | 32 | voMeasured = analog_value.read(); // Converts and read the analog input value |
ismaelo | 0:2f70df382411 | 33 | wait_us(deltaTime); |
ismaelo | 0:2f70df382411 | 34 | ledPower=1; // turn the LED off. Pull up to turn off |
ismaelo | 0:2f70df382411 | 35 | wait_us(sleepTime); |
ismaelo | 0:2f70df382411 | 36 | |
ismaelo | 0:2f70df382411 | 37 | voCalc = voMeasured*5.0;//Map 0:1 measured range to 0:3.3V |
ismaelo | 0:2f70df382411 | 38 | |
ismaelo | 0:2f70df382411 | 39 | // Original equation taken from Sharp data sheet measured in mg/m3 |
ismaelo | 0:2f70df382411 | 40 | // Sharp don't give you a best fit line, so you have to guess |
ismaelo | 0:2f70df382411 | 41 | dustDensitySharp = 0.5/2.8 * (float(voCalc) - 0.7); |
ismaelo | 0:2f70df382411 | 42 | |
ismaelo | 0:2f70df382411 | 43 | // Eqaution calibrated by Chris Nafis (c) 2012 |
ismaelo | 0:2f70df382411 | 44 | // see http://www.howmuchsnow.com/arduino/airquality/ |
ismaelo | 0:2f70df382411 | 45 | // measured in parts per 0.01 cf |
ismaelo | 0:2f70df382411 | 46 | // [I did not get meaningful values on my sensor with Chris' formula |
ismaelo | 0:2f70df382411 | 47 | // For me the Sharp graph works just fine. So make your own tests] |
ismaelo | 0:2f70df382411 | 48 | //dustDensityCN = (float(voCalc) - 0.0356)*1.2; |
ismaelo | 0:2f70df382411 | 49 | |
ismaelo | 0:2f70df382411 | 50 | printf("Measurment value: %1.3f", voMeasured); |
ismaelo | 0:2f70df382411 | 51 | printf("Voltage calculated: %1.3f", voCalc); |
ismaelo | 0:2f70df382411 | 52 | printf("Dust Density [mg/m3]: %f", dustDensitySharp); |
ismaelo | 0:2f70df382411 | 53 | // printf(" - C. Nafis' Dust Density [pp.01cf](x10^4): %f\n", dustDensityCN,"\n"); |
ismaelo | 0:2f70df382411 | 54 | |
ismaelo | 0:2f70df382411 | 55 | wait(1.0); |
ismaelo | 0:2f70df382411 | 56 | } |
ismaelo | 0:2f70df382411 | 57 | } |