9b213edadaad87b0ff5e7d7bb1f378ef3da76274
1 """Read the MICS6812 via an ads1015 ADC"""
4 import RPi
.GPIO
as GPIO
9 ads1015
.I2C_ADDRESS_DEFAULT
= ads1015
.I2C_ADDRESS_ALTERNATE
13 class Mics6812Reading(object):
14 __slots__
= 'oxidising', 'reducing', 'nh3'
16 def __init__(self
, ox
, red
, nh3
):
22 return """Oxidising: {:05.02f}
25 """.format(self
.oxidising
, self
.reducing
, self
.nh3
)
36 adc
= ads1015
.ADS1015(i2c_addr
=0x49)
37 adc
.set_mode('single')
38 adc
.set_programmable_gain(6.148)
39 adc
.set_sample_rate(1600)
41 GPIO
.setwarnings(False)
42 GPIO
.setmode(GPIO
.BCM
)
43 GPIO
.setup(MICS6812_EN_PIN
, GPIO
.OUT
)
44 GPIO
.output(MICS6812_EN_PIN
, 1)
48 ox
= adc
.get_voltage('in0/gnd')
49 red
= adc
.get_voltage('in1/gnd')
50 nh3
= adc
.get_voltage('in2/gnd')
52 ox
= (ox
* 56000) / (3.3 - ox
)
53 red
= (red
* 56000) / (3.3 - red
)
54 nh3
= (nh3
* 56000) / (3.3 - nh3
)
56 return Mics6812Reading(ox
, red
, nh3
)
60 """Return gas resistance for oxidising gases.
62 Eg chlorine, nitrous oxide
65 return read_all().oxidising
69 """Return gas resistance for reducing gases.
71 Eg hydrogen, carbon monoxide
74 return read_all().reducing
78 """Return gas resistance for nh3/ammonia"""