# ADC : A0
# ILED : D3 / GIPO00
#=====================================================
#// Formulas to to calculate dust by minimum & maximum values.
#// According to specification: min=600mv; max=3520mv
#// using linear function: y = a*x + b;
#// and Fig. 3 Output Voltage vs. Dust Density from specification
#// 0.6 = a*0 + b => b = 0.6
#// 3.52 = a*0.5 + 0.6 => a = (3.52 - 0.6)/0.5 = 5.84
#// y = 5.84*x + 0.6
#//
#// Lets's inverse function, because y is unknown and x is our measured voltage
#//
#// y - 0.6 = 5.84 * x
#// x = (y-0.6)/5.84
#// x = y*1/5.84-0.6/5.84
#// x = 0.171*y - 0.1
#https://laurentblogs.wordpress.com/2017/01/09/capteur-de-poussieres-et-micropython-partie-1/
# ADC : A0
# ILED : D3 / GIPO00
#=====================================================================
from machine import Pin, ADC
import time
p0 = Pin(5, Pin.OUT)
adc = ADC(0)
def measure():
p0.high() # d?but du cr?neau
time.sleep_us(280) # les 0.28 ms
readvalue = adc.read() # lecture de l’adc
time.sleep_us(40) # compl?ment du cr?neau ? 0.32 ms
p0.low() # fin du cr?neau
time.sleep_us(9680) # compl?ment du cycle ? 10 ms
return readvalue
#--------------------------------------
print('PM2.5 Result:')
t,tot,t1=0,0,0
ppm=0.0
t1=measure()
print('Test measure Value : ',t1,'---- this value always too low')
for i in range(10): # on fait 10 mesures
t=measure()
print(i,"---",t)
tot=tot+t
ppm=tot/10
tot2='PM2.5 Value = '+str(ppm)[:5]
print(tot2)
# 0 - 3.3V mapped to 0 - 1023 integer values
# recover voltage
calcVoltage=0.0
calcVoltage = ppm * (3.3 / 1024)
print(' - Voltage: ---- ',calcVoltage)
# linear eqaution taken from http://www.howmuchsnow.com/arduino/airquality/
# Chris Nafis (c) 2012
dustDensity = 0.0
if (calcVoltage < 0.583) :
dustDensity = 0
else:
dustDensity = 6 * calcVoltage / 35 - 0.1 # 6/35 =0.171
print(' - Dust Density: ',dustDensity*1000,' ug/m3 ')
print('Finish.....')
================================================================
$ ampy --port COM13 run PM25-1.py
PM2.5 Result:
Test measure Value : 0 ---- this value always too low
0 --- 1
1 --- 1
2 --- 0
3 --- 0
4 --- 1
5 --- 0
6 --- 0
7 --- 1
8 --- 0
9 --- 0
PM2.5 Value = 0.4
- Voltage: ---- 0.001289062
- Dust Density: 0 ug/m3
Finish.....
alex@alex-PC MINGW64 /d/mini3
$ ampy --port COM13 run PM25-1.py
PM2.5 Result:
Test measure Value : 1024 ---- this value always too low
0 --- 1024
1 --- 1024
2 --- 1024
3 --- 1024
4 --- 1024
5 --- 1024
6 --- 1024
7 --- 1024
8 --- 1024
9 --- 1024
PM2.5 Value = 1024.
- Voltage: ---- 3.299999
- Dust Density: 465.7141 ug/m3
Finish.....
alex@alex-PC MINGW64 /d/mini3
$ ampy --port COM13 run PM25-1.py
PM2.5 Result:
Test measure Value : 3 ---- this value always too low
0 --- 52
1 --- 42
2 --- 79
3 --- 55
4 --- 21
5 --- 62
6 --- 17
7 --- 69
8 --- 53
9 --- 81
PM2.5 Value = 53.09
- Voltage: ---- 0.171123
- Dust Density: 0 ug/m3
Finish.....
alex@alex-PC MINGW64 /d/mini3
$ ampy --port COM13 run PM25-1.py
PM2.5 Result:
Test measure Value : 3 ---- this value always too low
0 --- 301
1 --- 221
2 --- 342
3 --- 269
4 --- 289
5 --- 298
6 --- 188
7 --- 3
8 --- 226
9 --- 219
PM2.5 Value = 235.6
- Voltage: ---- 0.7592576
- Dust Density: 30.15837 ug/m3
Finish.....
沒有留言:
張貼留言