I am interfacing a PT100 RTD temperature sensor with Arduino mega 2560 using MX31865. I am displaying the resultant temperature on LCD ; but the LCD displays some garbage value after 4 digits.
/***************************************************
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<LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
//Use software SPI: CS, DI, DO, CLK
Adafruit_MAX31865 thermo = Adafruit_MAX31865(53, 51, 50, 52);
// use hardware SPI, just pass in the CS pin
//Adafruit_MAX31865 thermo = Adafruit_MAX31865(53);
// 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.println("Adafruit MAX31865 PT100 Sensor Test!");
lcd.begin(16,2);
thermo.begin(MAX31865_3WIRE); // set to 2WIRE or 4WIRE as necessary
}
void loop() {
uint16_t rtd = thermo.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);
//lcd.clear();
lcd.setCursor(0,0);
lcd.print("Temperature = ");
float x=thermo.temperature(RNOMINAL, RREF);
lcd.setCursor(0,1);
lcd.println(x,1);
//lcd.setCursor(5,1);
//lcd.print("(char) 223");
lcd.setCursor(6,1);
lcd.print("C ");
// Check and print any faults
uint8_t fault = thermo.readFault();
if (fault) {
lcd.print("Fault 0x"); lcd.print(fault, HEX);
if (fault & MAX31865_FAULT_HIGHTHRESH) {
lcd.print("RTD High Threshold");
}
if (fault & MAX31865_FAULT_LOWTHRESH) {
lcd.print("RTD Low Threshold");
}
if (fault & MAX31865_FAULT_REFINLOW) {
lcd.print("REFIN- > 0.85 x Bias");
}
if (fault & MAX31865_FAULT_REFINHIGH) {
lcd.print("REFIN- < 0.85 x Bias - FORCE- open");
}
if (fault & MAX31865_FAULT_RTDINLOW) {
lcd.print("RTDIN- < 0.85 x Bias - FORCE- open");
}
if (fault & MAX31865_FAULT_OVUV) {
lcd.print("Under/Over voltage");
}
thermo.clearFault();
}
//Serial.println();
}