e5fbdd94555edacd32bffb19e81e5508a72d5fd5
1 """Read the MICS6812 via an ads1015 ADC"""
5 import RPi
.GPIO
as GPIO
7 MICS6812_HEATER_PIN
= 24
10 ads1015
.I2C_ADDRESS_DEFAULT
= ads1015
.I2C_ADDRESS_ALTERNATE
14 class Mics6812Reading(object):
15 __slots__
= 'oxidising', 'reducing', 'nh3'
17 def __init__(self
, ox
, red
, nh3
):
23 return """Oxidising: {:05.02f} Ohms
24 Reducing: {:05.02f} Ohms
26 """.format(self
.oxidising
, self
.reducing
, self
.nh3
)
37 adc
= ads1015
.ADS1015(i2c_addr
=0x49)
38 adc
.set_mode('single')
39 adc
.set_programmable_gain(6.148)
40 adc
.set_sample_rate(1600)
42 GPIO
.setwarnings(False)
43 GPIO
.setmode(GPIO
.BCM
)
44 GPIO
.setup(MICS6812_HEATER_PIN
, GPIO
.OUT
)
45 GPIO
.output(MICS6812_HEATER_PIN
, 1)
46 atexit
.register(cleanup
)
50 GPIO
.output(MICS6812_HEATER_PIN
, 0)
54 """Return gas resistence for oxidising, reducing and NH3"""
56 ox
= adc
.get_voltage('in0/gnd')
57 red
= adc
.get_voltage('in1/gnd')
58 nh3
= adc
.get_voltage('in2/gnd')
60 ox
= (ox
* 56000) / (3.3 - ox
)
61 red
= (red
* 56000) / (3.3 - red
)
62 nh3
= (nh3
* 56000) / (3.3 - nh3
)
64 return Mics6812Reading(ox
, red
, nh3
)
68 """Return gas resistance for oxidising gases.
70 Eg chlorine, nitrous oxide
73 return read_all().oxidising
77 """Return gas resistance for reducing gases.
79 Eg hydrogen, carbon monoxide
82 return read_all().reducing
86 """Return gas resistance for nh3/ammonia"""