Wemos with pt100/max31865

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
remko2000
Normal user
Posts: 41
Joined: 28 Dec 2017, 15:56

Wemos with pt100/max31865

#1 Post by remko2000 » 13 Jan 2019, 12:15

I have connected a PT100 with MAX31865 to my wemos d1. I have uploaded this script via the arduino ide.

Code: Select all

/*************************************************** 
  This is a library for the Adafruit PT100/P1000 RTD Sensor w/MAX31865

  Designed specifically to work with the Adafruit RTD Sensor
  ----> https://www.adafruit.com/products/3328

  This sensor uses SPI to communicate, 4 pins are required to  
  interface
  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/

#include <Adafruit_MAX31865.h>


// Use software SPI:         CS, DI, DO, CLK
//NodeMCU pins connected to: D0, D1, D2, D3
Adafruit_MAX31865 max1 = Adafruit_MAX31865(16, 5, 4, 0);
// use hardware SPI, just pass in the CS pin
//Adafruit_MAX31865 max1 = Adafruit_MAX31865(16);

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


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

  max1.begin(MAX31865_3WIRE);  // set to 2WIRE or 4WIRE as necessary
}


void loop() {
  uint16_t rtd = max1.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(max1.temperature(100, RREF));

/*  // Check and print any faults
  uint8_t fault = max1.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"); 
    }
    max1.clearFault();
  }
  Serial.println();
*/  
  delay(1000);
}
I get the correct values back via the serial monitor. Thats great!

The next step is of course that I want to see these values in eg. domoticz.
I searched with google and I think I've to include the esp library into my sketch with
#include <ESP8266WiFi.h>
but how do I send this temperature to my domoticz? I have already created a dummy switch temperature in domoticz with IDX 4732. How do I integrate this ESP8266-code in my working max31865script?

remko2000
Normal user
Posts: 41
Joined: 28 Dec 2017, 15:56

Re: Wemos with pt100/max31865

#2 Post by remko2000 » 24 Jan 2019, 16:50

If tried to make a script. I combined my working max31865 script with a temperaturescript:

Code: Select all

/*************************************************** 
  This is a library for the Adafruit PT100/P1000 RTD Sensor w/MAX31865

  Designed specifically to work with the Adafruit RTD Sensor
  ----> https://www.adafruit.com/products/3328

  This sensor uses SPI to communicate, 4 pins are required to  
  interface
  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/

#include <Adafruit_MAX31865.h>
#include <ESP8266WiFi.h>

//int status = WL_IDLE_STATUS;     // the Wifi radio's status
WiFiClient client;

// domoticz
const char * domoticz_server = "xx.x.x.xx"; //Domoticz port
int port = 8080; //Domoticz port
int idx = 4732; //IDX for virtual sensor, found in Setup -> Devices

float temp = 0;

//Create Instance of PT100/max31865sensor
Temp sensor;

// Use software SPI: CS, DI, DO, CLK
Adafruit_MAX31865 max = Adafruit_MAX31865(8, 7, 6, 5);
// use hardware SPI, just pass in the CS pin
//Adafruit_MAX31865 max = Adafruit_MAX31865(10);

// The value of the Rref resistor. Use 430.0 for PT100 and 4300.0 for PT1000
#define RREF      430.0
// The 'nominal' 0-degrees-C resistance of the sensor
// 100.0 for PT100, 1000.0 for PT1000
#define RNOMINAL  100.0

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

  max.begin(MAX31865_3WIRE);  // set to 2WIRE or 4WIRE as necessary

  //Initialize the I2C sensors and ping them
    sensor.begin();
}


void loop() {
  //Get readings from all sensors
    getTemp();
    printInfo();
    delay(60000); // Wait 60 seconds
    
  uint16_t rtd = max.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(max.temperature(RNOMINAL, RREF));

  // Check and print any faults
  uint8_t fault = max.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"); 
    }
    max.clearFault();
  }
  Serial.println();
  delay(1000);
}

void getTemp()
{
  // Measure Temperature from PT100/max31865sensor
  temp = sensor.getTemp();
  // Temperature is measured every time RH is requested.
  // It is faster, therefore, to read it from previous RH
  // measurement with getTemp() instead with readTemp()
}

void printInfo()
{
// Domoticz format /json.htm?type=command&param=udevice&idx=IDX&nvalue=0&svalue=TEMP

if (client.connect(domoticz_server,port)) {
  
    client.print("GET /json.htm?type=command&param=udevice&idx=");
    client.print(idx);
    client.print("&nvalue=0&svalue=");
    client.print(temp);
    client.print(";");
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.print(domoticz_server);
    client.print(":");
    client.println(port);
    client.println("User-Agent: Arduino-ethernet");
    client.println("Connection: close");
    client.println();

    client.stop();
    }
}
This script isnt working. The error:
'Temp' does not name a type
Im not verry good in coding. What am I doning wrong?

kimot
Normal user
Posts: 157
Joined: 12 Oct 2017, 20:46

Re: Wemos with pt100/max31865

#3 Post by kimot » 25 Jan 2019, 12:14

And what is :

Code: Select all

Temp sensor;
At Adafruit_MAX31865 library is nothing that.

you create Adafruit instance calling

Code: Select all

Adafruit_MAX31865 max = Adafruit_MAX31865(8, 7, 6, 5);
But you are using some sensor.getTemp function.
Where it is defined?

It look like mixing two independent code, but not completely.

remko2000
Normal user
Posts: 41
Joined: 28 Dec 2017, 15:56

Re: Wemos with pt100/max31865

#4 Post by remko2000 » 25 Jan 2019, 18:51

Yes thats right. I want to mix 2 examples of code in one script. Maybe that's not a good approach. All I want is the temperature in my seriel monitor send to domoticz. The code below is working for me. Next step is to send the value to IDX 4732 in domoticz instead of the seriel monitor but I don't know how to do this.
/***************************************************
This is a library for the Adafruit PT100/P1000 RTD Sensor w/MAX31865

Designed specifically to work with the Adafruit RTD Sensor
----> https://www.adafruit.com/products/3328

This sensor uses SPI to communicate, 4 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!

Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/

#include <Adafruit_MAX31865.h>

// Use software SPI: CS, DI, DO, CLK
Adafruit_MAX31865 max = Adafruit_MAX31865(8, 7, 6, 5);
// use hardware SPI, just pass in the CS pin
//Adafruit_MAX31865 max = Adafruit_MAX31865(10);

// The value of the Rref resistor. Use 430.0 for PT100 and 4300.0 for PT1000
#define RREF 430.0
// The 'nominal' 0-degrees-C resistance of the sensor
// 100.0 for PT100, 1000.0 for PT1000
#define RNOMINAL 100.0

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

max.begin(MAX31865_3WIRE); // set to 2WIRE or 4WIRE as necessary
}


void loop() {
uint16_t rtd = max.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(max.temperature(RNOMINAL, RREF));

// Check and print any faults
uint8_t fault = max.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");
}
max.clearFault();
}
Serial.println();
delay(1000);
}

kimot
Normal user
Posts: 157
Joined: 12 Oct 2017, 20:46

Re: Wemos with pt100/max31865

#5 Post by kimot » 25 Jan 2019, 21:52

Here is example how to send data to Domoticz:

https://diyprojects.io/esp8266-web-clie ... -api-json/

But is for different dummy device ( combination temp + hum + pressure )

By the way, your IDX 4732 is odd.

Domoticz allocates IDX incrementally.
So you have got more then 4000 devices ?!?

remko2000
Normal user
Posts: 41
Joined: 28 Dec 2017, 15:56

Re: Wemos with pt100/max31865

#6 Post by remko2000 » 26 Jan 2019, 16:32

Thanx for the link. I have tried to rewrite my script witg inspiration of the example:

Code: Select all

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <Adafruit_MAX31865.h>

const char* ssid     = "xxx";
const char* password = "xxxxx";
const char* host = "10.0.1.32";
const int   port = 8080;
const int   watchdog = 60000; // Fréquence d'envoi des données à Domoticz - Frequency of sending data to Domoticz
unsigned long previousMillis = millis(); 

// Use software SPI: CS, DI, DO, CLK
Adafruit_MAX31865 max = Adafruit_MAX31865(8, 7, 6, 5);
// use hardware SPI, just pass in the CS pin
//Adafruit_MAX31865 max = Adafruit_MAX31865(10);

// The value of the Rref resistor. Use 430.0 for PT100 and 4300.0 for PT1000
#define RREF      430.0
// The 'nominal' 0-degrees-C resistance of the sensor
// 100.0 for PT100, 1000.0 for PT1000
#define RNOMINAL  100.0

HTTPClient http;

void setup() {
  Serial.begin(115200);
  delay(10);
  Serial.println("Adafruit MAX31865 PT100 Sensor Test!");
  max.begin(MAX31865_3WIRE);  // set to 2WIRE or 4WIRE as necessary
  }
  
  Serial.setDebugOutput(true);  
  Serial.println("Connecting Wifi...");

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
   
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.print(WiFi.localIP()); 
}

int value = 0;

void loop() {
  unsigned long currentMillis = millis();

  if ( currentMillis - previousMillis > watchdog ) {
    previousMillis = currentMillis;

    if(WiFi.status() != WL_CONNECTED) {
      Serial.println("WiFi not connected !");
    } else {  
      Serial.println("Send data to Domoticz");
 {     
  uint16_t rtd = max.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(max.temperature(RNOMINAL, RREF));

  // Check and print any faults
  uint8_t fault = max.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"); 
    }
    max.clearFault();
  }
  Serial.println();
  delay(1000); 
     
}    
        
        String url = "/json.htm?type=command&param=udevice&idx=4732&nvalue=0&svalue=";
        url += String(t); url += ";";
        url += String(h); url += ";";
        url += String(hum_stat); url += ";";
        url += String(pa);url += ";";
        url += String(bar_for);
     
        sendDomoticz(url);
      }
    }
  }
}

void sendDomoticz(String url){
  Serial.print("connecting to ");
  Serial.println(host);
  Serial.print("Requesting URL: ");
  Serial.println(url);
  http.begin(host,port,url);
  int httpCode = http.GET();
    if (httpCode) {
      if (httpCode == 200) {
        String payload = http.getString();
        Serial.println("Domoticz response "); 
        Serial.println(payload);
      }
    }
  Serial.println("closing connection");
  http.end();
}
I get an error (Serial' does not name a type) by the line:
Serial.print(WiFi.localIP());
Am I close?

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests