def Gas_NH3(tests, num_test_bytes, write_tests_to_nvm, reset): try: from pimoroni_envirowing import gas if 0 <= gas.read_all().nh3 <= 5: tests["Gas_NH3"]["Passed"] = True print("Passed with", gas.read_all().nh3) else: tests["Gas_NH3"]["Passed"] = False print("Failed") except Exception as e: tests["Gas_NH3"]["Passed"] = False print("Failed with ", e) finally: tests["Gas_NH3"]["Test Run"] = True write_tests_to_nvm(tests, num_test_bytes) reset()
from pimoroni_envirowing import gas import time while True: try: print(gas.read_all()) time.sleep(0.1) finally: gas.cleanup()
max_glyphs=15)) # from https://stackoverflow.com/a/49955617 def human_format(num, round_to=0): magnitude = 0 while abs(num) >= 1000: magnitude += 1 num = round(num / 1000.0, round_to) return '{:.{}f}{}'.format(round(num, round_to), round_to, ['', 'K', 'M', 'G', 'T', 'P'][magnitude]) while True: #take readings reading = gas.read_all() # update the line graph # the value plotted on the graph is the voltage drop over each sensor, not the resistance, as it graphs nicer splotter.update( reading._OX.value * (reading._OX.reference_voltage / 65535), reading._RED.value * (reading._RED.reference_voltage / 65535), reading._NH3.value * (reading._NH3.reference_voltage / 65535)) # update the labels splotter.group[1].text = "OX:{}".format(human_format(reading.oxidising)) splotter.group[2].text = "RED:{}".format(human_format(reading.reducing)) splotter.group[3].text = "NH3:{}".format(human_format(reading.nh3)) time.sleep(interval)
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x76) bme280.sea_level_pressure = 1013.25 softassert.softassert(lambda: -50 <= bme280.temperature <= 50, "Temperature out of expected range") softassert.softassert(lambda: 0 <= bme280.humidity <= 100, "Humidity out of expected range") softassert.softassert(lambda: 850 <= bme280.pressure <= 1100, "Pressure out of expected range") print("BME280 Tests Passed!") #endregion BME280 testing #region Gas Sensor testing softassert.softassert(lambda: 0 <= gas.read_all().oxidising <= 5, "Oxidising gases reading out of expected range") softassert.softassert(lambda: 0 <= gas.read_all().reducing <= 5, "Reducing gases reading out of expected range") softassert.softassert(lambda: 0 <= gas.read_all().nh3 <= 5, "NH3 gases reading out of expected range") print("Gas Sensor Tests Passed!") #endregion Gas Sensor testing #region Light/Prox Sensor testing i2c_dev = not_SMBus(I2C=i2c) ltr559 = LTR559(i2c_dev=i2c_dev) softassert.softassert(lambda: 0 <= ltr559.get_lux() <= 30000, "Lux out of expected range")