Maybe I just don’t know how to use it. First time Blynk user here.
TLDR; ESP8266 with a MAX6675 sensor. Temp reporting fine with a V0 and V1 pins. But when I define the Units on the datastream to be Fahrenheit it converts to C…which makes no sense… the code is sending the value in F.
Thanks for the quick reply. I been breaking my head. The same call ktc.readFahrenheit() reports correctly if I remove the unit on the datastream. I’m attaching a screenshot of the datastreams definition. Like I said. first time using Blynk.
Yep both the Serial and the OLED connected are displaying right… just the Blynk…
18:29:34.271 -> C = 22.75 F = 72.95
18:29:34.271 -> C = 23.00 F = 73.40
18:29:35.201 -> C = 22.75 F = 72.95
18:29:36.297 -> C = 22.50 F = 72.50
18:29:37.390 -> C = 22.50 F = 72.50
You are also taking readings and storing them in the variables DC and DF, but then you aren’t using these variables again. Instead, you’re repeatedly taking new readings. This is the wrong approach.
When you move all of this junk out of your void loop and into a function that’s called with a BlynkTimer (and of course delete the delay command) you should structure the function so that you take readings at the beginning of this function and store them in variables, then use these variables when you send the values to the serial monitor, LCD and Blynk.
Well… I’m no expert but I tried to follow your advice and based on the great post you did Using BlynkTimer or SimpleTimer and this is the current status…
#define BLYNK_PRINT Serial
#include <Blynk.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <max6675.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_TEMPLATE_NAME ""
#define BLYNK_AUTH_TOKEN ""
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
char auth[] = ""; // You should get Auth Token in the Blynk App.
char ssid[] = ""; // Your WiFi credentials.
char pass[] = "";
int ktcSO = 12;
int ktcCS = 13;
int ktcCLK = 14;
MAX6675 ktc(ktcCLK, ktcCS, ktcSO);
// This function creates the timer object. It's part of Blynk library
BlynkTimer timer;
void getTemp()
{
float DC = ktc.readCelsius();
float DF = ktc.readFahrenheit();
Blynk.virtualWrite(V0, DC);
Blynk.virtualWrite(V1, DF);
Serial.print("C = ");
Serial.print(DC);
Serial.print("\t F = ");
Serial.println(DF);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(20, 0);
display.print("Temperature");
display.setTextSize(2);
display.setCursor(10, 20);
display.print(DC);
display.print((char)247);
display.print("C");
display.setTextSize(2);
display.setCursor(10, 45);
display.print(DF);
display.print((char)247);
display.print("F");
display.display();
}
void setup()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
timer.setInterval(5000L, getTemp);
display.begin(SSD1306_SWITCHCAPVCC, 0x3c); //initialize with the I2C addr 0x3C (128x64)
delay(500);
display.clearDisplay();
display.setCursor(25, 15);
display.setTextSize(1);
display.setTextColor(WHITE);
display.println(" Thermometer");
display.setCursor(25, 35);
display.setTextSize(1);
display.print("Initializing");
display.display();
delay(3000);
}
void loop()
{
timer.run(); // call the BlynkTimer object
Blynk.run(); // perform a handshake with the Blynk server
}
And unfortunately I’m still getting the same results. I’m attaching a side by side photo of the lcd and the blynk on the phone. This photo is with No Units defined on the Datastream V1. It shows the right value… I tried with setInterval 1sec and 5sec. Same result.