# Adafruit PT100 library MAX31865

**URL:** <https://community.particle.io/t/adafruit-pt100-library-max31865/33901>\
**Category:** Libraries\
**Created:** [June 19, 2017, 11:50am UTC](https://community.particle.io/t/adafruit-pt100-library-max31865/33901 "2017-06-19T11:50:35Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![rdavidsson](https://avatars.discourse-cdn.com/v4/letter/r/7993a0/32.png) [@rdavidsson](https://community.particle.io/u/rdavidsson)\
**Post date:** [June 19, 2017, 11:50am UTC](https://community.particle.io/t/adafruit-pt100-library-max31865/33901/1 "2017-06-19T11:50:35Z")

</div>

Hello guys,

I´m trying to use a PT100 breakout from Adafruit with my Photon ([Adafruit Board](https://www.adafruit.com/product/3328)). The library is not in the Web IDE so I used the “+” to include it in the project. I´m always getting this error when I compile…

What should I do ?

 ![](https://us1.discourse-cdn.com/flex026/uploads/particle/original/2X/0/0a6ac467b75832dd225a87b0e3197895d7c50413.JPG)

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [June 19, 2017, 1:49pm UTC](https://community.particle.io/t/adafruit-pt100-library-max31865/33901/2 "2017-06-19T13:49:09Z")

</div>

@rdavidsson,

I added it to the Particle library and you can find it here: [https://build.particle.io/libs/Adafruit\_MAX31865\_library](https://build.particle.io/libs/Adafruit_MAX31865_library)

System firmware needs to be \>= 0.6.2

---

<div class="post-metadata">

**Author:** ![rdavidsson](https://avatars.discourse-cdn.com/v4/letter/r/7993a0/32.png) [@rdavidsson](https://community.particle.io/u/rdavidsson)\
**Post date:** [June 19, 2017, 3:54pm UTC](https://community.particle.io/t/adafruit-pt100-library-max31865/33901/3 "2017-06-19T15:54:17Z")

</div>

Thank´s alot, now it compiles ! 😄

---

<div class="post-metadata">

**Author:** ![rdavidsson](https://avatars.discourse-cdn.com/v4/letter/r/7993a0/32.png) [@rdavidsson](https://community.particle.io/u/rdavidsson)\
**Post date:** [June 20, 2017, 8:47am UTC](https://community.particle.io/t/adafruit-pt100-library-max31865/33901/4 "2017-06-20T08:47:42Z")

</div>

On more question, regarding the SPI. The example is for Arduino where the pins are 10,11,12,13, hardware pins. In my case, I´m trying to use A2, A3, A4, A5. How do I do that here:

```
// Use software SPI: CS, DI, DO, CLK
Adafruit_MAX31865 sensor = Adafruit_MAX31865(2, 5, 4, 3);
// use hardware SPI, just pass in the CS pin

```

The code:  
#include \<Adafruit\_MAX31865.h\>

```
// Use software SPI: CS, DI, DO, CLK
Adafruit_MAX31865 sensor = Adafruit_MAX31865(2, 5, 4, 3);
// use hardware SPI, just pass in the CS pin
//Adafruit_MAX31865 sensor = Adafruit_MAX31865(2);

// The value of the Rref resistor. Use 430.0!
#define RREF 430.0

void setup() {
  Serial.begin(115200);
  Serial.println("Adafruit MAX31865 PT100 Sensor Test!");

  sensor.begin(MAX31865_4WIRE); // set to 2WIRE or 4WIRE as necessary
}

void loop() {
  uint16_t rtd = sensor.readRTD();

  Serial.print("RTD value: "); Serial.println(rtd);
  float ratio = rtd;
  ratio /= 32768;
  Serial.print("Ratio = "); Serial.println(ratio,8);
  Serial.print("Resistance = "); Serial.println(RREF*ratio,8);
  Serial.print("Temperature = "); Serial.println(sensor.temperature(100, RREF));

  // Check and print any faults
  uint8_t fault = sensor.readFault();
  if (fault) {
Serial.print("Fault 0x"); Serial.println(fault, HEX);
if (fault & MAX31865_FAULT_HIGHTHRESH) {
  Serial.println("RTD High Threshold");
}
if (fault & MAX31865_FAULT_LOWTHRESH) {
  Serial.println("RTD Low Threshold");
}
if (fault & MAX31865_FAULT_REFINLOW) {
  Serial.println("REFIN- > 0.85 x Bias");
}
if (fault & MAX31865_FAULT_REFINHIGH) {
  Serial.println("REFIN- < 0.85 x Bias - FORCE- open");
}
if (fault & MAX31865_FAULT_RTDINLOW) {
  Serial.println("RTDIN- < 0.85 x Bias - FORCE- open");
}
if (fault & MAX31865_FAULT_OVUV) {
  Serial.println("Under/Over voltage");
}
sensor.clearFault();
  }
  Serial.println();
  delay(10000);
}
```

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [June 20, 2017, 9:12am UTC](https://community.particle.io/t/adafruit-pt100-library-max31865/33901/5 "2017-06-20T09:12:53Z")

</div>

For software SPI:

```auto
Adafruit_MAX31865 sensor = Adafruit_MAX31865(A2, A5, A4, A3);

```

You should instead the Hardware SPI initialization:

```auto
Adafruit_MAX31865 sensor = Adafruit_MAX31865(A2);

```

---

<div class="post-metadata">

**Author:** ![xa4gva](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/xa4gva/32/14999_2.png) [@xa4gva](https://community.particle.io/u/xa4gva)\
**Post date:** [July 17, 2017, 9:30pm UTC](https://community.particle.io/t/adafruit-pt100-library-max31865/33901/6 "2017-07-17T21:30:15Z")

</div>

So finally did it work ? The lib works great on arduino but I can’t get correct values using the particle photon (0.6.2)…  
I tried both SPI and SPI1 pins…

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [July 17, 2017, 9:34pm UTC](https://community.particle.io/t/adafruit-pt100-library-max31865/33901/7 "2017-07-17T21:34:02Z")

</div>

Just for nit-picking, the preferable syntax would be

```cpp
Adafruit_MAX31865 sensor(A2);

```

as this constructs the object in-place while the other syntax first creates a default object `Adafruit_MAX31865()`, a temporary object `Adafruit_MAX31865(A2)` and then assigns the latter to the former.

---

<div class="post-metadata">

**Author:** ![rdavidsson](https://avatars.discourse-cdn.com/v4/letter/r/7993a0/32.png) [@rdavidsson](https://community.particle.io/u/rdavidsson)\
**Post date:** [July 17, 2017, 9:56pm UTC](https://community.particle.io/t/adafruit-pt100-library-max31865/33901/8 "2017-07-17T21:56:34Z")

</div>

Yes it worked when I use hardware SPI. My code is like this:

```
#include "application.h"
#include <Adafruit_MAX31865.h>

// use hardware SPI, just pass in the CS pin
Adafruit_MAX31865 sensor = Adafruit_MAX31865(A2);

// The value of the Rref resistor. Use 430.0!
#define RREF 430.0

void setup() {
  Serial.begin(115200);
  Serial.println("Adafruit MAX31865 PT100 Sensor Test!");
  SPI.begin();
  sensor.begin(MAX31865_4WIRE); // set to 2WIRE or 4WIRE as necessary
}

void loop() {
  uint16_t rtd = sensor.readRTD();

  Serial.print("RTD value: "); Serial.println(rtd);
  float ratio = rtd;
  ratio /= 32768;
  Serial.print("Ratio = "); Serial.println(ratio,8);
  Serial.print("Resistance = "); Serial.println(RREF*ratio,8);
  Serial.print("Temperature = "); Serial.println(sensor.temperature(100, RREF));

  // Check and print any faults
  uint8_t fault = sensor.readFault();
  if (fault) {
    Serial.print("Fault 0x"); Serial.println(fault, HEX);
    if (fault & MAX31865_FAULT_HIGHTHRESH) {
      Serial.println("RTD High Threshold");
    }
    if (fault & MAX31865_FAULT_LOWTHRESH) {
      Serial.println("RTD Low Threshold");
    }
    if (fault & MAX31865_FAULT_REFINLOW) {
      Serial.println("REFIN- > 0.85 x Bias");
    }
    if (fault & MAX31865_FAULT_REFINHIGH) {
      Serial.println("REFIN- < 0.85 x Bias - FORCE- open");
    }
    if (fault & MAX31865_FAULT_RTDINLOW) {
      Serial.println("RTDIN- < 0.85 x Bias - FORCE- open");
    }
    if (fault & MAX31865_FAULT_OVUV) {
      Serial.println("Under/Over voltage");
    }
    sensor.clearFault();
  }
  Serial.println();
  delay(10000);
}
```

---

<div class="post-metadata">

**Author:** ![xa4gva](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/xa4gva/32/14999_2.png) [@xa4gva](https://community.particle.io/u/xa4gva)\
**Post date:** [July 18, 2017, 12:00am UTC](https://community.particle.io/t/adafruit-pt100-library-max31865/33901/9 "2017-07-18T00:00:09Z")

</div>

Yay! I don’t know what went wrong but I copy pasted your code and it works 🙂 Thank you Ragnar

---

<div class="post-metadata">

**Author:** ![rdavidsson](https://avatars.discourse-cdn.com/v4/letter/r/7993a0/32.png) [@rdavidsson](https://community.particle.io/u/rdavidsson)\
**Post date:** [July 31, 2017, 1:24pm UTC](https://community.particle.io/t/adafruit-pt100-library-max31865/33901/10 "2017-07-31T13:24:29Z")

</div>

Hello Guys. I changed the code a little bit today but now I cannot compile the project…

I get the following error when compiling:

"lib/Adafruit\_MAX31865\_library/src/Adafruit\_MAX31865.h:54:23: fatal error: WProgram,h: No such file or directory  
#include “WProgram.h”  
^  
It´s the same error I was getting before Kenneth installed the library in the WEB IDE…

@ScruffR @kennethlimcp

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [August 2, 2017, 2:05pm UTC](https://community.particle.io/t/adafruit-pt100-library-max31865/33901/11 "2017-08-02T14:05:07Z")

</div>

Standard response: What system version are you targeting? (double check 😉 )  
Stating this initially (along with other standard info) might save you the extra iterations in a thread.

---

<div class="post-metadata">

**Author:** ![rdavidsson](https://avatars.discourse-cdn.com/v4/letter/r/7993a0/32.png) [@rdavidsson](https://community.particle.io/u/rdavidsson)\
**Post date:** [August 2, 2017, 2:18pm UTC](https://community.particle.io/t/adafruit-pt100-library-max31865/33901/12 "2017-08-02T14:18:32Z")

</div>

Firmware on Photon: v0.6.2. Adafruit\_MAX31865\_library: v1.0.0.

I havent changed anything since last time when it worker but I can see that the library name is not the same now (waw without “\_library”)…

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [August 2, 2017, 2:33pm UTC](https://community.particle.io/t/adafruit-pt100-library-max31865/33901/13 "2017-08-02T14:33:46Z")

</div>

Still double check, sometimes Web IDE suffers from amnesia 😉

BTW, how come there is a comma in the error message `WProgram,h`?

You could also try adding this before your other includes

```cpp
#define ARDUINO (100)
#include <Arduino.h>

```
