Make sure that SERVO_DIGITAL_PIN is set to the PWM pin you wired the servo to on your Arduino (in my case here, 9). Then make note of what SERVO_VIRTUAL_PIN is set to.
Once the sketch is uploaded to your Arduino, try creating the widget again from Devices/Widgets > Actuators > Motors > Servo Motor , but this time set the Connectivity to ‘Virtual’ and the Pin to the number set for SERVO_VIRTUAL_PIN (in my case, 1).
That should allow you to add the widget to the dashboard without error and control your servo.
I have the same problem. My code seems right from what I read above, but I am still getting the error message. I have tried to put in different numbers and values everywhere, but nothing seems to work.
My servo is in digital pin 6.
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
// If you're not using the Ethernet W5100 shield, change this to match your connection type. See Communications examples.
#include <CayenneEthernetW5500.h>
#define SERVO_VIRTUAL_PIN 2
#define SERVO_DIGITAL_PIN 6
// servo util lib
#include <Servo.h>
Servo s1;
// a flag to keep track of servos last position
double lastPosition = 0;
// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "private_token";
void setup()
{
Serial.begin(9600);
Cayenne.begin(token);
s1.attach(SERVO_DIGITAL_PIN);
}
CAYENNE_IN(SERVO_VIRTUAL_PIN)
{
// get value sent from dashboard
double currentValue = getValue.asDouble();
int position = currentValue * 200;
// actually move the servo to the specified position
s1.write(position);
//update last position
lastPosition = currentValue;
}
void loop()
{
Cayenne.run();
}
I can see in the bottom screenshot that you have your ‘Connectivity’ set to Analog. Have you tried setting it to ‘Virtual’ with Pin V2? I suspect that will allow you to add and then control the servo at physical pin D6 per your sketch.
sory i have one more question. It work but just 0 and 1 position.( left or right)
i woud like to control stepper motor from -45 to 45 with slider ?
how i control angle ?
can help me ?