#https://laurentblogs.wordpress.com/2017/01/09/capteur-de-poussieres-et-micropython-partie-1/
U | Mesure ADC | |||||||||
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | |
0.00 | 3 | 3 | 3 | 4 | 3 | 3 | 3 | 3 | 3 | 3 |
0.25 | 86 | 86 | 86 | 86 | 86 | 86 | 86 | 86 | 86 | 86 |
0.50 | 170 | 170 | 170 | 170 | 171 | 170 | 171 | 170 | 170 | 170 |
1.00 | 334 | 334 | 334 | 334 | 334 | 334 | 334 | 334 | 334 | 334 |
1.50 | 502 | 502 | 502 | 502 | 502 | 502 | 502 | 502 | 502 | 502 |
La configuration de l’entrée adc :
import machine
adc = machine.ADC(0)
Lecture du convertisseur :
adc.read()
U(V) | ADC |
0.00 | 3 |
0.25 | 86 |
0.50 | 170 |
0.75 | 254 |
1.00 | 334 |
1.25 | 416 |
1.50 | 502 |
1.75 | 585 |
2.00 | 666 |
2.25 | 750 |
2.50 | 833 |
2.75 | 915 |
3.00 | 1000 |
3.05 | 1017 |
3.06 | 1021 |
3.07 | 1024 |
3.08 | 1024 |
3.09 | 1024 |
3.10 | 1024 |
3.08 | 1024 |
3.09 | 1024 |
3.10 | 1024 |
# 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)
print('Finish.....')