Commit 2430973a authored by Pedro Henrique Kopper's avatar Pedro Henrique Kopper

Implement thermocouple

parent 9a5bf9fd
This diff is collapsed.
* @file Adafruit_MAX31856.h
* This is the documentation for Adafruit's MAX31856 driver for the
* Arduino platform. It is designed specifically to work with the
* Adafruit MAX31856 breakout:
* These sensors use SPI to communicate, 4 pins are required to
* interface with the breakout.
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
* Written by ladyada for Adafruit Industries.
* BSD license, all text here must be included in any redistribution.
#ifndef ADAFRUIT_MAX31856_H
#define ADAFRUIT_MAX31856_H
#define MAX31856_CR0_REG 0x00 ///< Config 0 register
#define MAX31856_CR0_AUTOCONVERT 0x80 ///< Config 0 Auto convert flag
#define MAX31856_CR0_1SHOT 0x40 ///< Config 0 one shot convert flag
#define MAX31856_CR0_OCFAULT1 0x20 ///< Config 0 open circuit fault 1 flag
#define MAX31856_CR0_OCFAULT0 0x10 ///< Config 0 open circuit fault 0 flag
#define MAX31856_CR0_CJ 0x08 ///< Config 0 cold junction disable flag
#define MAX31856_CR0_FAULT 0x04 ///< Config 0 fault mode flag
#define MAX31856_CR0_FAULTCLR 0x02 ///< Config 0 fault clear flag
#define MAX31856_CR1_REG 0x01 ///< Config 1 register
#define MAX31856_MASK_REG 0x02 ///< Fault Mask register
#define MAX31856_CJHF_REG 0x03 ///< Cold junction High temp fault register
#define MAX31856_CJLF_REG 0x04 ///< Cold junction Low temp fault register
#define MAX31856_LTHFTH_REG 0x05 ///< Linearized Temperature High Fault Threshold Register, MSB
#define MAX31856_LTHFTL_REG 0x06 ///< Linearized Temperature High Fault Threshold Register, LSB
#define MAX31856_LTLFTH_REG 0x07 ///< Linearized Temperature Low Fault Threshold Register, MSB
#define MAX31856_LTLFTL_REG 0x08 ///< Linearized Temperature Low Fault Threshold Register, LSB
#define MAX31856_CJTO_REG 0x09 ///< Cold-Junction Temperature Offset Register
#define MAX31856_CJTH_REG 0x0A ///< Cold-Junction Temperature Register, MSB
#define MAX31856_CJTL_REG 0x0B ///< Cold-Junction Temperature Register, LSB
#define MAX31856_LTCBH_REG 0x0C ///< Linearized TC Temperature, Byte 2
#define MAX31856_LTCBM_REG 0x0D ///< Linearized TC Temperature, Byte 1
#define MAX31856_LTCBL_REG 0x0E ///< Linearized TC Temperature, Byte 0
#define MAX31856_SR_REG 0x0F ///< Fault Status Register
#define MAX31856_FAULT_CJRANGE 0x80 ///< Fault status Cold Junction Out-of-Range flag
#define MAX31856_FAULT_TCRANGE 0x40 ///< Fault status Thermocouple Out-of-Range flag
#define MAX31856_FAULT_CJHIGH 0x20 ///< Fault status Cold-Junction High Fault flag
#define MAX31856_FAULT_CJLOW 0x10 ///< Fault status Cold-Junction Low Fault flag
#define MAX31856_FAULT_TCHIGH 0x08 ///< Fault status Thermocouple Temperature High Fault flag
#define MAX31856_FAULT_TCLOW 0x04 ///< Fault status Thermocouple Temperature Low Fault flag
#define MAX31856_FAULT_OVUV 0x02 ///< Fault status Overvoltage or Undervoltage Input Fault flag
#define MAX31856_FAULT_OPEN 0x01 ///< Fault status Thermocouple Open-Circuit Fault flag
/** Noise filtering options enum. Use with setNoiseFilter() */
typedef enum {
} max31856_noise_filter_t;
/** Multiple types of thermocouples supported */
typedef enum
MAX31856_TCTYPE_B = 0b0000,
MAX31856_TCTYPE_E = 0b0001,
MAX31856_TCTYPE_J = 0b0010,
MAX31856_TCTYPE_K = 0b0011,
MAX31856_TCTYPE_N = 0b0100,
MAX31856_TCTYPE_R = 0b0101,
MAX31856_TCTYPE_S = 0b0110,
MAX31856_TCTYPE_T = 0b0111,
MAX31856_VMODE_G8 = 0b1000,
MAX31856_VMODE_G32 = 0b1100,
} max31856_thermocoupletype_t;
#if (ARDUINO >= 100)
#include "Arduino.h"
#include "WProgram.h"
@brief Class that stores state and functions for interacting with MAX31856
class Adafruit_MAX31856 {
Adafruit_MAX31856(int8_t spi_cs, int8_t spi_mosi, int8_t spi_miso, int8_t spi_clk);
Adafruit_MAX31856(int8_t spi_cs);
boolean begin(void);
void setThermocoupleType(max31856_thermocoupletype_t type);
max31856_thermocoupletype_t getThermocoupleType(void);
uint8_t readFault(void);
void oneShotTemperature(void);
float readCJTemperature(void);
float readThermocoupleTemperature(void);
void setTempFaultThreshholds(float flow, float fhigh);
void setColdJunctionFaultThreshholds(int8_t low, int8_t high);
void setNoiseFilter(max31856_noise_filter_t noiseFilter);
int8_t _sclk, _miso, _mosi, _cs;
void readRegisterN(uint8_t addr, uint8_t buffer[], uint8_t n);
uint8_t readRegister8(uint8_t addr);
uint16_t readRegister16(uint8_t addr);
uint32_t readRegister24(uint8_t addr);
void writeRegister8(uint8_t addr, uint8_t reg);
uint8_t spixfer(uint8_t addr);
#include <Arduino.h>
#include <Adafruit_MAX31856.h>
#include <InstrumentInterface.hpp>
#include "ADS1115.h"
Adafruit_MAX31856 thermocouple = Adafruit_MAX31856(10);
InstrumentInterface iface;
void multi_req_cb(bool status, sadapmap_ReqMultiChannelReading *req) {
return; // Pacote inválido
float readings[req->id_count] = {0};
for(uint8_t i = 0; i < req->id_count; i++) {
// 0x04 pra medir single ended
adc0.setMultiplexer(req->id[i] | 0x04);
readings[i] = adc0.getMilliVolts(false);
if(req->id[i] < 2) {
adc0.setMultiplexer(req->id[i] | 0x04);
readings[i] = adc0.getMilliVolts(false);
} else {
readings[i] = thermocouple.readThermocoupleTemperature();
readings[0] = adc0.getMilliVolts(false);
readings[1] = adc0.getMilliVolts(false);
readings[2] = thermocouple.readThermocoupleTemperature();*/
iface.sendMultiChannel(req->id, readings, req->id_count);
......@@ -25,6 +38,9 @@ void setup() {
iface.init(Serial, &multi_req_cb);
//Serial.println("Testing device connections...");
//Serial.println(adc0.testConnection() ? "ADS1115 connection successful" : "ADS1115 connection failed");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment