Servo and Photon 2?

The docs for the servo say " NOTE: Servo is only supported on Gen 3 devices in Device OS 0.8.0-rc.26 and later."

Does that mean that I can't use the servo on a Photon 2?

1 Like

Servo works on the P2, Photon 2, and M-SoM.

2 Likes

Yup, I just got it to work, thank you! I know that there's servo.h, but my understanding is that behind the scenes the servo is using PWM. Is there any where I can see the source code that's behind the servo.h methods?

This is the implementation of the API

This is the platform-specfiic code for RTL872x:

I am having trouble getting a Servo to work on the Photon2 and feel silly about it. I can get the same servo to work on a Photon 1. DMM shows 5.0V on servo power pins. Blinking LED works fine (see code below).

Are there particular pins that PWM/Servos are restricted to? I have tried pins D0, D4, and D7. Does anything jump out at you about my code/example shown below?

Example Code that works on a Photon 1 and fails on a Photon 2:

#include "Particle.h"

Servo myServo;

//<snip> System Mode Semi_Automatic, Thread Enabled, Log Level Info

void setup() {
  myServo.attach(D0);
  pinMode(A5,OUTPUT);
  Log.info("Sending Hello World!");
}

void loop() {
  digitalWrite(A5,HIGH);
  myServo.write(10);
  delay(1000);

  digitalWrite(A5,LOW);
  myServo.write(170);
  delay(1000);
}

Hi @Phoenix

You should not have to use digitalWrite(), just the myservo.write() calls.

I think you are taking over the pin (A5) and not letting the servo PWM have the pin for output.

The digitalWrite() statements are just there to ensure that the code is uploaded correctly and running as expected. (They are sometimes called a heartbeat.)

The servo is attached to D0.

OK Sorry I read the code too quickly. The heartbeat is fine.

According the Photon2 datasheet, D0 is not a PWM pin and servo does not work on D0.

The PWM Pins are: D1, MISO (aka D16), MOSI (aka D15), A5 (hence my confusion), and A2.

Can you try using one of these pins? The pinout part of the datasheet is here:

2 Likes

Bingo! Thank you!

1 Like

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