Servo Configuration

In this step you'll determine the positions 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, “cd” to the project directory and type the following command:

python servo.py

Servos operate on timed pulses, typically from 1000 to 2000 microseconds long (but a few servos may function a bit beyond this range), covering the full “sweep” of the servo (usually 180 degrees, sometimes 90 for high-torque units).

Using this script, you can interactively type in different timing values and see how this affects servo position. Idea is to progressively dial in on good values for “open” and “locked” positions.

If your servo is connected to a different pin than GPIO18, edit the file config.py and change the number associated with LOCK_SERVO_PIN.

You can see the values I found for my hardware below:

Latch in the unlocked position with a servo pulse width of 2000 microseconds.

Latch in the locked position with a servo pulse width of 1100 microseconds.

Take note of the pulse width values you determined for the locked and unlocked position as they will be used later in the configuration, then press CTRL-C to exit.

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 Mar 08, 2024.

This page (Configuration) was last updated on Mar 08, 2024.

Text editor powered by tinymce.