Servo Control with Particle Argon on D7

I have couple of 9g SG90 servos that i want to control using the argon. I chose Pins D7 and D8 for that. Everything seems to be working fine on pin D8. However, when i use the same code on D7 and connect the servo, it does not seem to work, it just jitters and stops.

Is there something different that needs to be done to get the servo work on D7? I am using standard code i found on the internet.

Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created

int pos = 0;    // variable to store the servo position

void setup()
{
  myservo.attach(D7);  // attaches the servo on the D0 pin to the servo object
  // Only supported on pins that have PWM
}

void loop()
{
  for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
  {
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

Any guidance is appreciated. Thanks!

Could it be that the on-board LED with current limiting resistor makes the difference?

1 Like

@ScruffR how can i check that?

I’d use an oscilloscope to compare the levels on D8 and D7.
I’d also try another pin - when it works on all other PWM pins but D7, I’d put my money on the only difference - that is the LED.

hmm agreed… makes sense

I’d guess that the problem is that on Gen 3 devices (Argon, Boron, Xenon), pin D7 shares timer group 0 with the RGB LED. This probably prevents Servo from operating properly as the frequency and resolution must be the same as the RGB LED, and this is probably not compatible with Servo.

It would be helpful if this limitation is specified clearly in some documentation.

It’s mentioned in PMW, which has the same restrictions as Servo, but it should be mentioned in Servo as well.

https://docs.particle.io/reference/device-os/firmware/argon/#analogwrite-pwm-

Ah ok! Thanks for pointing to this :slight_smile:

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.