Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************************************
- 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 <ESP8266WebServer.h>
- #include <ESP8266WiFi.h>
- // Use software SPI: CS, DI, DO, CLK
- //NodeMCU pins connected to: D0, D1, D2, D3
- //Adafruit_MAX31865 max1 = Adafruit_MAX31865(16, 5, 4, 14);
- // use hardware SPI, just pass in the CS pin
- Adafruit_MAX31865 max1 = Adafruit_MAX31865(5);
- Adafruit_MAX31865 max2 = Adafruit_MAX31865(4);
- Adafruit_MAX31865 max3 = Adafruit_MAX31865(15);
- // The value of the Rref resistor. Use 430.0!
- #define RREF 400.0
- // WIFI constants
- const char* ssid = "WTK_KL";
- const char* password = "";
- // Create an instance of the server
- // specify the port to listen on as an argument
- ESP8266WebServer server(80);
- float temp1;
- float temp2;
- float temp3;
- void setup() {
- Serial.begin(115200);
- Serial.println("Adafruit MAX31865 PT100 Sensor Test!");
- max1.begin(MAX31865_2WIRE); // set to 2WIRE or 4WIRE as necessary
- max2.begin(MAX31865_2WIRE);
- max3.begin(MAX31865_2WIRE);
- delay(500);
- // Connect to WiFi network
- Serial.println();
- Serial.println();
- Serial.print("Connecting to ");
- Serial.println(ssid);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("");
- Serial.println("WiFi connected");
- Serial.print("MAC: ");
- Serial.println(WiFi.macAddress());
- // Start the server
- server.begin();
- Serial.println("Server started");
- // Print the IP address
- Serial.println(WiFi.localIP());
- server.on("/", []() {
- String responseData = "[";
- 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 = ");
- temp1 = max1.temperature(100, RREF);
- Serial.println(temp1);
- HandleFault(max1);
- delay(500);
- rtd = max2.readRTD();
- ratio = rtd;
- ratio /= 32768;
- temp2 = max2.temperature(100, RREF);
- Serial.println(temp2);
- HandleFault(max2);
- delay(500);
- rtd = max3.readRTD();
- ratio = rtd;
- ratio /= 32768;
- temp3 = max3.temperature(100, RREF);
- Serial.println(temp3);
- HandleFault(max3);
- for(byte i = 0; i< 3; i++)
- {
- Serial.println(i);
- responseData += "{ \"sensor_id\": " + String(i) + ", \"temperature\": " + String(getTemp(i)) + "}";
- if(i < 2)
- {
- responseData += ",";
- }
- }
- responseData += "]";
- server.sendHeader("Access-Control-Max-Age", "10000");
- server.sendHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS");
- server.sendHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
- server.send(200, "application/json", responseData);
- });
- }
- String getTemp(byte i)
- {
- switch(i)
- {
- case 0:
- return String(temp1);
- break;
- case 1:
- return String(temp2);
- break;
- case 2:
- return String(temp3);
- break;
- default:
- return "";
- break;
- }
- }
- void HandleFault(Adafruit_MAX31865 max_)
- {
- // 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();
- }
- }
- void loop() {
- server.handleClient();
- }
Add Comment
Please, Sign In to add comment