How to access data from widgets assigned to GPO pins

Using NodeMCU 1.0 (ESP12 Module). Connecting via Wifi. I want to control pan and tilt of device with two SG90 Servo motors. Have tried Blynk Slider(2), StepH and StepV widgets all of which only allow me to select GPO pins. I have tired repeatedly but cannot change to Virtual pins. All code examples are for virtual pins. I am currently using StepV (GPO13) and StepH (GPO15) widgets. The two BLYNK_WRITE functions in my code are never accessed when the sketch is running. Step switch changes have no effect on my servos. HELP!

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Servo.h>

char auth[] = "";
char ssid[] = "";
char pass[] = "";

Servo ServoPan;
Servo ServoTilt;

BLYNK_WRITE(15)
{
  Serial.println("accessed BLYNK_WRITE15");
  int panSrvoPos = param.asInt();
  ServoPan.write(panSrvoPos);
  
}
BLYNK_WRITE(13)
{
  int tiltSrvoPos = param.asInt();
  ServoTilt.write(tiltSrvoPos);
}

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);

  pinMode(15, OUTPUT);
  pinMode(13, OUTPUT);

  ServoPan.attach(15); //pan camera NodeMCU D8 pin
  ServoTilt.attach(13); //tilt camera NodeMCU D7 pin

    /* ServoPan.write(0);
    delay(500);
    ServoTilt.write(0);
    delay(500);
    ServoPan.write(180);
    delay(500);
    ServoTilt.write(180);
    delay(500);
    ServoPan.write(90);
    delay(500);
    ServoTilt.write(90);
    delay(500);*/

}

void loop()
{
  Blynk.run();
}

Which device are you using?

In the screenshot provided, Digital is selected on the left hand side. Are you saying that the control on the left hand side of the screen doesn’t allow you to select Virtual?

Pete.

Thanks for Replys…
JustBertC
I am using both a StepH and StepV widget

PeteKnight
That is correct…it would not let me switch to Virtual. I also tried to use sliders and I could not select Virtual on them either.

UPDATE.

I had selected esp8266 as the device type for my project but discovered earlier this evening there is a NodeMCU type so I switched project to that type. Now I can select virtual for the step buttons but have new set of issue I haven’t been able to puzzle out. The Step buttons only return + or - the step value. I set the step button counters to 90 by code and created a variable to keep track of the change in value from that number based on step changes from virtual buttons.
Problem is servo.write( val) will not write to servo when a named variable is used for the value. I have tried type int and float for the named variable but neither works. Any thoughts there? I have a revise sketch but don’t know if including it in a reply is appropriate.

It sounds like you don’t have the step widget configured correctly. Have you tried changing the various options from within the widget and noting the different outputs?

Also, exactly which servo library are you using?

Pete.

You were right… had a box set YES for send step. Now is it sending widget value

I am using Servo.h

Have a bit of code to rework… mostly delete …lol… but too tired to do it now …seems like I forgot to go to bed and here it is 4:17 AM. Oh well, I’m retired and don’t live by the clock an calendar any more.

Thanks again, Pete. will post an update asap

Final Status Update. Revised the code getting rid of all the superfluous junk I had added because of stupidly chosen “send step” settings on StepH and StepV widgets and all is working as I wanted. The sketch now is short, simple and available to anyone interested in working with multiple servo motors and Blynk.

It turns out the servo.write(val) command only accepts an int variable for param.asInt(), param.asInt() itself or a number. Inserting some other variable for val in any part of the sketch code caused all servo.write() calls to be ignored.

Thanks for the Help!

1 Like

Excellent!
Maybe you should do a “projects made with Blynk” write-up?

Pete.

LOL… I’ll give it some thought. What I’m working on now is my third iteration of the 3 wheeled two motor robo car thing. I’ve done it with programmed movement only, with RF Joystick Control using UNO’s and now with NodeMCU and Blynk. I discover there was a companion motor controller that the old NodeMCU plugs into that can control 2 DC motors and 4 servos with a foot print smaller than an UNO and a ton fewer wires. Since I’ve got all that servo space I decided to put a pan tilt camera and some kind of audio messaging on it so I can send it about the house to find my wife and when it does tell her to bring me a cup of coffee and a cookie. Now that is a useful IoT ! (you don’t suppose the community minds if we turn this post into a chat room do you?)

Probably not as much as Mrs Hascall is going to mind the “bring Richard a cup of tea” instructions :grinning:
Your project sounds a bit like @Gunner rover…

Pete.