Пример #1
0
    def __init__(self):
        TempSensor.__init__(self)
        self.sleeptime = self.time_step / float(
            config.temperature_average_samples)
        self.bad_count = 0
        self.ok_count = 0
        self.bad_stamp = 0

        if config.max31855:
            log.info("init MAX31855")
            from max31855 import MAX31855, MAX31855Error
            self.thermocouple = MAX31855(config.gpio_sensor_cs,
                                         config.gpio_sensor_clock,
                                         config.gpio_sensor_data,
                                         config.temp_scale)

        if config.max31856:
            log.info("init MAX31856")
            from max31856 import MAX31856
            software_spi = {
                'cs': config.gpio_sensor_cs,
                'clk': config.gpio_sensor_clock,
                'do': config.gpio_sensor_data,
                'di': config.gpio_sensor_di
            }
            self.thermocouple = MAX31856(
                tc_type=config.thermocouple_type,
                software_spi=software_spi,
                units=config.temp_scale,
                ac_freq_50hz=config.ac_freq_50hz,
            )
    def test_get_internal_temperaure_reading(self):
        '''Checks to see if we can read a temperature from the board, using Hardware SPI
        '''
        _logger.debug('test_get_internal_temperature_reading()')
        # Raspberry Pi hardware SPI configuration.
        SPI_PORT = 0
        SPI_DEVICE = 0
        sensor = MAX31856(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))

        temp = sensor.readInternalTempC()

        if temp:
            self.assertTrue(True)
        else:
            self.assertTrue(False)
Пример #3
0
    def test_get_internal_temperaure_reading(self):
        '''Checks to see if we can read a temperature from the board, using Hardware SPI
        '''
        _logger.debug('test_get_internal_temperature_reading()')
        # Raspberry Pi hardware SPI configuration.
        spi_port = 0
        spi_device = 0
        sensor = MAX31856(hardware_spi=SPI.SpiDev(spi_port, spi_device))

        temp = sensor.read_internal_temp_c()

        if temp:
            self.assertTrue(True)
        else:
            self.assertTrue(False)
    def test_hardware_SPI_initialize(self):
        '''Checks to see if the sensor can initialize on the hardware SPI interface.
        
        Will fail if it cannot find the MAX31856 library or any dependencies.
        Test only checks to see that the sensor can be initialized in Software, does not check the hardware connection.
        '''
        _logger.debug('test_hardware_SPI_initialize()')
        # Raspberry Pi hardware SPI configuration.
        SPI_PORT = 0
        SPI_DEVICE = 0
        sensor = MAX31856(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))

        if sensor:
            self.assertTrue(True)
        else:
            self.assertTrue(False)
    def test_get_internal_temperaure_reading_k_type(self):
        """
        Checks to see if we can read a temperature from the board, using Hardware SPI, and K type thermocouple
        """
        _logger.debug('test_get_internal_temperature_reading()')
        # Raspberry Pi hardware SPI configuration.
        spi_port = 0
        spi_device = 0
        sensor = MAX31856(hardware_spi=SPI.SpiDev(spi_port, spi_device),
                          tc_type=MAX31856.MAX31856_K_TYPE)

        temp = sensor.read_internal_temp_c()

        if temp:
            self.assertTrue(True)
        else:
            self.assertTrue(False)
    def test_get_register_reading(self):
        '''Checks to see if we can read a register from the device.  Good test for correct connectivity.
        '''
        _logger.debug('test_get_register_reading()')
        # Raspberry Pi hardware SPI configuration.
        SPI_PORT = 0
        SPI_DEVICE = 0
        sensor = MAX31856(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))

        value = sensor._read_register(MAX31856.MAX31856_REG_READ_CR0)
        for ii in xrange(0x00, 0x10):
            # Read all of the registers, will store data to log
            sensor._read_register(ii)

        if value:
            self.assertTrue(True)
        else:
            self.assertTrue(False)
    def test_hardware_spi_initialize(self):
        """
        Checks to see if the sensor can initialize on the hardware SPI interface.

        Will fail if it cannot find the MAX31856 library or any dependencies.
        Test only checks to see that the sensor can be initialized in Software, does not check the
        hardware connection.
        """
        _logger.debug('test_hardware_SPI_initialize()')
        # Raspberry Pi hardware SPI configuration.
        spi_port = 0
        spi_device = 0
        sensor = MAX31856(hardware_spi=SPI.SpiDev(spi_port, spi_device))

        if sensor:
            self.assertTrue(True)
        else:
            self.assertTrue(False)
Пример #8
0
    def test_get_register_reading(self):
        '''Checks to see if we can read a register from the device.  Good test for correct
        connectivity.
        '''
        _logger.debug('test_get_register_reading()')
        # Raspberry Pi hardware SPI configuration.
        spi_port = 0
        spi_device = 0
        sensor = MAX31856(hardware_spi=SPI.SpiDev(spi_port, spi_device))

        value = sensor._read_register(MAX31856.MAX31856_REG_READ_CR0)
        for ii in range(0x00, 0x10):
            # Read all of the registers, will store data to log
            sensor._read_register(ii)  # pylint: disable-msg=protected-access

        if value:
            self.assertTrue(True)
        else:
            self.assertTrue(False)
Пример #9
0
    def __init__(self):
        TempSensor.__init__(self)
        if config.max31855:
            log.info("init MAX31855")
            from max31855 import MAX31855, MAX31855Error
            self.thermocouple = MAX31855(config.gpio_sensor_cs,
                                         config.gpio_sensor_clock,
                                         config.gpio_sensor_data,
                                         config.temp_scale)

        if config.max31856:
            log.info("init MAX31856")
            from max31856 import MAX31856, MAX31856Error
            software_spi = {
                'cs': config.gpio_sensor_cs,
                'clk': config.gpio_sensor_clock,
                'do': config.gpio_sensor_data
            }
            self.thermocouple = MAX31856(tc_type=config.thermocouple_type,
                                         software_spi=sofware_spi,
                                         units=config.temp_scale)
Пример #10
0
# Test file using ESP8266 with K-type temerature sensor (https://www.adafruit.com/product/270)
#
# Breakout Board: https://www.adafruit.com/product/3263
# Chip Datasheet: https://cdn-learn.adafruit.com/assets/assets/000/035/948/original/MAX31856.pdf
# SPI Tutorial: https://learn.adafruit.com/micropython-hardware-spi-devices?view=all
import machine
import time
import max31856
from max31856 import MAX31856

spi = machine.SPI(1, baudrate=5000000, polarity=0, phase=1)
cs = machine.Pin(15, machine.Pin.OUT)
cs.on()
t = MAX31856(spi, cs)
while True:
    print('Temp: {} C (Junction: {} C)\n'.format(
        t.read_temp_c(),
        t.read_internal_temp_c(),
    ))
    time.sleep_ms(1000)
Пример #11
0
    def test_temperature_byte_conversions(self):
        '''Checks the byte conversion for various known temperature byte values.
        '''
        _logger.debug('test_temperature_byte_conversions()')

        #-------------------------------------------#
        # Test Thermocouple Temperature Conversions #
        byte2 = 0x01
        byte1 = 0x70
        byte0 = 0x20
        decimal_temp = MAX31856._thermocouple_temp_from_bytes(
            byte0, byte1, byte2)  # pylint: disable-msg=protected-access
        self.assertEqual(decimal_temp, 23.0078125)

        # Check a couple values from the datasheet
        byte2 = 0b00000001
        byte1 = 0b10010000
        byte0 = 0b00000000
        decimal_temp = MAX31856._thermocouple_temp_from_bytes(
            byte0, byte1, byte2)  # pylint: disable-msg=protected-access
        self.assertEqual(decimal_temp, 25.0)

        byte2 = 0b00000000
        byte1 = 0b00000000
        byte0 = 0b00000000
        decimal_temp = MAX31856._thermocouple_temp_from_bytes(
            byte0, byte1, byte2)  # pylint: disable-msg=protected-access
        self.assertEqual(decimal_temp, 0.0)

        byte2 = 0b11111111
        byte1 = 0b11110000
        byte0 = 0b00000000
        decimal_temp = MAX31856._thermocouple_temp_from_bytes(
            byte0, byte1, byte2)  # pylint: disable-msg=protected-access
        self.assertEqual(decimal_temp, -1.0)

        byte2 = 0b11110000
        byte1 = 0b01100000
        byte0 = 0b00000000
        decimal_temp = MAX31856._thermocouple_temp_from_bytes(
            byte0, byte1, byte2)  # pylint: disable-msg=protected-access
        self.assertEqual(decimal_temp, -250.0)

        #---------------------------------#
        # Test CJ Temperature Conversions #
        msb = 0x1C
        lsb = 0x64
        decimal_cj_temp = MAX31856._cj_temp_from_bytes(
            msb, lsb)  # pylint: disable-msg=protected-access
        self.assertEqual(decimal_cj_temp, 28.390625)

        # Check a couple values from the datasheet
        msb = 0b01111111
        lsb = 0b11111100
        decimal_cj_temp = MAX31856._cj_temp_from_bytes(
            msb, lsb)  # pylint: disable-msg=protected-access
        self.assertEqual(decimal_cj_temp, 127.984375)

        msb = 0b00011001
        lsb = 0b00000000
        decimal_cj_temp = MAX31856._cj_temp_from_bytes(
            msb, lsb)  # pylint: disable-msg=protected-access
        self.assertEqual(decimal_cj_temp, 25)

        msb = 0b00000000
        lsb = 0b00000000
        decimal_cj_temp = MAX31856._cj_temp_from_bytes(
            msb, lsb)  # pylint: disable-msg=protected-access
        self.assertEqual(decimal_cj_temp, 0)

        msb = 0b11100111
        lsb = 0b00000000
        decimal_cj_temp = MAX31856._cj_temp_from_bytes(
            msb, lsb)  # pylint: disable-msg=protected-access
        self.assertEqual(decimal_cj_temp, -25)

        msb = 0b11001001
        lsb = 0b00000000
        decimal_cj_temp = MAX31856._cj_temp_from_bytes(
            msb, lsb)  # pylint: disable-msg=protected-access
        self.assertEqual(decimal_cj_temp, -55)
    def test_temperature_byte_conversions(self):
        '''Checks the byte conversion for various known temperature byte values.
        '''
        _logger.debug('test_temperature_byte_conversions()')

        #-------------------------------------------#
        # Test Thermocouple Temperature Conversions #
        byte2 = 0x01
        byte1 = 0x70
        byte0 = 0x20
        decimal_temp = MAX31856._thermocoupleTempFromBytes(byte0, byte1, byte2)
        self.assertEqual(decimal_temp, 23.0078125)

        # Check a couple values from the datasheet
        byte2 = 0b00000001
        byte1 = 0b10010000
        byte0 = 0b00000000
        decimal_temp = MAX31856._thermocoupleTempFromBytes(byte0, byte1, byte2)
        self.assertEqual(decimal_temp, 25.0)

        byte2 = 0b00000000
        byte1 = 0b00000000
        byte0 = 0b00000000
        decimal_temp = MAX31856._thermocoupleTempFromBytes(byte0, byte1, byte2)
        self.assertEqual(decimal_temp, 0.0)

        byte2 = 0b11111111
        byte1 = 0b11110000
        byte0 = 0b00000000
        decimal_temp = MAX31856._thermocoupleTempFromBytes(byte0, byte1, byte2)
        self.assertEqual(decimal_temp, -1.0)

        byte2 = 0b11110000
        byte1 = 0b01100000
        byte0 = 0b00000000
        decimal_temp = MAX31856._thermocoupleTempFromBytes(byte0, byte1, byte2)
        self.assertEqual(decimal_temp, -250.0)

        #---------------------------------#
        # Test CJ Temperature Conversions #
        MSB = 0x1C
        LSB = 0x64
        decimal_CJ_temp = MAX31856._cjTempFromBytes(MSB, LSB)
        self.assertEqual(decimal_CJ_temp, 28.390625)

        # Check a couple values from the datasheet
        MSB = 0b01111111
        LSB = 0b11111100
        decimal_CJ_temp = MAX31856._cjTempFromBytes(MSB, LSB)
        self.assertEqual(decimal_CJ_temp, 127.984375)

        MSB = 0b00011001
        LSB = 0b00000000
        decimal_CJ_temp = MAX31856._cjTempFromBytes(MSB, LSB)
        self.assertEqual(decimal_CJ_temp, 25)

        MSB = 0b00000000
        LSB = 0b00000000
        decimal_CJ_temp = MAX31856._cjTempFromBytes(MSB, LSB)
        self.assertEqual(decimal_CJ_temp, 0)

        MSB = 0b11100111
        LSB = 0b00000000
        decimal_CJ_temp = MAX31856._cjTempFromBytes(MSB, LSB)
        self.assertEqual(decimal_CJ_temp, -25)

        MSB = 0b11001001
        LSB = 0b00000000
        decimal_CJ_temp = MAX31856._cjTempFromBytes(MSB, LSB)
        self.assertEqual(decimal_CJ_temp, -55)
Пример #13
0
sensor3_internal = []
sensor3_external = []

# Uncomment one of the blocks of code below to configure your Pi to use software or hardware SPI.

# Raspberry Pi software SPI configuration.
# software_spi = {"clk": 13, "cs": 5, "do": 19, "di": 26}
# sensor = MAX31856(software_spi=software_spi)

# software_spi2 = {"clk": 13, "cs": 6, "do": 19, "di": 26}
# sensor2 = MAX31856(software_spi=software_spi2)

# Raspberry Pi hardware SPI configuration.
SPI_PORT = 0
SPI_DEVICE = 0
sensor = MAX31856(avgsel=2,
                  hardware_spi=Adafruit_GPIO.SPI.SpiDev(SPI_PORT, SPI_DEVICE))

SPI_PORT = 0
SPI_DEVICE = 1
sensor2 = MAX31856(hardware_spi=Adafruit_GPIO.SPI.SpiDev(SPI_PORT, SPI_DEVICE))

sensor3 = MAX31856(software_spi={'clk': 13, 'cs': 5, 'do': 19, 'di': 26})


def write_temp(timestamp, temp, internal, temp2, internal2, temp3, internal3):
    with open("temp.csv", "a") as log:
        log.write("{0},{1!s},{2!s},{3!s},{4!s},{5!s},{6!}\n".format(
            timestamp, temp, internal, temp2, internal2, temp3, internal3))


def graph():