-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathe2e_adc.py
54 lines (38 loc) · 1.28 KB
/
e2e_adc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from time import sleep
import math
import Adafruit_ADS1x15
import Adafruit_DHT
'''
This is an end to end communication channel of the Raspberry Pi with the Adafruit's ADS1015 ***12-bit*** ADC.
Environmental sensors used are the:
DHT22
-> Digital communication directly with Pi
Kipp and Zonen PAR sensor
-> Millivolt output read by ADC
'''
#static variable
GAIN = 16
PAR_SENSITIVITY = 0.00000457
COLLECTION_INTERVAL = 2
PAR_PIN = 0
DHT_PIN = 22
#setup
dht = Adafruit_DHT.DHT22
adc = Adafruit_ADS1x15.ADS1015()
ADC_SENSITIVITY = math.pow(2,11)
#adc = Adafruit_ADS1x15.ADS1115()
#ADC_SENSITIVITY = math.pow(2,15)
print "Starting reads from PAR sensor"
print 'Reading every {:d} seconds...'.format(COLLECTION_INTERVAL)
while True:
par_readout = adc.read_adc(PAR_PIN, gain=GAIN)
print "par_readout: {:d}".format(par_readout)
#we turn a digital read back to a voltage
adc_voltage_range = 4.096 / GAIN
par_voltage = par_readout * (adc_voltage_range / ADC_SENSITIVITY)
print "par_voltage {:0.1f}".format( par_voltage)
irridance = par_voltage / PAR_SENSITIVITY
print "IRRIDANCE: {:0.1f}".format(irridance)
humidity, temperature = Adafruit_DHT.read_retry(dht, DHT_PIN)
print 'Temperature: {:0.1f}*C, Humidity: {:0.1f}%'.format(temperature, humidity)
sleep(COLLECTION_INTERVAL)