def main(): parser = argparse.ArgumentParser( description= 'HAL component to read ADC values and convert to temperature') parser.add_argument('-n', '--name', help='HAL component name', required=True) parser.add_argument('-i', '--interval', help='Adc update interval', default=0.05) parser.add_argument( '-c', '--channels', help= 'Komma separated list of channels and thermistors to use e.g. 01:semitec_103GT_2,02:epcos_B57560G1104', required=True) parser.add_argument('-f', '--filter_size', help='Size of the low pass filter to use', default=10) parser.add_argument('-b', '--cape_board', help='Type of cape used', default='BeBoPr') parser.add_argument( '-r', '--r_pu', default=2000, type=float, help='Divider pull-up resistor value (default 2k Ohms)') args = parser.parse_args() updateInterval = float(args.interval) filterSize = int(args.filter_size) error = False watchdog = True # Create pins pins = [] if (args.channels != ""): channelsRaw = args.channels.split(',') for channel in channelsRaw: pinRaw = channel.split(':') if (len(pinRaw) != 2): print(("wrong input")) sys.exit(1) pin = Pin() pin.pin = int(pinRaw[0]) if ((pin.pin > 5) or (pin.pin < 0)): print(("Pin not available")) sys.exit(1) checkAdcInput(pin) if (pinRaw[1] != "none"): pin.r2temp = R2Temp(pinRaw[1]) pin.filterSize = filterSize pins.append(pin) # Initialize HAL h = hal.component(args.name) for pin in pins: pin.halRawPin = h.newpin( getHalName(pin) + ".raw", hal.HAL_FLOAT, hal.HAL_OUT) if (pin.r2temp is not None): pin.halValuePin = h.newpin( getHalName(pin) + ".value", hal.HAL_FLOAT, hal.HAL_OUT) halErrorPin = h.newpin("error", hal.HAL_BIT, hal.HAL_OUT) halNoErrorPin = h.newpin("no-error", hal.HAL_BIT, hal.HAL_OUT) halWatchdogPin = h.newpin("watchdog", hal.HAL_BIT, hal.HAL_OUT) h.ready() halErrorPin.value = error halNoErrorPin.value = not error halWatchdogPin.value = watchdog try: while (True): try: for pin in pins: f = open(pin.filename, 'r') value = float(f.readline()) pin.addSample(value) pin.halRawPin.value = pin.rawValue if (pin.r2temp is not None): pin.halValuePin.value = adc2Temp(pin) error = False except IOError: error = True halErrorPin.value = error halNoErrorPin.value = not error watchdog = not watchdog halWatchdogPin.value = watchdog time.sleep(updateInterval) except: print(("exiting HAL component " + args.name)) h.exit()
pins = [] if (args.channels != ""): channelsRaw = args.channels.split(',') for channel in channelsRaw: pinRaw = channel.split(':') if (len(pinRaw) != 2): print(("wrong input")) sys.exit(1) pin = Pin() pin.pin = int(pinRaw[0]) if ((pin.pin > 7) or (pin.pin < 0)): print(("Pin not available")) sys.exit(1) if (pinRaw[1] != "none"): pin.r2temp = R2Temp(pinRaw[1]) pin.filterSize = filterSize pins.append(pin) # Initialize HAL h = hal.component(args.name) for pin in pins: pin.halRawPin = h.newpin(getHalName(pin) + ".raw", hal.HAL_FLOAT, hal.HAL_OUT) if (pin.r2temp is not None): pin.halInputPin = h.newpin(getHalName(pin) + ".input", hal.HAL_U32, hal.HAL_IN) pin.halValuePin = h.newpin(getHalName(pin) + ".value", hal.HAL_FLOAT, hal.HAL_OUT) if (args.ref == 'y'): halRefPin = h.newpin("voltage-ref", hal.HAL_U32, hal.HAL_IN) halErrorPin = h.newpin("error", hal.HAL_BIT, hal.HAL_OUT) halNoErrorPin = h.newpin("no-error", hal.HAL_BIT, hal.HAL_OUT) halWatchdogPin = h.newpin("watchdog", hal.HAL_BIT, hal.HAL_OUT)
def main(): parser = argparse.ArgumentParser( description='HAL component to read Temperature values over I2C') parser.add_argument('-n', '--name', help='HAL component name', required=True) parser.add_argument('-b', '--bus_id', help='I2C bus id', default=2) parser.add_argument('-a', '--address', help='I2C device address', default=0x20) parser.add_argument('-i', '--interval', help='I2C update interval', default=0.05) parser.add_argument( '-c', '--channels', help= 'Comma separated list of channels and thermistors to use e.g. 01:semitec_103GT_2,02:epcos_B57560G1104', required=True) parser.add_argument('-f', '--filter_size', help='Size of the low pass filter to use', default=10) parser.add_argument('-d', '--delay', help='Delay before the i2c should be updated', default=0.0) args = parser.parse_args() updateInterval = float(args.interval) delayInterval = float(args.delay) filterSize = int(args.filter_size) error = True watchdog = True adc = ADS7828(busId=int(args.bus_id), address=int(args.address)) # Create pins pins = [] if (args.channels != ""): channelsRaw = args.channels.split(',') for channel in channelsRaw: pinRaw = channel.split(':') if (len(pinRaw) != 2): print(("wrong input")) sys.exit(1) pin = Pin() pin.pin = int(pinRaw[0]) if ((pin.pin > 7) or (pin.pin < 0)): print(("Pin not available")) sys.exit(1) if (pinRaw[1] != "none"): pin.r2temp = R2Temp(pinRaw[1]) pin.filterSize = filterSize pins.append(pin) # Initialize HAL h = hal.component(args.name) for pin in pins: pin.halRawPin = h.newpin( getHalName(pin) + ".raw", hal.HAL_FLOAT, hal.HAL_OUT) if (pin.r2temp is not None): pin.halValuePin = h.newpin( getHalName(pin) + ".value", hal.HAL_FLOAT, hal.HAL_OUT) halErrorPin = h.newpin("error", hal.HAL_BIT, hal.HAL_OUT) halNoErrorPin = h.newpin("no-error", hal.HAL_BIT, hal.HAL_OUT) halWatchdogPin = h.newpin("watchdog", hal.HAL_BIT, hal.HAL_OUT) h.ready() halErrorPin.value = error halNoErrorPin.value = not error halWatchdogPin.value = watchdog try: time.sleep(delayInterval) while (True): try: for pin in pins: value = float(adc.readChannel(pin.pin)) pin.addSample(value) pin.halRawPin.value = pin.rawValue if (pin.r2temp is not None): pin.halValuePin.value = adc2Temp(pin) error = False except IOError as e: error = True halErrorPin.value = error halNoErrorPin.value = not error watchdog = not watchdog halWatchdogPin.value = watchdog time.sleep(updateInterval) except: print(("exiting HAL component " + args.name)) h.exit()