You can use the program below to help determine the feedback values that correspond to your servo's range of motion.

If you want to calibrate over a difference range of motion, you can change these lines at the top:

# Calibration setup
ANGLE_MIN = 0
ANGLE_MAX = 180

When the code runs, it will print out the analog reading values that correspond to the min/max range of motion. Write these values down, you'll need them to calibrate the other programs.

# Example code for calibrating analog feedback values to servo range

import time
import board
import pwmio
from adafruit_motor import servo
from analogio import AnalogIn

# Pin setup
SERVO_PIN = board.A1
FEEDBACK_PIN = board.A5

# Calibration setup
ANGLE_MIN = 0
ANGLE_MAX = 180

# Setup servo
pwm = pwmio.PWMOut(SERVO_PIN, duty_cycle=2 ** 15, frequency=50)
servo = servo.Servo(pwm)
servo.angle = None

# Setup feedback
feedback = AnalogIn(FEEDBACK_PIN)

print("Servo feedback calibration.")
# Move to MIN angle
print("Moving to {}...".format(ANGLE_MIN), end="")
servo.angle = ANGLE_MIN
time.sleep(2)
print("Done.")
feedback_min = feedback.value
# Move to MAX angle
print("Moving to {}...".format(ANGLE_MAX), end="")
servo.angle = ANGLE_MAX
time.sleep(2)
print("Done.")
feedback_max = feedback.value
# Print results
print("Feedback MIN = {}".format(feedback_min))
print("Feedback MAX = {}".format(feedback_max))
# Deactivate servo
servo.angle = None

This guide was first published on Aug 24, 2013. It was last updated on Aug 24, 2013.

This page (Calibrating The Feedback) was last updated on Dec 01, 2021.

Text editor powered by tinymce.