Pan/Tilt strange behavior

I have a simple script that tests my pan motor. At zero degrees, it is pointing right where I want it. Sometimes, when the program ends, the thing will rotate -79 degrees, twisting my cables around the mounting post, all for no reason. The camera still has power, which means the pan/tilt motors have power. I feed 5V in from a power supply for this board. Why is the servo sometimes doing this unwanted rotation at the end?

If there’s nothing to block the cam at the end of the script, the cam will soft-reset some peripherals including servos, timers etc… Just add a while (True): sleep(1000) at the end if you want to maintain that position.

Thanks. I’ll try it.

What do you mean by “If there’s nothing to block the cam at the end of the script”? Do you mean physically block the servos from spinning around or add the infinite while loop to prevent the servo from receiving any more instructions? I am using the pan/tilt servos to point the camera where I need it to be. If I move the servos and then stop them with “while (True): time.sleep(1000)”, then the program cannot move forward to use the camera to capture an image.

Is there anything you can do in your firmware to prevent the soft reset that makes the pan servo (Servo(1) # P7) from rotate 79 degrees occasionally?

From what I’ve read about servos, best practice is to provide the PWM signal before the servos get power to prevent any rapid jerky motion on startup, but in this case, I’d have to cut the power leads from the shield to the servos and control them with a relay.

No I meant infinite loop, you said when the program ends, the soft reset happens if there’s nothing blocking the script and it runs to completion.