Adafruit MAX31865 Arduino Library
Adafruit_MAX31865.h
1 /***************************************************
2  This is a library for the Adafruit PT100/P1000 RTD Sensor w/MAX31865
3 
4  Designed specifically to work with the Adafruit RTD Sensor
5  ----> https://www.adafruit.com/products/3328
6 
7  This sensor uses SPI to communicate, 4 pins are required to
8  interface
9  Adafruit invests time and resources providing this open source code,
10  please support Adafruit and open-source hardware by purchasing
11  products from Adafruit!
12 
13  Written by Limor Fried/Ladyada for Adafruit Industries.
14  BSD license, all text above must be included in any redistribution
15  ****************************************************/
16 
17 #ifndef ADAFRUIT_MAX31865_H
18 #define ADAFRUIT_MAX31865_H
19 
20 #define MAX31865_CONFIG_REG 0x00
21 #define MAX31865_CONFIG_BIAS 0x80
22 #define MAX31865_CONFIG_MODEAUTO 0x40
23 #define MAX31865_CONFIG_MODEOFF 0x00
24 #define MAX31865_CONFIG_1SHOT 0x20
25 #define MAX31865_CONFIG_3WIRE 0x10
26 #define MAX31865_CONFIG_24WIRE 0x00
27 #define MAX31865_CONFIG_FAULTSTAT 0x02
28 #define MAX31865_CONFIG_FILT50HZ 0x01
29 #define MAX31865_CONFIG_FILT60HZ 0x00
30 
31 #define MAX31865_RTDMSB_REG 0x01
32 #define MAX31865_RTDLSB_REG 0x02
33 #define MAX31865_HFAULTMSB_REG 0x03
34 #define MAX31865_HFAULTLSB_REG 0x04
35 #define MAX31865_LFAULTMSB_REG 0x05
36 #define MAX31865_LFAULTLSB_REG 0x06
37 #define MAX31865_FAULTSTAT_REG 0x07
38 
39 #define MAX31865_FAULT_HIGHTHRESH 0x80
40 #define MAX31865_FAULT_LOWTHRESH 0x40
41 #define MAX31865_FAULT_REFINLOW 0x20
42 #define MAX31865_FAULT_REFINHIGH 0x10
43 #define MAX31865_FAULT_RTDINLOW 0x08
44 #define MAX31865_FAULT_OVUV 0x04
45 
46 #define RTD_A 3.9083e-3
47 #define RTD_B -5.775e-7
48 
49 #if (ARDUINO >= 100)
50 #include "Arduino.h"
51 #else
52 #include "WProgram.h"
53 #endif
54 
55 #include <Adafruit_SPIDevice.h>
56 
57 typedef enum max31865_numwires {
58  MAX31865_2WIRE = 0,
59  MAX31865_3WIRE = 1,
60  MAX31865_4WIRE = 0
61 } max31865_numwires_t;
62 
63 typedef enum {
64  MAX31865_FAULT_NONE = 0,
65  MAX31865_FAULT_AUTO,
66  MAX31865_FAULT_MANUAL_RUN,
67  MAX31865_FAULT_MANUAL_FINISH
68 } max31865_fault_cycle_t;
69 
72 public:
73  Adafruit_MAX31865(int8_t spi_cs, int8_t spi_mosi, int8_t spi_miso,
74  int8_t spi_clk);
75  Adafruit_MAX31865(int8_t spi_cs, SPIClass *theSPI = &SPI);
76 
77  bool begin(max31865_numwires_t x = MAX31865_2WIRE);
78 
79  uint8_t readFault(max31865_fault_cycle_t fault_cycle = MAX31865_FAULT_AUTO);
80  void clearFault(void);
81  uint16_t readRTD();
82 
83  void setThresholds(uint16_t lower, uint16_t upper);
84  uint16_t getLowerThreshold(void);
85  uint16_t getUpperThreshold(void);
86 
87  void setWires(max31865_numwires_t wires);
88  void autoConvert(bool b);
89  void enable50Hz(bool b);
90  void enableBias(bool b);
91 
92  float temperature(float RTDnominal, float refResistor);
93  float calculateTemperature(uint16_t RTDraw, float RTDnominal,
94  float refResistor);
95 
96 private:
97  Adafruit_SPIDevice spi_dev;
98 
99  void readRegisterN(uint8_t addr, uint8_t buffer[], uint8_t n);
100 
101  uint8_t readRegister8(uint8_t addr);
102  uint16_t readRegister16(uint8_t addr);
103 
104  void writeRegister8(uint8_t addr, uint8_t reg);
105 };
106 
107 #endif
bool begin(max31865_numwires_t x=MAX31865_2WIRE)
Initialize the SPI interface and set the number of RTD wires used.
Definition: Adafruit_MAX31865.cpp:59
Definition: Adafruit_MAX31865.h:71
void autoConvert(bool b)
Whether we want to have continuous conversions (50/60 Hz)
Definition: Adafruit_MAX31865.cpp:139
uint16_t getUpperThreshold(void)
Read the raw 16-bit lower threshold value.
Definition: Adafruit_MAX31865.cpp:197
float temperature(float RTDnominal, float refResistor)
Read the temperature in C from the RTD through calculation of the resistance. Uses http://www...
Definition: Adafruit_MAX31865.cpp:232
uint16_t readRTD()
Read the raw 16-bit value from the RTD_REG in one shot mode.
Definition: Adafruit_MAX31865.cpp:296
uint8_t readFault(max31865_fault_cycle_t fault_cycle=MAX31865_FAULT_AUTO)
Read the raw 8-bit FAULTSTAT register.
Definition: Adafruit_MAX31865.cpp:82
void enable50Hz(bool b)
Whether we want filter out 50Hz noise or 60Hz noise.
Definition: Adafruit_MAX31865.cpp:156
void clearFault(void)
Clear all faults in FAULTSTAT.
Definition: Adafruit_MAX31865.cpp:110
uint16_t getLowerThreshold(void)
Read the raw 16-bit lower threshold value.
Definition: Adafruit_MAX31865.cpp:187
float calculateTemperature(uint16_t RTDraw, float RTDnominal, float refResistor)
Calculate the temperature in C from the RTD through calculation of the resistance. Uses http://www.analog.com/media/en/technical-documentation/application-notes/AN709_0.pdf technique.
Definition: Adafruit_MAX31865.cpp:249
Adafruit_MAX31865(int8_t spi_cs, int8_t spi_mosi, int8_t spi_miso, int8_t spi_clk)
Create the interface object using software (bitbang) SPI.
Definition: Adafruit_MAX31865.cpp:36
void enableBias(bool b)
Enable the bias voltage on the RTD sensor.
Definition: Adafruit_MAX31865.cpp:123
void setThresholds(uint16_t lower, uint16_t upper)
Write the lower and upper values into the threshold fault register to values as returned by readRTD()...
Definition: Adafruit_MAX31865.cpp:174
void setWires(max31865_numwires_t wires)
How many wires we have in our RTD setup, can be MAX31865_2WIRE, MAX31865_3WIRE, or MAX31865_4WIRE...
Definition: Adafruit_MAX31865.cpp:208