I have a NodeMCU and a Adafruit Max31866 RTD breakout board. I have hooked the pins on the MCU to the Max like it looks like it should be but what or how do tell the MCU which pins do what in the sketch? The example sketch shows pins 10, 11, 12, 13 as the SPI pins but I dont think thats correct. Please help.
What sketch and what hookup?
#include <Wire.h>
// #include <Adafruit_Sensor.h>
// #include <Adafruit_BMP085_U.h>
#include "ESP8266WiFi.h"
#include "Adafruit_MAX31865.h"
char myWifiName[] = "vsat-24g-98B94C";
char myWifiPassword[] = "3uqokfa61xsne950";
long tsLastScan;
long tsStartConnect;
long tsLastConnectCheck;
long tsLastNOOP;
long tsLastBMP;
long tsLastRTD;
bool bConnecting;
bool bConnected;
bool bBMP;
// Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);
// Use software SPI: CS, DI, DO, CLK
Adafruit_MAX31865 mymax = Adafruit_MAX31865(10, 11, 12, 13);
// The value of the Rref resistor. Use 430.0 for PT100 and 4300.0 for PT1000
#define RREF 4300.0
// The 'nominal' 0-degrees-C resistance of the sensor
// 100.0 for PT100, 1000.0 for PT1000
#define RNOMINAL 1000.0
//void displaySensorDetails(void) {
// sensor_t sensor;
// bmp.getSensor(&sensor);
// Serial.println("------------------------------------");
// Serial.print ("Sensor: "); Serial.println(sensor.name);
// Serial.print ("Driver Ver: "); Serial.println(sensor.version);
// Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id);
// Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" hPa");
// Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" hPa");
// Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" hPa");
// Serial.println("------------------------------------");
// Serial.println("");
// delay(500);
//}
void setup() {
Serial.begin(115200);
Serial.println("test");
// Set WiFi to station mode and disconnect from an AP if it was previously connected
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(2000);
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
pinMode(0, OUTPUT);
// // Initialize the pressure sensor
// bBMP = 0;
// if(!bmp.begin()) {
// /* There was a problem detecting the BMP085 ... check your connections */
// Serial.println("No BMP085 detected.");
// } else {
// Serial.println("BMP online.");
// bBMP = -1;
// }
// Initialize the Pt1000
mymax.begin(MAX31865_3WIRE); // set to 2WIRE or 4WIRE as necessary
// Initialize global variables: timestamps and status holders
tsLastScan = millis();
Serial.print(millis());
Serial.println("ms");
tsStartConnect = 0;
tsLastNOOP = millis();
bConnecting = 0;
bConnected = 0;
Serial.println("Setup done");
// displaySensorDetails();
}
void loop() {
// Initialize sensor output variable.
uint16_t rtd = mymax.readRTD();
if (((millis() - tsLastScan) > 5000) && !bConnecting && !bConnected) {
digitalWrite(LED_BUILTIN, LOW); // Turn the LED on (Note that LOW is the voltage level
digitalWrite(0, HIGH); // Turn the LED on (Note that LOW is the voltage level
Serial.println("scan start");
int n = WiFi.scanNetworks();// WiFi.scanNetworks will return the number of networks found
Serial.println("scan done");
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
digitalWrite(0, LOW); // Turn the LED off by making the voltage HIGH
if (n == 0)
Serial.println("no networks found");
else
{
Serial.print(n);
Serial.println(" networks found");
for (int i = 0; i < n; ++i)
{
// Print SSID and RSSI for each network found
Serial.print(i + 1);
Serial.print(": ");
Serial.print(WiFi.SSID(i));
Serial.print(" (");
Serial.print(WiFi.RSSI(i));
Serial.print(")");
Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*");
delay(10);
if (WiFi.SSID(i) == myWifiName) {
Serial.println("Match found.");
WiFi.begin(myWifiName, myWifiPassword);
bConnecting = -1;
tsStartConnect = millis();
tsLastConnectCheck = millis();
Serial.print("Connecting");
}
}
}
Serial.println("");
tsLastScan = millis();
Serial.print(millis());
Serial.println("ms");
}
if (bConnecting && (millis() - tsLastConnectCheck > 500)) {
if (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
Serial.print(WiFi.status());
} else {
Serial.println("Connected.");
bConnected = -1;
bConnecting = 0;
}
tsLastConnectCheck = millis();
if (millis() - tsStartConnect > 30000) {
WiFi.disconnect();
Serial.println("Connection failed.");
tsLastScan = millis();
bConnected = 0;
bConnecting = 0;
}
}
if (bConnected && (millis() - tsLastNOOP > 10000)) {
Serial.print("Connected, IP address: ");
Serial.println(WiFi.localIP());
if (WiFi.status() != WL_CONNECTED) {
Serial.println("Lost Connection.");
WiFi.disconnect();
bConnected = 0;
bConnecting = 0;
tsLastScan = millis();
}
tsLastNOOP = millis();
}
/* END CONNECTION STUFF
*
* SWITCH TO SENSOR STUFF
*
*
*/
// Get RTD reading.
if (millis() - tsLastRTD > 5000) {
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(mymax.temperature(RNOMINAL, RREF));
// Check and print any faults
uint8_t fault = mymax.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");
}
mymax.clearFault();
}
Serial.println();
tsLastRTD = millis();
}
// if (bBMP && (millis() - tsLastBMP > 5000)) {
// sensors_event_t event;
// bmp.getEvent(&event);
//
// if (event.pressure) {
// Serial.print("Pressure: ");
// Serial.print(event.pressure);
// Serial.println(" hPa");
//
// float temperature;
// bmp.getTemperature(&temperature);
// Serial.print("Temperature: ");
// Serial.print(temperature);
// Serial.println(" C");
//
// float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;
// Serial.print("Altitude: ");
// Serial.print(bmp.pressureToAltitude(seaLevelPressure, event.pressure));
// Serial.println(" m");
// Serial.println("");
// } else {
// Serial.println("Sensor error");
// }
//
// tsLastBMP = millis();
// }
delay(10);
}
Once you’ve decided how you want to connect your sensor, you real problem will be the structure of this code and all that stuff in the void loop.
Before you start adding-in all of the required Blynk libraries and code you should read this:
Pete.