ESP8266 + ValueDisplayS. What is a right code?

I use ESP & I2C temperature sensor IC.
At 1st, I’m not sure how to use ValueDisplayS in detail. ex) meaning of wire mark, frequency,…
I read many web site and now, temperature is displayed.

But there is one issue.

Serial.println(temperture);
Blynk.virtualWrite(V1, temperture);

I connect V1 to Display, and upper code is called 3sec each.

Serial.println(temperture);

prints right value of temperature. But on the BLynk’s display, right valu -> fixed non-correct value -> right value…

I changed, frequency or wire mark and more, nothing is changed.
I’m not sure who write the data? Blynk get ? ESP push ?
I guess when

Blynk.virtualWrite(V1, temperture);

is done, BLYNK’s display value is OK, but BLYNK over write another value.

Who knows the resolution ?

@yuji the incorrect values are almost certainly coming from your sketch. So we would need to see your sketch, correctly formatted, to fix your problem.

What frequency did you set for the Value Display and are you saying you have a 3 second loop for the virtualWrite?

If you have a timed loop then you should just use PUSH for the frequency as your timed loop can interfere with any Blynk frequency not set as PUSH. You may know that it takes time to read a temperature sensor and it can be a very long time (up to 750ms). So a 3 second sketch loop and say a 3 second Blynk frequency can clash with the 750ms read time, hence you get a good reading, bad reading, good reading etc.

Thank you for repl.

All sketch is so long, so I write main loop only.


void loop ( )
{

// server or Blynk mode
if (serverMode == 1) {
server.handleClient();
} else {
Blynk.run();
}

// Blynk command
BlkPinNew = digitalRead(BLKIN_PIN);
if ((BlkPinNew ^ BlkPinOld)) {
if (digitalRead(BLKIN_PIN) == HIGH) {
irsend.sendRawOn(&results);
} else {
irsend.sendRawOff(&results);
}
BlkPinOld = BlkPinNew;
}

ESP.wdtDisable();

// Temperture
String temperture;
if (WaitCntr1 == 0xfff) {
Wire.requestFrom(0x48, 1); // request 2 bytes from slave device #0x48

while (Wire.available())    // slave may send less than requested
{
  char c = Wire.read();     // receive a byte as character

  if (c > 127) {
    c = (256 - c);
    int temp = (int)c;
    temperture = (String)temp;
    temperture = "-" + temperture + " ℃";
  } else {
    int temp = (int)c;
    temperture = (String)temp;
    temperture = temperture + " ℃";
  }
  Serial.println(temperture);
  Blynk.virtualWrite(V1, temperture);
}
WaitCntr1 = 0;

} else {
WaitCntr1++;
delay(1);
}

// IR test
if (digitalRead(MODE_PIN) == LOW) {
delay(50);
if (digitalRead(MODE_PIN) == LOW) {
if (IRtestSW == 0) {
Serial.println(“2”);
irsend.sendRawOn(&results);
IRtestSW = 1;
delay(500);
} else {
Serial.println(“3”);
irsend.sendRawOff(&results);
IRtestSW = 0;
delay(500);
}
}
}
}

My Blynk setting have 1 button & 1display.
Blynk itself moves well.

What frequency did you set for the Value Display

now, “push”.

are you saying you have a 3 second loop for the virtualWrite?

As the sketch, I use wait counter.(WaitCntr1) now limit is 0xfff & delay(1) ==> almost 3sec. this will be changed slower.

If you have a timed loop then you shoul~

Sorry, it’s difficult for me. I’m not sure frequency. What for ?

issues example:
25deg,29deg,25deg,29deg…
between 25deg and 25deg is 3sec and right temperature on the phone display.
When i use cold spray, 10deg, 29,deg, 12,deg,29,deg…like this. sometimes not 29 but 28.
On the serial monitor, . 25, 25, 25, 25 … 3sec interval.

regards,

Edit your last post, select the text relating to the sketch and then press the </> button so we can read it.

Normally a “Blynk loop” has just 2 lines of code:

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

Sorry I couldn’t.
I attached as a jpg file.

I add timer.run(); but error.


IRrecvWROOM.ino: In function ‘void loop()’:
IRrecvWROOM:388: error: ‘timer’ was not declared in this scope
Multiple libraries were found for “BlynkSimpleEsp8266.h”

Used: C:\Users\SilBurg\Documents\Arduino\libraries\blynk-library-master

Not used: C:\Users\SilBurg\Documents\Arduino\libraries\Blynk

‘timer’ was not declared in this scope

A Blynk sketch is generally nothing like an Arduino sketch because Arduino’s aren’t connected to internet servers.

See https://github.com/blynkkk/blynk-library/blob/master/examples/GettingStarted/PushData/PushData.ino for how to use Timers with Blynk then modify your sketch to have 2 lines in the loop.

Delays should be avoided in Blynk sketches as during the delay you might be disconnected from the server. It will depend how you structure your code but normally delays should be less than a few hundred ms. If you have bad code, continuous looping, even delay(1) will fail.

You need to use the most basic Blynk sketch with just the temperature sensor and when this works add all your other (IR) stuff etc.

Now I use timer (1sec interval). Nicer code.
But nothing is changed.
Incorrect value is displays. Serial .print value is OK too.

BTW, I wrote the code seeing
http://docs.blynk.cc/#blynk-firmware-virtual-pins-control-blynkvirtualwritevpin-value

so my code is

Serial.println(temperture);
Blynk.virtualWrite(V1, temperture);

what the 2nd value mean below ?

Blynk.virtualWrite(V5, millis() / 1000);

And I understand using delay() breaks the connection, Thank you.
500msec delay moves only for test.

And around here, Blynk moves perfectly via server. (using button).

// Blynk command
BlkPinNew = digitalRead(BLKIN_PIN);
if ((BlkPinNew ^ BlkPinOld)) {
if (digitalRead(BLKIN_PIN) == HIGH) {

In addition.
I checked iOS and Android both.
This issue is iOS only (iPhone5s).

@yuji I think you were asking what the second value is in Blynk.virtualWrite(V5, millis() / 1000).

millis() is simply the running time of the MCU in milliseconds so millis() / 1000 is running time in seconds. Blynk use it in their PushData example as an easy way to have a ValueDisplay increment by 1 every second (as the timer is at 1 second, 1000L, intervals). You could use an incrementing counter rather than millis() but based on using the SimpleTimer it is the shortest possible code, that I know of, to demonstrate pushing data.

I don’t use iPhone’s so if Android works and iPhone doesn’t it suggests a bug in the iPhone version.

You need to provide a full sketch, as short as possible, to demonstrate the problem, so the Blynk guys can take a look at it.

1 Like

Here is video what I mean.

And here is code (sorry for jpg)

This function is called 1 sec interval by timer.

I check I2C pulse, Connection is 1 sec interval too.

I think iOS bug.

Nice video but we will need to see a full sketch to see which libraries you are using etc.

Are you not able to cut and paste the most basic sketch that shows the false temperatures?

don’t use jpg for code. It makes it unusable for others.

Just follow these instructions:

Wrap the code by adding 3 Backtick: ``` symbols:

Example:

 ``` cpp <--put 3 backticks BEFORE your code starts  (cpp means C++ language) 

   //Put your code here
   //..................
   //..................

 ``` <--insert 3 backticks AFTER your code

**This makes your code readable and with highlighted syntax, like this:**
//comment goes here 
void helloWorld() { 
   String message =  "hello" + "world"; 
}

I’ll paste the code, but without above code, I guess it’s not concern with the issue.
Because I2C and BlynkvertualWrite() is only inside this 1sec timer function.
All code is so long. Above code is the most basic sketch.

void myTimerEvent()
{
  // Temperture
  String temperture;
  Wire.requestFrom(0x48, 1);  // request 2 bytes from slave device #0x48

  while (Wire.available())    // slave may send less than requested
  {
    int c = Wire.read();     // receive a byte as character

    if (c > 127) {
      c = (256 - c);
      temperture = (String)c;
      temperture = "-" + temperture + " ℃";
    } else {
      temperture = (String)c;
      temperture = temperture + " ℃";
    }
    
 Serial.println(temperture);
    Blynk.virtualWrite(V1, temperture);
  }
}

//+=============================================================================
// Set Up
//

void  setup ( )
{
  results.rawbuf = rawbuf;
  results.rawlen = rawBufLength1;

  Serial.begin(57600);                         // Status message will be sent to PC at 9600 baud

  SPIFFS.begin();                              // resume file system.

  pinMode(CHK_LED, OUTPUT);
  pinMode(MODE_PIN, INPUT);

  // Server or Cliant mode or IR get mode
  if (digitalRead(MODE_PIN) == LOW) {
    delay(3000);
    if (digitalRead(MODE_PIN) == LOW) {
      setup_server();                         // config as server mode
      serverMode = 1;
    } else {
      irrecv.enableIRIn();                      // Start the receiver
      digitalWrite(CHK_LED, HIGH);
      delay(200);
      digitalWrite(CHK_LED, LOW);

      while (!(irrecv.decode(&results) == 1)) { // Grab an IR code
        delay(10);
      }
      irrecv.disableIRIn();
      dumpRaw(&results);                        // Output the results in RAW format
      irrecv.resume();
      Serial.println("");                      // Blank line between entries
    }
  } else {
    setup_client();                           // congfig as cliant mode
    const char *t = token.c_str();
    const char *s = ssid.c_str();
    const char *p = pass.c_str();
    Blynk.begin(t, s, p);
    readback(&results);
    irsend.begin();       // Start the sender
  }
  irrecv.disableIRIn();

  Wire.begin();
  Wire.beginTransmission(0x48);
  Wire.write(0);
  Wire.endTransmission();

  pinMode(CTRL_PIN, OUTPUT);
  pinMode(BLKIN_PIN, INPUT);
  pinMode(SEND_PIN, OUTPUT);
  digitalWrite(SEND_PIN, LOW);

  // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);

  ESP.wdtDisable();
}

//+=============================================================================
// The repeating section of the code
//
char BlkPinNew = 0;
char BlkPinOld = 0;
int WaitCntr1 = 0;
char IRtestSW = 0;

void  loop ( )
{

  // server or Blynk mode
  if (serverMode == 1) {
    server.handleClient();
  } else {
    Blynk.run();
    timer.run(); // Initiates SimpleTimer
  }

  // Blynk command
  BlkPinNew = digitalRead(BLKIN_PIN);
  if ((BlkPinNew ^ BlkPinOld)) {
    if (digitalRead(BLKIN_PIN) == HIGH) {
      irsend.sendRawOn(&results);
    } else {
      irsend.sendRawOff(&results);
    }
    BlkPinOld = BlkPinNew;
  }

  ESP.wdtDisable();

  // IR test
  if (digitalRead(MODE_PIN) == LOW) {
    delay(50);
    if (digitalRead(MODE_PIN) == LOW) {
      if (IRtestSW == 0) {
        Serial.println("2");
        irsend.sendRawOn(&results);
        IRtestSW = 1;
        delay(500);
      } else {
        Serial.println("3");
        irsend.sendRawOff(&results);
        IRtestSW = 0;
        delay(500);
      }
    }
  }
}

Thank you Pavel.
Unfortunately, there is not the character on Japanese keyboard :slight_smile:
I copied your charactor.

I use many lib.

#include <IRremoteESP8266.h>
#include <FS.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <EEPROM.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h>
#include <SimpleTimer.h>

You can see the wrong value comes suddenly (compare with 1 sec interval).
As I wrote,

  • I2C is 1sec interval
  • Serial.print() shows 1 sec interval and the value is correct.

where / when comes the wrong data on iOS ?

Shall I tell to Blynk guys as bug ?
Blynk app is latest version.

HI,

I guess I took you enough info & sketch.
I’m waiting for answer with inside Blynk guys.

Need to analyze WiFi data ?
I can do.
But I suppose this is BUG in Blynk.

Is your widget in PUSH mode?

Yes, push mode finally.
I tried another mode, nothing is change.

Thank you for repl.