Configuration

Servo Configuration

In this step you'll determine the pulse width values for the locked and unlocked servo positions of the box. Make sure the hardware is assembled, the software dependencies are installed, and power is applied to both the Raspberry Pi and servo before you continue. Connect to the Raspberry Pi in a terminal session and type the following to run an interactive python shell as root:

sudo python

At the python shell type in the following to load the RPIO library and its servo control class (note you don't need to type the >>>, it's just a reference for what you should see):

>>> from RPIO import PWM
>>> servo = PWM.Servo()

Now you can call the set_servo function to send pulse width values to the servo which will move it to different positions. The pulse width value you send can range from 1000 to 2000 microseconds, with a value of 1500 being the center position of the servo. If you're curious, you can find more information on servos in this tutorial.

Make sure the box is open so you can see the servo and it's free to move, then execute this command to move the servo to the center position (pulse width of 1500 microseconds):

>>> servo.set_servo(18, 1500)

Note that if your servo is connected to a different GPIO port of the Raspberry Pi, change the first parameter from 18 to the appropriate value.

Try sending different pulse width values between 1000 and 2000 to find the values which move the latch to the locked and unlocked position. Don't forget you can adjust the position of the servo horn and latch on the servo if necessary. You can see the values I found for my hardware below:
Latch in the unlocked position with a servo pulse width of 2000 micro seconds.
Latch in the locked position with a servo pulse width of 1100 micro seconds.
Take note of the pulse width values you determined for the locked and unlocked position as they will be used later in the configuration. Execute the following command in the python shell to close it:

>>> quit()

Software Configuration

In the directory with code for this project, open the file config.py in a text editor. This file defines the configuration for the project and might require a few changes for your hardware. Specifically you can adjust the following values:
  • LOCK_SERVO_PIN - this should be the GPIO number of the Raspberry Pi which is connected to the signal line of the lock servo. This project is built to use GPIO 18 by default.
  • LOCK_SERVO_UNLOCKED - this should be the pulse width value (in microseconds) for the unlocked position of the latch. Use the value you determined in the previous step.
  • LOCK_SERVO_LOCKED - this should be the pulse width value for the locked position of the latch.
  • BUTTON_PIN - this should be the GPIO number which is connected to the push button on the box. This project is built to use GPIO 25 by default.
The rest of the values in the configuration can be ignored. The only other value of interest is the POSITIVE_THRESHOLD configuration, which gives the boundary for how confident the face recognition has to be before it's considered a positive match. For now the default value of 2000 should suffice, but it can be adjusted later if the box has too many false positive or false negative recognitions.

Continue on to run the box software and finish the project.

This guide was first published on Jan 24, 2014. It was last updated on Jan 24, 2014. This page (Configuration) was last updated on May 04, 2015.