"Servo" class not recognized in editor

image

Working with an Electron.

Servo.h is included automatically, right? Why would this object definition not recognize “Servo” as the class? I’m a beginner and must be missing something. Thanks for your help.

What system version are you building against and what platform?
When I build for Photon 0.6.3 I don’t get any error message.

2 Likes

v0.5.4. Interestingly enough, I don’t get any compile faults but I also don’t get any servo movement further in the code.

Servo zfServo;

void setup()
{
   pinMode(D0, OUTPUT);
   zfServo.attach(D0);
   zfServo.write(25);
   
}

void loop()
{
   // Nothing to do here
}

int ledToggle(String command) {

    if (command=="open") {
        zfServo.write(85);
        return 1;
    }
    else if (command=="closed") {
        zfServo.write(15);          
        return 0;
    }
    else {
        return -1;
    }
}

Are you upset that it is not highlighted, or is there some other problem?

Classes are not highlighted in the Atom GUI the same way the 'special' classes are in the Arduino GUI.

I'm assuming you've left code out of your example.. because this code just sets the servo to 25 and leaves it there forever?

If the error is elsewhere in the code I’d be glad to have some help. I’ve validated I have a good servo with a sparkfun trigger board but I’m not getting any movement with this code.

The first thing that stood out to me is that Particle’s example code shows “Servo” in blue.

“Servo” remains white in my code which makes me think it’s not recognizing the Servo class. If I’m wrong, again, I appreciate the help.

Yes, I removed irrelevant code - ledToggle is called from mobile

If it compiles it compiles-- it’s getting a Servo class from somewhere!

Why don’t you make things simpler and test with servo move commands in loop() with delay()'s in between?

Does the servo seem active? Does it chatter? Is it weirdly quiet?

That’s a good idea, I’ll give it a try. Thanks

No, zero movement on servo. setup() should at least jog it but I get nothing

With servo you don’t have declare the pin as an output so I would try deleting that line and just doing the attach in setup.

Could you have a wiring problem? Or a power problem (servos generally don’t like 3.3V and 5V or more)?

Ok, I’ve just written a simple loop to test.

Servo zfServo;

void setup()
{
   zfServo.attach(D0);
}

void loop()
{
   zfServo.write(85);
   delay(2000);
   zfServo.write(15);
   delay(2000);
}

I get zero movement with this code. I know the servo works with this 5V 2A source. I can put the signal jumper back on the sparkfun board and it cycles fine. I’ve double checked my jumper wires and connection to D0. What else can I try?

Put an LED and resistor on D0 and see if you can toggle the brightness by setting the servo position to 0 and 180.

Hi @gr4vityrider

Can you show a picture of your wiring?

Do you have the ground from the servo tied to the ground on the Electron (even if +5V is coming from another supply)?