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.


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() {
  pinMode(A5,OUTPUT);"Sending Hello World!");

void loop() {


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:


Bingo! Thank you!

1 Like