Step #7: Configure Servo
In this step you'll determine the servo pulse width values for the unlocked and locked latch positions.
With power applied to both the Raspberry Pi and latch servo, connect to the Pi in a terminal session. Make sure the box is propped open so you can watch the servo move without it getting stuck.
Execute the following command to start an interactive Python session as root (necessary to access the GPIO pins and move the servo): sudo python
At the Python >>> prompt, enter this command to load the RPIO servo library: from RPIO import PWM
Next enter this command to create a servo object: servo = PWM.Servo()
Finally, execute this command to move the latch servo to its center position: servo.set_servo(18, 1500)
The 1500 parameter to the set_servo function is the servo pulse width in microseconds and can range from 1000 to 2000 at each servo extreme.
The 1500 parameter to the set_servo function is the servo pulse width in microseconds and can range from 1000 to 2000 at each servo extreme.
Try executing the set_servo function with different pulse width values until you find the values which are appropriate to move the latch into the open and closed positions as shown in the pictures.
Don't forget you can remove the servo horn and reattach it to better orient the latch on the servo.
Once you've determined the pulse width values for the unlocked and locked positions, open config.py in the project root with a text editor and change the following values:
Set LOCK_SERVO_UNLOCKED equal to the pulse width value for the unlocked latch position. On my hardware I found a value of 2000 was appropriate.
Set LOCK_SERVO_LOCKED to the pulse width value for the locked latch position. I found a value of 1100 worked for my hardware.