Example #1
0
def index2():
    #address = select_hat_device(HatIDs.MCC_134)
    mylist = hat_list(filter_by_id=HatIDs.MCC_134)
    address = mylist[1].address

    hat = mcc134(address)
    tc_type = TcTypes.TYPE_K  # change this to the desired thermocouple type
    delay_between_reads = 1  # Seconds
    channels = (0, 1, 2, 3)

    lib = cdll.LoadLibrary('/usr/local/lib/liblifepo4wered.so')

    for channel in channels:
        hat.tc_type_write(channel, tc_type)

    tempZero = str("{:.2f}".format((hat.t_in_read(0) * 1.8) + 32))
    tempOne = str("{:.2f}".format((hat.t_in_read(1) * 1.8) + 32))
    tempTwo = str("{:.2f}".format((hat.t_in_read(2) * 1.8) + 32))
    tempThree = str("{:.2f}".format((hat.t_in_read(3) * 1.8) + 32))

    vbat = str(lib.read_lifepo4wered(10))

    return jsonify(temp1=tempZero,
                   temp2=tempOne,
                   temp3=tempTwo,
                   temp4=tempThree,
                   BatteryVoltage=vbat)
Example #2
0
    def open_device(self, address):
        """ Open selected device """
        try:
            self.board = mcc134(address)

        except HatError:
            return False
        else:
            return True
Example #3
0
    def openDevice(self, address):
        try:
            self.board = mcc134(address)

        except:
            raise
            return False
        else:
            return True
Example #4
0
def start_stop_click(n_clicks, button_label, hat_descriptor_json_str,
                     active_channels, tc_type0, tc_type1, tc_type2, tc_type3):
    """
    A callback function to change the application status when the Configure,
    Start or Stop button is clicked.

    Args:
        n_clicks (int): Number of button clicks - triggers the callback.
        button_label (str): The current label on the button.
        hat_descriptor_json_str (str): A string representation of a JSON object
            containing the descriptor for the selected MCC 134 DAQ HAT.
        active_channels ([int]): A list of integers corresponding to the user
            selected Active channel checkboxes.
        tc_type0 (TcTypes): The selected TC Type for channel 0.
        tc_type1 (TcTypes): The selected TC Type for channel 0.
        tc_type2 (TcTypes): The selected TC Type for channel 0.
        tc_type3 (TcTypes): The selected TC Type for channel 0.

    Returns:
        str: The new application status - "idle", "configured", "running"
        or "error"

    """
    output = 'idle'
    if n_clicks is not None and n_clicks > 0:
        output = 'error'
        if button_label == 'Configure':
            # If configuring, create the hat object.
            if hat_descriptor_json_str:
                hat_descriptor = json.loads(hat_descriptor_json_str)
                # The hat object is retained as a global for use in
                # other callbacks.
                global _HAT  # pylint: disable=global-statement
                _HAT = mcc134(hat_descriptor['address'])

                if active_channels:
                    # Set the TC type for all active channels to the selected TC
                    # type prior to acquiring data.
                    tc_types = [tc_type0, tc_type1, tc_type2, tc_type3]
                    for channel in active_channels:
                        _HAT.tc_type_write(channel, tc_types[channel])
                    output = 'configured'
        elif button_label == 'Start':
            output = 'running'
        elif button_label == 'Stop':
            output = 'idle'

    return output
Example #5
0
def main():
    """ Main function """
    log_period = 5 * 60
    channel = 0
    tc_type = TcTypes.TYPE_T

    if KEY == "<my_key>":
        print("The default key must be changed to the user's personal IFTTT "
              "Webhooks key before using this example.")
        sys.exit()

    # Find the first MCC 134
    mylist = hat_list(filter_by_id=HatIDs.MCC_134)
    if not mylist:
        print("No MCC 134 boards found")
        sys.exit()

    board = mcc134(mylist[0].address)

    # Configure the thermocouple type on the desired channel
    board.tc_type_write(channel, tc_type)

    # Set library update interval to a longer time since we are not reading
    # often.
    if log_period > 255:
        board.update_interval_write(60)
    else:
        board.update_interval_write(log_period)

    print("Logging temperatures, Ctrl-C to exit.")

    while True:
        # read the temperature
        temperature = board.t_in_read(channel)

        # check for errors
        if temperature == mcc134.OPEN_TC_VALUE:
            temp_val = "Open"
        elif temperature == mcc134.OVERRANGE_TC_VALUE:
            temp_val = "Overrange"
        elif temperature == mcc134.COMMON_MODE_TC_VALUE:
            temp_val = "Common mode"
        else:
            temp_val = "{:.2f}".format(temperature)

        send_trigger(EVENT_NAME, temp_val)

        time.sleep(log_period)
Example #6
0
 def initBoard(self):
     # Try to initialize the device
     try:
         self.board = mcc134(0)
         
         serial = self.board.serial()
         self.serial_number.set(serial)
         
         for channel in range(mcc134.info().NUM_AI_CHANNELS):
             self.board.tc_type_write(channel, TcTypes.TYPE_T)
             
         self.ready_led.set(1)
         self.device_open = True
     except:
         self.software_errors += 1
         self.current_failures += 1
Example #7
0
    def __init__(self, conn, ip, port):
        Thread.__init__(self)
        self._stop_event = Event()
        self.ip = ip
        self.port = port
        self.conn = conn
        self.hat = mcc172(0)
	try:
            self.temp = mcc134(1)
        except:
            self.temp = None

        try:
            self.sht20 = SHT20(1, 0x40)
        except:
            self.sht20 = None

        print "[+] New thread started for "+ip+":"+str(port)
            log("Failed to connect to internet... will try again soon.")
            time.sleep(5.0)

# Tell the world that we've booted and how to connect over ssh.  To login, use:
# ssh [email protected], where xxx.xxx.xxx is the MAC address from the tweet.
sendTweet("Booted with MAC address " + findMacAddress())

# Find the MCC 134
hats = hat_list(filter_by_id=HatIDs.MCC_134)
if not hats:
    sendTweet('No MCC 134 found, quiting')
    sys.exit()
else:
    log('Found MCC134')

board = mcc134(hats[0].address)

# Configure the thermocouple type on the channel 0
board.tc_type_write(channel, tc_type)

# Create new joke instance
weeklyJoke = Joke()

while True:
    weeklyJoke.printJokeMondayAtNoon()
    error = True
    temperature = board.t_in_read(channel)
    if temperature == mcc134.OPEN_TC_VALUE:
        tweet = "Error - Open"
    elif temperature == mcc134.OVERRANGE_TC_VALUE:
        tweet = "Error - Over range"
# Create the DMM instrument
dmm = gpib.DMM()
# Create the DP8200 instrument
dp8200 = gpib.DP8200()

# drive to 0V during initialization in order to settle analog inputs
dp8200.set_voltage(0)

if len(sys.argv) > 1:
    # get board address
    board_num = int(sys.argv[1])
else:
    board_num = 0

# Create an instance of the board
board = hats.mcc134(board_num)
print "Serial " + board.serial()
num_channels = len(channels)  #board.info().NUM_AI_CHANNELS

# display the cal coefficients

for channel in channels:  #range(num_channels):
    coef = board.calibration_coefficient_read(channel)
    #print(coef)
    print("  Ch {0} slope: {1} offset: {2}".format(channel, coef.slope,
                                                   coef.offset))

print("Initializing...")

# Modify these for the specific test
num_averages = 10
def main():
    """
    This function is executed automatically when the module is run directly.
    """
    tc_type = TcTypes.TYPE_J  # change this to the desired thermocouple type
    delay_between_reads = 1  # Seconds
    channels = (0, 1, 2, 3)

    try:
        # Get an instance of the selected hat device object.
        address = select_hat_device(HatIDs.MCC_134)
        hat = mcc134(address)

        for channel in channels:
            hat.tc_type_write(channel, tc_type)

        print('\nMCC 134 single data value read example')
        print('    Function demonstrated: mcc134.t_in_read')
        print('    Channels: ' +
              ', '.join(str(channel) for channel in channels))
        print('    Thermocouple type: ' + tc_type_to_string(tc_type))
        try:
            input("\nPress 'Enter' to continue")
        except (NameError, SyntaxError):
            pass

        print('\nAcquiring data ... Press Ctrl-C to abort')

        # Display the header row for the data table.
        print('\n  Sample', end='')
        for channel in channels:
            print('     Channel', channel, end='')
        print('')

        try:
            samples_per_channel = 0
            while True:
                # Display the updated samples per channel count
                samples_per_channel += 1
                print('\r{:8d}'.format(samples_per_channel), end='')

                # Read a single value from each selected channel.
                for channel in channels:
                    value = hat.t_in_read(channel)
                    if value == mcc134.OPEN_TC_VALUE:
                        print('     Open     ', end='')
                    elif value == mcc134.OVERRANGE_TC_VALUE:
                        print('     OverRange', end='')
                    elif value == mcc134.COMMON_MODE_TC_VALUE:
                        print('   Common Mode', end='')
                    else:
                        print('{:12.2f} C'.format(value), end='')

                stdout.flush()

                # Wait the specified interval between reads.
                sleep(delay_between_reads)

        except KeyboardInterrupt:
            # Clear the '^C' from the display.
            print(CURSOR_BACK_2, ERASE_TO_END_OF_LINE, '\n')

    except (HatError, ValueError) as error:
        print('\n', error)
Example #11
0
num_channels = 4
slopes = [0.0] * num_channels
offsets = [0.0] * num_channels
inv_lsb_size = (2 ** 24)/ (2 * 0.078125)
#zero_code = 2048

print("Initializing...")

# Create the DMM instrument
dmm = gpib.DMM()
# Create the DP8200 instrument
dp8200 = gpib.DP8200()

# Create an instance of the board
board = hats.mcc134(int(address))

# configure the channels
for channel in range(4):
    board.tc_type_write(channel, hats.TcTypes.TYPE_J)

num_averages = 10
num_points = 3
min_voltage = -0.070
max_voltage = 0.070
output_path = "calibrate_134.csv"
voltage_step = (max_voltage - min_voltage) / (num_points - 1)

output_file = open(output_path, "w")
str = datetime.datetime.now().isoformat() + "\n"
output_file.write(str)
except (OSError, serial.SerialException) as e:
    print("Problem setting up the OMRON sensors", e)
    exit()

# set up connection to Graphite database
sock = socket.socket()
sock.connect((GRAPHITE_IP, GRAPHITE_PORT))
starttime = time.time()

# configure the thermocouple
# type e
tc_type = daqhats.TcTypes.TYPE_E
delay_between_read = 60  # in seconds
channels = (0, 1)  # of four possible
tc_address = daqhats.hat_list(filter_by_id=daqhats.HatIDs.MCC_134)[0].address
tc_hat = daqhats.mcc134(tc_address)
try:
    for channel in channels:
        tc_hat.tc_type_write(channel, tc_type)
except (HatError, ValueError) as e:
    print("\n", e)
    exit()

db = ([])
ii = 0
while True:
    ####
    #### OMRON 2JCIE BU01 environmental sensor
    ####
    # loop over two sensors
    # update OMRON readings
Example #13
0
def main():
    """ Main function """

    if KEY == "<my_key>":
        print("The default key must be changed to the user's personal IFTTT "
              "Webhooks key before using this example.")
        sys.exit()

    # Find the first MCC 134
    mylist = hat_list(filter_by_id=HatIDs.MCC_134)
    if not mylist:
        print("No MCC 134 boards found")
        sys.exit()

    board = mcc134(mylist[0].address)

    # Configure for type T thermocouple
    board.tc_type_write(CHANNEL, TcTypes.TYPE_T)

    # Read and display current temperature
    temperature = board.t_in_read(CHANNEL)
    print("Current temperature: {:.2f}.".format(temperature))
    print("Monitoring temperature, Ctrl-C to exit. ")

    alarm_set = False
    error_value = 0.0

    while True:
        # read the temperature
        temperature = board.t_in_read(CHANNEL)

        # check for errors
        if temperature == mcc134.OPEN_TC_VALUE:
            if error_value != temperature:
                error_value = temperature
                send_trigger(EVENT_NAME, "{:.0f}".format(temperature),
                             "{:.2f}".format(CLEAR_THRESHOLD),
                             "Open thermocouple")
                print("Open thermocouple.")
        elif temperature == mcc134.OVERRANGE_TC_VALUE:
            if error_value != temperature:
                error_value = temperature
                send_trigger(EVENT_NAME, "{:.0f}".format(temperature),
                             "{:.2f}".format(CLEAR_THRESHOLD), "Overrange")
                print("Overrange.")
        elif temperature == mcc134.COMMON_MODE_TC_VALUE:
            if error_value != temperature:
                error_value = temperature
                send_trigger(EVENT_NAME, "{:.0f}".format(temperature),
                             "{:.2f}".format(CLEAR_THRESHOLD),
                             "Common mode error")
                print("Common mode error.")
        else:
            # compare against the thresholds; change the logic if using falling
            # temperature alarm
            if alarm_set:
                if ((ALARM_RISING and (temperature < CLEAR_THRESHOLD)) or
                    (not ALARM_RISING and (temperature > CLEAR_THRESHOLD))):
                    # we crossed the clear threshold, send a trigger
                    alarm_set = False
                    send_trigger(EVENT_NAME, "{:.2f}".format(temperature),
                                 "{:.2f}".format(CLEAR_THRESHOLD), "cleared")
                    print("Temp: {:.2f}, alarm cleared.".format(temperature))
            else:
                if ((ALARM_RISING and (temperature >= ALARM_THRESHOLD)) or
                    (not ALARM_RISING and (temperature <= ALARM_THRESHOLD))):
                    # we crossed the alarm threshold, send a trigger
                    alarm_set = True
                    send_trigger(EVENT_NAME, "{:.2f}".format(temperature),
                                 "{:.2f}".format(ALARM_THRESHOLD), "set")
                    print("Temp: {:.2f}, alarm set.".format(temperature))

        time.sleep(1)