def main(): # Attach gas sensor to Analog A0 sensor = upmGAS.MQ7(0) ## Exit handlers ## # This function stops python from printing a stacktrace when you hit control-C def SIGINTHandler(signum, frame): raise SystemExit # This function lets you run code on exit, including functions from sensor def exitHandler(): print "Exiting" sys.exit(0) # Register exit handlers atexit.register(exitHandler) signal.signal(signal.SIGINT, SIGINTHandler) threshContext = upmGAS.thresholdContext() threshContext.averageReading = 0 threshContext.runningAverage = 0 threshContext.averagedOver = 2 # Infinite loop, ends when script is cancelled # Repeatedly, take a sample every 2 microseconds; # find the average of 128 samples; and # print a running graph of asteriskss as averages mybuffer = upmGAS.uint16Array(128) while(1): samplelen = sensor.getSampledWindow(2, 128, mybuffer) if samplelen: thresh = sensor.findThreshold(threshContext, 30, mybuffer, samplelen) sensor.printGraph(threshContext, 5)
def __init__(self, refresh=1, port=1, averageReading=0, runningAverage=0, averagedOver=2, *args, **kwargs): super(GasSensor, self).__init__(refresh=refresh, *args, **kwargs) self.upm_sensor = gas.MQ5(port) self.threshContext = gas.thresholdContext() self.threshContext.averageReading = averageReading self.threshContext.runningAverage = runningAverage self.threshContext.averagedOver = averagedOver self.buffer = gas.uint16Array(128)
def fMq2(): # From # https://github.com/intel-iot-devkit/upm/blob/master/examples/python/mq2.py thisMq2 = upmGas.MQ2(0); threshContext = upmGas.thresholdContext() threshContext.averageReading = 0 threshContext.runningAverage = 0 threshContext.averagedOver = 2 thisbuffer = upmGas.uint16Array(128) while True: samplelen = thisMq2.getSampledWindow(2, 128, thisbuffer) if samplelen: thresh = thisMq2.findThreshold(threshContext, 30, thisbuffer, samplelen) #thisMq2.printGraph(threshContext, 5) if(thresh): print("MQ2 Threshold: ", thresh) time.sleep(1)
def fMq2(): # From # https://github.com/intel-iot-devkit/upm/blob/master/examples/python/mq2.py thisMq2 = upmGas.MQ2(0) threshContext = upmGas.thresholdContext() threshContext.averageReading = 0 threshContext.runningAverage = 0 threshContext.averagedOver = 2 thisbuffer = upmGas.uint16Array(128) while True: samplelen = thisMq2.getSampledWindow(2, 128, thisbuffer) if samplelen: thresh = thisMq2.findThreshold(threshContext, 30, thisbuffer, samplelen) #thisMq2.printGraph(threshContext, 5) if (thresh): print("MQ2 Threshold: ", thresh) time.sleep(1)
def SIGINTHandler(signum, frame): raise SystemExit # This function lets you run code on exit, including functions from myMQ9 def exitHandler(): print "Exiting" sys.exit(0) # Register exit handlers atexit.register(exitHandler) signal.signal(signal.SIGINT, SIGINTHandler) threshContext = upmGas.thresholdContext() threshContext.averageReading = 0 threshContext.runningAverage = 0 threshContext.averagedOver = 2 # Infinite loop, ends when script is cancelled # Repeatedly, take a sample every 2 microseconds; # find the average of 128 samples; and # print a running graph of dots as averages mybuffer = upmGas.uint16Array(128) while(1): samplelen = myMQ9.getSampledWindow(2, 128, mybuffer) if samplelen: thresh = myMQ9.findThreshold(threshContext, 30, mybuffer, samplelen) myMQ9.printGraph(threshContext, 5) if(thresh): print "Threshold is ", thresh
raise SystemExit # This function lets you run code on exit, including functions from myMQ9 def exitHandler(): print "Exiting" sys.exit(0) # Register exit handlers atexit.register(exitHandler) signal.signal(signal.SIGINT, SIGINTHandler) threshContext = upmGas.thresholdContext() threshContext.averageReading = 0 threshContext.runningAverage = 0 threshContext.averagedOver = 2 # Infinite loop, ends when script is cancelled # Repeatedly, take a sample every 2 microseconds; # find the average of 128 samples; and # print a running graph of dots as averages mybuffer = upmGas.uint16Array(128) while (1): samplelen = myMQ9.getSampledWindow(2, 128, mybuffer) if samplelen: thresh = myMQ9.findThreshold(threshContext, 30, mybuffer, samplelen) myMQ9.printGraph(threshContext, 5) if (thresh): print "Threshold is ", thresh
def SIGINTHandler(signum, frame): raise SystemExit # This function lets you run code on exit, including functions from sensor def exitHandler(): print "Exiting" sys.exit(0) # Register exit handlers atexit.register(exitHandler) signal.signal(signal.SIGINT, SIGINTHandler) threshContext = upmGAS.thresholdContext() threshContext.averageReading = 0 threshContext.runningAverage = 0 threshContext.averagedOver = 2 # Infinite loop, ends when script is cancelled # Repeatedly, take a sample every 2 microseconds; # find the average of 128 samples; and # print a running graph of asteriskss as averages mybuffer = upmGAS.uint16Array(128) while(1): samplelen = sensor.getSampledWindow(2, 128, mybuffer) if samplelen: thresh = sensor.findThreshold(threshContext, 30, mybuffer, samplelen) sensor.printGraph(threshContext, 5) # if(thresh): # print "Threshold is ", thresh