Problem connecting a servo to the core

I tried to develop a small project, how ever after a short time I ran into problems with the servo. I think I found a bug (other have reported similar problems https://github.com/voodootikigod/voodoospark/issues/32).

I made a small project to reproduce the problem. Connect the servo to vin and gnd. Connect the controll pin to port A0 of the core. Then connect a push button to 3V3 and D0. If you run the following programm:

Servo myservo;  // create servo object to control a servo

void setup()
{
  myservo.attach(A0);  // attaches the servo on the A0 pin to the servo object
  pinMode(D0, INPUT_PULLDOWN);
  pinMode(A1, OUTPUT);
}

void loop()
{
    if(digitalRead(D0) == HIGH) {
        myservo.write(20);
        analogWrite(A1, 255);
    }
    delay(10);
}

As soon as you press the button the servo tries to do someting strange (reach an unreachable position) and makes some noise. (I guess you need to disconnect the servo fast as this might destroy it.)

The problem does not appear if you connect the servo to pin A7. (Until now I could not get the servo work on pin A0 on the Particle Photon at all, on A5 it works fine.)

Can someone confirm this problem?

Hi @leo.buettiker

The servo and analogWrite functions both require a hardware timer in order to work, soI think you are seeing a conflict since the timer is shared for A0 and A1 and cannot service both servos and analog writes at the same time.

I thought that @BDub had put together some doc on this but I searched and could not find it.

1 Like