Blank code insertion point

I have a sketch that reads a temperature from an RTD connected to a MAX31865 RTD to Digital Converter. The MAX31865 is connected to an ESP8266 NodeMCU and the code I downloaded to the ESP8266 allows for the temperature in °F to be read via Serial Monitor.

Where I am confused is the Blynk instruction telling me to “open their example sketch, change it to my hardware and connection, insert token and “FLASH” the sketch to my ESP8266”

Question: If I have a sketch currently running on my ESP8266 that is successfully displaying the °F temperature on the Serial Monitor, wouldn’t “FLASHING” the Blynk code (above) overwrite my code currently running that is displaying the temperature on the ESP8266 ?

Nah,
You need to edit your code (the one running on your esp) and add Blynk specific code and libraries:

#include <ESP8266WiFi.h>  // for ESP8266
#include <BlynkSimpleEsp8266.h>  // for ESP8266
#include <Adafruit_MAX31865.h>

// Use software SPI: CS, DI, DO, CLK
Adafruit_MAX31865 max = Adafruit_MAX31865(10, 11, 12, 13);
// use hardware SPI, just pass in the CS pin - this is for Arduino, change for ESP
//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
char auth[] = "xxxxxxxxxx";
char ssid[] = "xxxxx";
char pass[] =“xxxxx”;
uint16_t rtd = 0.0;

void setup(){
  max.begin(MAX31865_3WIRE);  // set to 2WIRE or 4WIRE as necessary
  Blynk.config(auth);
  timer.setInterval(2000L, myFunc);
}

void myFunc(){
  //your code to retrive data from RCD...
  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));
}

void loop() {
  Blynk.run();
  timer.run();
}

EDIT: added timer in setup

So, if I follow correctly, I simply add:

#include <ESP8266WiFi.h> // for ESP8266
#include <BlynkSimpleEsp8266.h> // for ESP8266 char auth[] = “xxxxxxxxxx”;
char ssid[] = “xxxxx”;
char pass[] =“xxxxx”;

before the Void Setup() in my sketch where my other libraries are declared.

Then, add:
Blynk.run();
timer.run();
anywhere in the Void Loop() code of the loop currently running in the ESP8266

Finally, where is your code:

Void myFunc(){ //your code to retrive data from RTD
}

fitted into my sketch? I’m not sure of what “myFunc” means and what exactly goes there.

Well, yes… you need to add the libs on top of your sketch. A little below that you add the ssid, pass, auth,… than you need to setup the timer (in the setup func) that calls your myFunc function.
Check THIS post from @Gunner and try to implement it in your code. Check the void loop()… you’ll notice that there are only 3 lines (you don’t need OTA to start with coding) and put all the code regarding your RTD in myFunc.
Read a little through the docs, try with writing some code, upload to esp and if it doesn’t work, post your code here and ask for hints :slight_smile: to make it work

The ONLY thing on your void loop should be:

Blynk.run();
timer.run();

All of your existing code, which is used to take the temperature measurements, should be in a function of it’s own (in the example called “myFunc()”. If you have any delay() statements in there to control the frequency of the temperature readings then these need to be removed.

The other thing that’s missing from @ericssson’s code is code to set up a timer.
This belongs in your void setup and will look like this:

 timer.setInterval(1000L, myFunc);

This will call your temperature reading function once every second. You can adjust this time to suit your needs.

I’m guessing that you’ll also want to send the data from the temperature readings to a display widget in Blynk, this can be done within the myFunc function, using a Blynk.virtualWrite command to send the data to the virtual pin that your display widget is attached to.

Pete.

does that mean you have something else in your loop?

your loop should look like this, that’s all

void loop() {
  Blynk.run();
  timer.run();
}

please post your full sketch

I think so, I think that he used just a standard Arduino sketch so he has to edit it completely…
And yes @PeteKnight I have forgoten to add the timer in the setup as I’m on my phone but did mention it in my second post :blush: (edited my first post)
Second edit: added the MAX code… try it first as I’m still on my phone :smile: :nerd_face:

1 Like

I’m very sorry for just now posting the code for the BBQ Pit Temp sketch. I replied to the email notifying me of a response rather than to the community.

/***************************************************
  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(14);

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


void setup() {
  Serial.begin(9600);
  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 C= ");
  // Serial.println(max1.temperature(100, RREF));
  Serial.print("BBQ Pit Temperature F  = ");
  Serial.println(((max1.temperature(100, RREF))*1.8) + 32);
  /*  // 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);
}