A3 Analog Write / PWM does not work

I have a few Servo motors I want to control I’m using pins:
D0, D1, D2, A3, WKP and RX.

I have not tested RX yet. But in Tinker D0, D1, D2, WKP all work without any issues and can control the motor movement. Setting these pins to analogWrite in Tinker gives me a slider from 0 to 255 and dragging the slider creates slight movements.

However setting A3 to analogWrite creates a slider from 0 to 4000+ and changing this value does nothing for the attached motor. Digital write works but analogWrite does not.

My code is super simple:

Servo myservo;

/* This function is called once at start up ----------------------------------*/
void setup()
{
	//Setup the Tinker application here
    myservo.attach(A3);

	//Register all the Tinker functions
	Particle.function("digitalread", tinkerDigitalRead);
	Particle.function("digitalwrite", tinkerDigitalWrite);
	Particle.function("analogread", tinkerAnalogRead);
	Particle.function("analogwrite", tinkerAnalogWrite);
	Particle.function("servo", servo);
}

/* This function loops forever --------------------------------------------*/
void loop()
{
	//This will run in a loop
}

int servo(String value)
{
    myservo.write(value.toInt());
    delay(100);
    return 1;
}

What bugs me is the value range for A3 from 0 to 4k. Should I be setting a different mode or something on this pin?

Pin A3 on the photon is a DAC pin, meaning that any calls to analogWrite will result in the pin outputting a true analog value, not a PWM signal required by servos. https://docs.particle.io/reference/device-os/firmware/photon/#analog-output-dac-

Could you try using a different pin with your servo? https://docs.particle.io/reference/device-os/firmware/photon/#attach-

  • on the Photon, Servo can be connected to A4, A5, WKP, RX, TX, D0, D1, D2, D3
2 Likes

Yea the issue was the pin.

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