Hi Everyone,
Last weekend I moved one of my bigger projects from the Core to the Photon. All went well except for a non-working servo on what is now the DAC pin on the photon. Easily fixed I thought and moved the servo input to WKP. This worked the first time but stopped working after waking up from Deep Sleep. So I thought it's probably something to do with Deep Sleep grabbing WKP to act as the wakeup pin. Moved servo to RX and finally TX. Both these pins made the servo behave intermittently and/or with long delays.
I ran across this post
Similar to my situation but not clearly solved. So I spent the last couple of days trying to come up with something to make this behaviour repeatable and simple to demonstrate. This is what I've come up with.
This may be something for either @peekay123 or @ScruffR but all are welcome to try.
To show the strange behaviour you need;
-
A Photon running 0.4.5 firmware
-
A servo like the one that comes with the maker kit
-
The following code
#define ledblue D7
#define servocontrol_1 RX //TX also shows the same behaviour//SYSTEM_MODE(SEMI_AUTOMATIC);
Servo servo_1;
void setup() {
pinMode(ledblue, OUTPUT);
servo_1.attach(servocontrol_1);}
void loop() {
WiFi.connect();// Flash blue LED slowly while waiting for wifi.ready flag
while (!WiFi.ready()){digitalWrite(ledblue, HIGH); delay(200); digitalWrite(ledblue, LOW); delay(200);
}
servo_1.write(10);
delay(500);Particle.connect();
// Flash blue LED quickly while waiting for the pariticle.connected flag
while (!Particle.connected()){digitalWrite(ledblue, HIGH); delay(60); digitalWrite(ledblue, LOW); delay(60);
}
servo_1.write(80);
delay(500);for(int i=0; i<=10; i++) {
digitalWrite(ledblue,HIGH);
servo_1.write(20);
delay(300);
digitalWrite(ledblue,LOW);
servo_1.write(70);
delay(300);
}}
Connect your servo signal line to RX, flash the code OTA and watch the servo move one way then the other way and then wag back and forth just like it should.
Then make one change, un-comment the SYSTEM_MODE(SEMI_AUTOMATIC) line, flash and watch the servo.
This time the servo may or may not move, during the wag section it should move back and forth with each flash of the blue LED. The LED flashes but the servo may only move 2 or three times not the ten times as it did with SYSTEM_MODE(SEMI_AUTOMATIC) commented out.
I can make the servos make all the moves if I increase the delays after the Servo_1.Write statements to something in the neighbourhood of 3000 to 5000. Waiting 3 to 5 seconds for the servo to react isn't normal but may point to where to problem is.
If you attach the servo to the WKP pin and your Photon goes into a Deep Sleep cycle then the servo never gets re-attached to the WKP pin when it wakes up.
I don't know what is causing this but thought this might help the team in troubleshooting this anomaly. All other PWM pins behave as they should with this code.
As a secondary item, you may notice that the blue LED does not flash during the wait for the wifi.ready flag. It did when running on the Core. I'm assuming this is because WiFi.connect is now blocking. Is that correct? Of have I messed up the code somehow that I can't see. (I'm new to C programming)
Thanks for listening, hope this helps in some way.