My thermocouple works when a simple script is uploaded, however, when using the edgent example script it reads O deg C or 32 deg F. I don’t understand why it works with the simple Max6675 test script but not in edgent.
ESP32 with Max6675 and thermocouple
NY, USA
Blynk Library version 1.3.2
Serial output prints 0 as the temperature.
#define BLYNK_TEMPLATE_NAME "Temperature Sensor Network"
#define BLYNK_FIRMWARE_VERSION "0.2.0"
#define BLYNK_PRINT Serial
#define APP_DEBUG
#define USE_ESP32C3_DEV_MODULE
#include "BlynkEdgent.h"
#include <max6675.h>
#include <esp_sleep.h>
#include <SPI.h>
float temperature = 1.1;
// Blynk virtual pins
#define VPIN_TEMPERATURE V0
#define VPIN_SLEEP_TIME V1
#define SCK_PIN 10 // Clock pin
#define MISO_PIN 8 // Data output (MISO)
#define MOSI_PIN -1 // Not used by MAX6675
#define CS_PIN 9 // Chip Select (CS)
MAX6675 thermocouple(SCK_PIN, CS_PIN, MISO_PIN);
// Global variable to store the sleep time in minutes
int sleepTimeMinutes = 0; // Default to 0 minutes
// Callback to update sleep time from Blynk
BLYNK_WRITE(VPIN_SLEEP_TIME) {
sleepTimeMinutes = param.asInt(); // Get the value from the Blynk app
Serial.println("Updated sleep time to " + String(sleepTimeMinutes) + " minutes.");
}
void sendDataToBlynk() {
temperature = thermocouple.readCelsius();
delay(250);
Serial.println("Temperature: " + String(temperature) + " °C");
Blynk.virtualWrite(VPIN_TEMPERATURE, temperature);
}
void waitForBlynkConnection() {
Serial.println("Waiting for Blynk connection...");
unsigned long startTime = millis();
const unsigned long timeout = 60000; // 60 seconds timeout
while (!Blynk.connected()) {
BlynkEdgent.run();
delay(100);
if (millis() - startTime > timeout) {
Serial.println("Blynk connection timeout. Proceeding without connection.");
break;
}
}
if (Blynk.connected()) {
Serial.println("Blynk connected successfully!");
} else {
Serial.println("Failed to connect to Blynk. Check your app setup.");
}
}
void deepsleep(){
Serial.println("Going to sleep for " + String(sleepTimeMinutes) + " minutes.");
delay(100);
// Convert minutes to microseconds for deep sleep
esp_sleep_enable_timer_wakeup(sleepTimeMinutes * 60 * 1000000);
if (sleepTimeMinutes != 0){
esp_deep_sleep_start();
}
else {
delay(15000);
}
}
void setup() {
Serial.begin(115200);
delay(100);
BlynkEdgent.begin();
Blynk.syncVirtual(VPIN_SLEEP_TIME);
// Wait for a Blynk connection before proceeding
waitForBlynkConnection();
}
void loop() {
BlynkEdgent.run();
// Send temperature data
sendDataToBlynk();
deepsleep();
}
It constantly reads 0 degrees. The sleep time works if I change the value in my web dashboard. No issues there, only with reading the temperature.
[103740] Connecting to WiFi: XXXXXXXX
[104768] Using Dynamic IP: 10.0.25XXXXX
[104768] CONNECTING_NET => CONNECTING_CLOUD
Temperature: 0.00 °C
Going to sleep for 0 minutes.
@aweltig Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your compiler error message and your code so that they display correctly.
Triple backticks look like this:
```
Copy and paste these if you can’t find the correct symbol on your keyboard.
// this example is public domain. enjoy!
// https://learn.adafruit.com/thermocouple/
#include "max6675.h"
int thermoDO = 8;
int thermoCS = 9;
int thermoCLK = 10;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
void setup() {
Serial.begin(9600);
Serial.println("MAX6675 test");
// wait for MAX chip to stabilize
delay(500);
}
void loop() {
// basic readout test, just print the current temp
Serial.print("C = ");
Serial.println(thermocouple.readCelsius());
Serial.print("F = ");
Serial.println(thermocouple.readFahrenheit());
// For the MAX6675 to update, you must delay AT LEAST 250ms between reads!
delay(1000);
}
Update: Using the Blynk library (not edgent) everything works as expected. Below is the code and serial monitor. So it seems to be something with the Edgent script that causes it. I’m not really sure what to do from here because I need Edgent to for my application.
#define BLYNK_TEMPLATE_ID "TMPL2xxxxxx"
#define BLYNK_TEMPLATE_NAME "Test Center Temperature"
#define BLYNK_AUTH_TOKEN "-3OjfEH-Kxxxxxxxxx"
#define BLYNK_PRINT Serial // Enables Serial Monitor
char ssid[] = "VAxxxxxx";
char pass[] = "Welcxxxxxx";
#include <max6675.h>
#include <esp_sleep.h>
#include <SPI.h>
#include <BlynkSimpleEsp32.h>
float temperature = 1.1;
// Blynk virtual pins
#define VPIN_TEMPERATURE V0
#define VPIN_SLEEP_TIME V1
#define SCK_PIN 10 // Clock pin
#define MISO_PIN 8 // Data output (MISO)
#define MOSI_PIN -1 // Not used by MAX6675
#define CS_PIN 9 // Chip Select (CS)
MAX6675 thermocouple(SCK_PIN, CS_PIN, MISO_PIN);
// Global variable to store the sleep time in minutes
int sleepTimeMinutes = 0; // Default to 0 minutes
// Callback to update sleep time from Blynk
BLYNK_WRITE(VPIN_SLEEP_TIME) {
sleepTimeMinutes = param.asInt(); // Get the value from the Blynk app
Serial.println("Updated sleep time to " + String(sleepTimeMinutes) + " minutes.");
}
void sendDataToBlynk() {
temperature = thermocouple.readCelsius();
delay(250);
Serial.println("Temperature: " + String(temperature) + " °C");
Blynk.virtualWrite(VPIN_TEMPERATURE, temperature);
}
void waitForBlynkConnection() {
Serial.println("Waiting for Blynk connection...");
unsigned long startTime = millis();
const unsigned long timeout = 60000; // 60 seconds timeout
while (!Blynk.connected()) {
Blynk.run();
delay(100);
if (millis() - startTime > timeout) {
Serial.println("Blynk connection timeout. Proceeding without connection.");
break;
}
}
if (Blynk.connected()) {
Serial.println("Blynk connected successfully!");
} else {
Serial.println("Failed to connect to Blynk. Check your app setup.");
}
}
void deepsleep(){
Serial.println("Going to sleep for " + String(sleepTimeMinutes) + " minutes.");
delay(100);
// Convert minutes to microseconds for deep sleep
esp_sleep_enable_timer_wakeup(sleepTimeMinutes * 60 * 1000000);
if (sleepTimeMinutes != 0){
esp_deep_sleep_start();
}
else {
delay(15000);
}
}
void setup() {
Serial.begin(115200);
delay(100);
Blynk.begin(BLYNK_AUTH_TOKEN,ssid,pass);
Blynk.syncVirtual(VPIN_SLEEP_TIME);
// Wait for a Blynk connection before proceeding
waitForBlynkConnection();
}
void loop() {
Blynk.run();
// Send temperature data
sendDataToBlynk();
deepsleep();
}
Temperature: 24.50 °C
Going to sleep for 0 minutes.
Temperature: 24.00 °C
Going to sleep for 0 minutes.
Temperature: 24.25 °C
Going to sleep for 0 minutes.
Temperature: 24.25 °C
Going to sleep for 0 minutes.
Temperature: 24.00 °C