My temp reading from MAX6675 isnt refrashing

Im using Wemos D1 mini, max6675, Android and Blynk server.

In both Serial Monitor and thru Blynk app I can read the temperature but it doesn’t refresh.
Any help appropriated.

#define BLYNK_PRINT Serial   
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <max6675.h>
#include <SPI.h>
char auth[] = "";
char ssid[] = "";
char pass[] = "";

int thermoDO = D6;
int thermoCS = D8;
int thermoCLK = D5;
int LED = D1; 
MAX6675 thermocouple; 


void setup() {
  Serial.begin(9600);
   pinMode(LED, OUTPUT); 
   thermocouple.begin(thermoCLK, thermoCS, thermoDO);
  Blynk.begin(auth, ssid, pass);
}

//--------------------------
BLYNK_READ(V4){

  Blynk.virtualWrite(V4, thermocouple.readFahrenheit());
  }
  
//---------------------------
BLYNK_WRITE(V3) {
 int pinValue = param.asInt(); // Assigning incoming value from pin V3 to a variable
 if (pinValue == 1) {
    digitalWrite(LED, HIGH); // Turn LED on.
  } else {
    digitalWrite(LED, LOW); // Turn LED off.
 }
}

//--------------------------
void loop(){
  Blynk.run();
  Serial.print("F = ");
   Serial.println(thermocouple.readFahrenheit());
   delay(100);
}

Keep your void loop() clean

And use timers for periodically refreshing the data

Can you take a look at my code, My temp. still dose not change in serial and stays at 73.4 in the blynk app.


    #include <ESP8266WiFi.h>
    #include <BlynkSimpleEsp8266.h>
    #include "max6675.h"
    #include <SPI.h>

    char auth[] = "";
    char ssid[] = "";
    char pass[] = "";

    BlynkTimer timer; // Create a Timer object called "timer"! 

    int thermoDO = D6;
    int thermoCS = D8;
    int thermoCLK = D5;
    int LED = D1; // Define LED as an Integer (whole numbers) and pin D8 on Wemos D1 Mini Pro
    int sensorValue;
    MAX6675 thermocouple;

    //-------------------
    void setup() {
      Serial.begin(9600);
      Blynk.begin(auth, ssid, pass);
      timer.setInterval(1000L, myTimerEvent);
       pinMode(LED, OUTPUT); //Set the LED (D1) as an output
       thermocouple.begin(thermoCLK, thermoCS, thermoDO);
    }
       
     
    //--------------
    void myTimerEvent()
    {
      sensorValue = thermocouple.readFahrenheit();         // reading sensor from analog pin
      Blynk.virtualWrite(V4, sensorValue);
    }
      
    //---------------------------
    BLYNK_WRITE(V3) {
     int pinValue = param.asInt(); // Assigning incoming value from pin V3 to a variable
     if (pinValue == 1) {
        digitalWrite(LED, HIGH); // Turn LED on.
      } else {
        digitalWrite(LED, LOW); // Turn LED off.
     }
    }

    //--------------------------
    void loop(){
      Blynk.run();
      timer.run(); // BlynkTimer is working...
      Serial.print("F = ");
      Serial.println(thermocouple.readFahrenheit());
       
    ```

Try using the preferred Arduino pin designations… the Dpin options are not always recognized correctly.

1 Like
int xSO = 12; //D6;               // SO pin of MAX6675
int xCS = 13; // D7;               // CS pin on MAX6675
int xNCK = 15; //D8;              // SCK pin of MAX6675 (variable SCK cannot be used reserved for RTC)
int LED = D1; // Define LED as an Integer (whole numbers) and pin D8 on Wemos D1 Mini Pro

its the same

Well, I don’t know… nor am I going to dig through your code line by line… i am working on my own projects :wink:

But I just noticed that your void loop() still has invalid info trying to run thousands of times a second.

Take your serial prints and put them in the same function that reads the sensor in the first place… called by a timer of course.

Then if you still see something on the serial monitor, but it never changes… start double checking your sensor read commands, etc. for any issues.

If you DON’T see serial info, then something might be wrong in the entire timed function (not being called from the timer?)

Only you can troubleshoot it properly.

OK I got it to work, their where several small bugs in the code.
btw this is my first project with blynk and SPI.

Thanks for the tips.

Also uploaded the code as reference for anyone who is doing something similar.


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <max6675.h>
#include <SPI.h>

char auth[] = "auth code here";
char ssid[] = "wifi name";
char pass[] = "wifi pass";

BlynkTimer timer; // Create a Timer object called "timer"! 

int xSO = D7;         // SO pin of MAX6675
int xCS = D8;         // CS pin on MAX6675
int xNCK = D5;        // SCK pin of MAX6675

MAX6675 temp;


void myTimerEvent() {
  temp.begin(xNCK, xCS, xSO);
  Blynk.virtualWrite(V4, temp.readFahrenheit());
  delay(100);
  Serial.print("F = ");
  Serial.println(temp.readFahrenheit());
}


void setup() {
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, myTimerEvent);
}
    
void loop(){
  Blynk.run();
  timer.run(); // BlynkTimer is working...
}



2 Likes

but why delay?

Forgot to delete that, delay is not needed.

1 Like