I change this, and installed in arduino. I am trying using PID, without LCD. the output is:
RTD Sensor Trtd = 18.50 deg C
RTD Sensor Trtd = 18.47 deg C
RTD Sensor Trtd = 18.50 deg C
/* Arduino Uno --> SEN-30201
* CS: pin 4 --> CS
* MOSI: pin 11 --> SDI (must not be changed for hardware SPI)
* MISO: pin 12 --> SDO (must not be changed for hardware SPI)
* SCK: pin 13 --> SCLK (must not be changed for hardware SPI)
* GND --> GND
* 5V --> Vin (supply with same voltage as Arduino I/O, 5V)
***************************************************************************/
// the sensor communicates using SPI, so include the hardware SPI library:
#include <SPI.h>
// include Playing With Fusion MAX31865 libraries
#include <PlayingWithFusion_MAX31865.h> // core library
#include <PlayingWithFusion_MAX31865_STRUCT.h> // struct library
#include <PID_v1.h>
#define RelayPin 6
//Define Variables we'll be connecting to
double Setpoint, Input, Output;
//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint,2,5,1, DIRECT);
int WindowSize = 5000;
unsigned long windowStartTime;
//Sensor addresses:
const byte CONFIG_REG_W = 0x80; // Config register write addr
const byte CONFIG_VALUE = 0xC3; // Config register value (Vbias+Auto+FaultClear+50Hz, see pg 12 of datasheet)
const byte ADC_WORD_MSB = 0x01; // Addr of first byte of data (start reading at RTD MSB)
const byte ADC_FAULT_REG = 0x07; // Addr of the fault reg
// CS pin used for the connection with the sensor
// other connections are controlled by the SPI library)
const int CS_PIN = 4;
PWFusion_MAX31865_RTD rtd_ch0(CS_PIN);
void setup() {
Serial.begin(9600);
// setup for the the SPI library:
SPI.begin(); // begin SPI
SPI.setDataMode(SPI_MODE3); // MAX31865 is a Mode 3 device
// initalize the chip select pin
pinMode(CS_PIN, OUTPUT);
rtd_ch0.MAX31865_config();
// give the sensor time to set up
delay(100);
windowStartTime = millis();
//initialize the variables we're linked to
Setpoint = 40;
//tell the PID to range between 0 and the full window size
myPID.SetOutputLimits(0, WindowSize);
//turn the PID on
myPID.SetMode(AUTOMATIC);
}
void loop()
{
temp_sensor();
myPID.Compute();
/************************************************
* turn the output pin on/off based on pid output
************************************************/
if(millis() - windowStartTime>WindowSize)
{ //time to shift the Relay Window
windowStartTime += WindowSize;
}
if(Output < millis() - windowStartTime) digitalWrite(RelayPin,HIGH);
else digitalWrite(RelayPin,LOW);
}
void temp_sensor()
{
static struct var_max31865 RTD_CH0;
double tmp;
RTD_CH0.RTD_type = 1; // un-comment for PT100 RTD
struct var_max31865 *rtd_ptr;
rtd_ptr = &RTD_CH0;
rtd_ch0.MAX31865_full_read(rtd_ptr); // Update MAX31855 readings
// Print information to serial port
Serial.print("RTD Sensor "); // Print RTD0 header
if(0 == RTD_CH0.status) // no fault, print info to serial port
{
// calculate RTD temperature (simple calc, +/- 2 deg C from -100C to 100C)
// more accurate curve can be used outside that range
tmp = ((double)RTD_CH0.rtd_res_raw / 32) - 256;
Input = tmp;
delay(500);
Serial.print("Trtd = "); // print RTD temperature heading
Serial.print(tmp);
Serial.println(" deg C"); // print RTD temperature heading
} // end of no-fault handling
else
{
Serial.print("RTD Fault, register: ");
Serial.print(RTD_CH0.status);
Serial.print(" - ");
if(0x80 & RTD_CH0.status)
{
Serial.println("RTD High Threshold Met"); // RTD high threshold fault
}
else if(0x40 & RTD_CH0.status)
{
Serial.println("RTD Low Threshold Met"); // RTD low threshold fault
}
else if(0x20 & RTD_CH0.status)
{
Serial.println("REFin- > 0.85 x Vbias"); // REFin- > 0.85 x Vbias
}
else if(0x10 & RTD_CH0.status)
{
Serial.println("FORCE- open"); // REFin- < 0.85 x Vbias, FORCE- open
}
else if(0x08 & RTD_CH0.status)
{
Serial.println("FORCE- open"); // RTDin- < 0.85 x Vbias, FORCE- open
}
else if(0x04 & RTD_CH0.status)
{
Serial.println("Over/Under voltage fault"); // overvoltage/undervoltage fault
}
else
{
Serial.println("Unknown fault, check connection"); // print RTD temperature heading
}
} // end of fault handling
}