Jump to content
  • 0

MCC 134 gives my negative temp back without any sensor connected


bbfjumper

Question

Hi,

 

as I mentioned in the title i want to read out temperature values and stream it via serial port. The Problem is, that i get for every sensor port, without having a sensor connected, a strange negative value (-127.3...)

 

My code for reading out the sensors is:

import time
from sys import stdout

import serial
import serial.tools.list_ports
from daqhats import HatError, HatIDs, TcTypes, mcc134

from lib.daqhats_utils import select_hat_device

# Constants
CURSOR_BACK_2 = "\x1b[2D"
ERASE_TO_END_OF_LINE = "\x1b[0K"


def read_temp():
    """
    Reads temperature values from multiple channels of an MCC 134 hat device.

    Returns:
        list: A list of temperature values read from each channel.

    Raises:
        HatError: If there is an error with the hat device.
        ValueError: If there is an invalid value.

    """
    # Rest of the code...
    tc_type = TcTypes.TYPE_K  # change this to the desired thermocouple type
    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)

        try:
            temp_values = []
            for channel in channels:
                temp_values.append(hat.t_in_read(channel))

            stdout.flush()
            return temp_values

        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)


def find_serial_port() -> serial.Serial:
    """Find the first available serial port."""
    ports = serial.tools.list_ports.comports()  
    for port in ports:
        if port.description != "n/a":
            return port.device
    raise Exception("No valid serial port found")


def send_floats(floats: list[float]) -> None:
    """Send a list of floats over the specified serial port."""
    # "/dev/ttyAMA0" is the default serial port on Raspberry Pi
    with serial.Serial("/dev/ttyAMA0", 9600, timeout=1) as ser:
        for f in floats:
            ser.write(f"{f:.2f};".encode())
            print(f"sent: {f}")
        ser.write(b"\n")


if __name__ == "__main__":
    try:
        while True:
            send_floats(read_temp())
            time.sleep(2)
    except KeyboardInterrupt:
        print("\nExiting...")



Would be great if someone could help me or maybe have/had the same issue.

 

BR

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Hello @bbfjumper.

Please connect a thermocouple wire to the analog input terminals (CH#H and CH#L). Use the MCC DAQ HAT Manager to read the thermocouple channel.  What is the reading?  Test each channel option with a thermocouple via the MCC DAQ HAT Manager's channel selection for the MCC 134. Do any of the available channel selections in the application read the correct temperature?

Regards,

Fausto

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...