Mine is not as complex, theres no video feed and I’m using a simple DC motor not a stepper.
The problem: I have a command to the motor telling it to activate. Then theres a setTimeout calling a command for it to stop. The function the motor command is in IS being called as I the serial.prints are coming through. If I take the motor on instruction and put it in void loop, it works.
I know the varTimer = pinValue is probably wrong but it was a way of taking the integer from one virtual pin and using it another function. The idea being the slider will define the timeout period.
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This sketch shows how to read values from Virtual Pins
App project setup:
Slider widget (0...100) on Virtual Pin V1
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include "WEMOS_Motor.h"
#include <SimpleTimer.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "token";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "ssid";
char pass[] = "password";
SimpleTimer timer;
int varTimer;
Motor M1(0x30,_MOTOR_A, 1000);//Motor A
// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin V1
BLYNK_WRITE(V1)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
Serial.print("V1 Slider value is: ");
Serial.println(pinValue);
varTimer = pinValue;
}
BLYNK_WRITE(V3)
{
{
if(param.asInt() == 0) {
FeedStart();
}
}
}
void FeedStart() // Rotate the rotor
{
M1.setmotor( _CW, 100);
Serial.print(" FEEDING ");
Serial.print(" for ");
Serial.println(varTimer);
timer.setTimeout(5000, FeedStop); //After 5 seconds call the FeedStop function
}
void FeedStop() // stop the rotor
{
M1.setmotor(_STANDBY);
Serial.println("END OF FEEDING ");
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}
void loop()
{
Blynk.run();
timer.run();
}
Yes its the wemos motor shield stacked on top of a D1 so all the headers are populated. Its a 12v motor connected to A1 and A2
V3 is a button in push mode. V3 gets updated on press and again on release so yes, when it goes back to 0 then FeedStart is called - which appears to be the case, I am getting the “FEEDING” message and the “END OF FEEDING” message 5 seconds later.
If I change V3 to a switch it calls FeedStart on the second press, which is consistent. The motor does not activate on either press.
Change the button to switch and the V3 if statement to == 1 just as a test.
Do you know what the 100 does in setMotor()? 100ms / 100 degrees etc.
If it’s 100ms then it would work in loop() as it keeps repeating but you probably wouldn’t notice a single 100ms movement from pressing V3.
Going back the the project I’m basing mine off - If I change the ode to the following it works as it should. Which is ok but it’d be better to know why it doesn’t work the other way…
void loop()
{
Blynk.run();
timer.run();
// get the man switch value
if (digitalRead(V3) > 0) // feeds and updates the hopper level/man trigger count on manual trigger
{
FeedStart();
}
}
I think it’s because you haven’t declared the timeout correctly but I would be more interested in starting the motor in the first place than stopping it.
For slider operation all you need to do is define a global variable:
int feedSeconds = 5;
BLYNK_WRITE(V1)
{
feedSeconds = param.asInt(); // assigning incoming value from pin V1 to a variable
Serial.print("V1 Slider value is: ");
Serial.println(feedSeconds);
}
void FeedStart() // Rotate the rotor
{
M1.setmotor( _CW, 100);
Serial.print(" FEEDING ");
Serial.print(" for ");
Serial.println(varTimer);
timer.setTimeout(feedSeconds * 1000, FeedStop); //Slider set feeding time in ms
}
Not sure why V3 is not starting the motor but I would change it to normal logic of switch and 1 rather than push and 0.