Time widget behaves strange [iOS]

Hi,
I’m getting strange behavior on my Timer widget. I am running Blynk cloud and using it on iOS (all lastest versions).

I am using Timer widget to turn servo via NodeMCU with code below. Device does more things than just turning servo but it should not be the issue. When I turn servo with slider or button it works great but when I set up timer widget it just turn it to value 39 and it does not matter how I configure it and it does the same on Timer end or start.

Is it a bug or am I doing someting wrong?

#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Servo.h>
#include <OneWire.h>
#include <DallasTemperature.h> 
#include <SimpleTimer.h>
SimpleTimer timer;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "12345678987654321234";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "SSID";
char pass[] = "pass";

Servo servo;
BLYNK_CONNECTED(){
Blynk.syncAll();
}
BLYNK_WRITE(V3) // Slider set to Vx and to range 0-180
 {
  servo.attach(2);   // Attach Servo
   // Get slider value
  servo.write(param.asInt());  // Move servo to value
  delay(800);  // Set minimum delay for servo to reach desired position, keep as low as possible.
 
  
  servo.detach();   // Detach Servo - NOTE servo pin designation not required for detach
} // END Blynk Function


/* DS18B20 Temperature Sensor */
#define ONE_WIRE_BUS 9 // pin temperature set
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
float temp;

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
  DS18B20.begin();
  timer.setInterval(1000L, getSendData);
  pinMode(2, OUTPUT); 
}

void loop()
{
  Blynk.run();
  timer.run();
  digitalWrite(2, HIGH); //disables pesky blue diod
}

/***************************************************
 * Send Sensor data to Blynk
 **************************************************/
void getSendData()
{
  DS18B20.requestTemperatures(); 
  temp = DS18B20.getTempCByIndex(0);
  Serial.println(temp);
  Blynk.virtualWrite(10, temp); //virtual pin V10
  int pos = servo.read();
  Blynk.virtualWrite(4, pos); 
}

Probably a timing issue. Your timer is set to run every second (1000 ms):

timer.setInterval(1000L, getSendData);

This puppy requires about 800 ms to finish:

DS18B20.requestTemperatures();

With everything else going on, that might be too long before the timer want to start over again and it will normally generate strange behavior :smile:

I would use two timers, one for the temp and one for whatever int pos = servo.read(); does.

To avoid unnecessary delays when fetching the temperature, you could
use DS18B20.setWaitForConversion(0); to speed things up. It requires some coding, I’ve written about it many times so just search the forum :slight_smile: or look at my old project: Cheap(est) RF 433 Mhz bridge for home automation with both Tx and Rx

Can’t you set this once and for all during setup?

digitalWrite(2, HIGH);

You don’t need to do this thousands of times a second :stuck_out_tongue: once in setup is just fine.

Either you are mixing up Timer Widget with BlynkTimer, or you are using the wrong tool for the job… or at very least wrong way to use it.

Call a BLYNK_WRITE(vPin) Function with it, then that uses code to move the servo one way or the other based on the timers HIGH or LOW input.

It is for feeding SuperChart with position value because it can’t read constantly (only on change and it doesn’t draw nice graph) from V3 pin which i use to set postion. But I set another timer for that and Timer widget is still malfunctioning even when i remove this part completely.

Actually I do because this LED is hardwired to someting inside NodeMCU and every time servo turns it leaves LED on. But I’ve moved this under Servo servo; and works just fine.

I want to use Timer Widget to turn servo at position calling BLYNK_WRITE(vPin) at desired time given the setting of the widget. But now when I use it it ignores values in the app (see pic below) and just set value to 40 or 39. Documentation says that I can send any value not just HIGH or LOW. Control with button or slider in app works great.

NO, you shouldn’t need to. What was happening is becasue of something else you had done. GPIO2 is hardwired to the built in LED and a Pull Up resistor, thus the LED is active LOW.

You are trying to use that same pin for the servo as well, thus your issues… probably with both LED and servo.

Move the servo to another pin! Start with the Green = Safe pins

Thanks, I didn’t know that. LED is turned off now all the time just with lines at setup

So I moved servo to GPIO 5 and temperature sensor to GPIO 4 but Timer Widget still doesn’t behave OK. Still the same issue.

Doesn’t even work when I strip the code only to servo control like this:

#include <BlynkSimpleEsp8266.h>
#include <Servo.h>

#define BLYNK_PRINT Serial


char auth[] = "1b30ab9c1beb4b189117df2a450fce9d";
char ssid[] = "Krteckovo Kvarteto";
char pass[] = "cervenytrenky";

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  
  
}

/* servo moving */
Servo servo;
BLYNK_CONNECTED(){

}
BLYNK_WRITE(V3) // Slider set to Vx and to range 0-180
 {
  servo.attach(4);   // Attach Servo
   // Get slider value
  servo.write(param.asInt());  // Move servo to value
  delay(800);  // Set minimum delay for servo to reach desired position, keep as low as possible.
 
  
  servo.detach();   // Detach Servo - NOTE servo pin designation not required for detach
 
} // END Blynk Function


void loop()
{
  Blynk.run();


}

Any ideas?

Is this comment just a red herring? Is this your timer widget?

Pete.

I’ve been replying to @Gunner about the LED issue which might be relevant to Timer Widget issue but as it turns out it isn’t. Then I’ve simplyfied code just to turn servo to eliminate other interferences but it generates still the same issue.

Sorry, not quite sure what happened to the single line of text I was trying to quote. Fixed my previous post now.

Basically, I was trying to make sense of your code and the mention of a slider widget on V3 was confusing me. Is this comment just a red herring?

Pete.

Yeah, that comment is old and doesn’t make sense anymore and is confusing. Sorry about that.

This line brings value from blynk app to the nodeMCU on V3. On my App I now control this with buttons (pre set values) and slider (value I want to - especially for testing) without problem. And I want to control it also with Timer widget but that fails.

To underestand this whole set-up. It is simple “IoT servo” that is glued onto knob on my home thermostat (easy but works). So that is the reason why I want so many different ways to set servo position.

Try throwing some Serial.print commands into your BLYNK_WRITE(V3) function to see what data is coming from your widget and when.

Pete.

Not with the Timer Widget, only with the Eventor Timer.

image

And this will test that validity.