November 2018
Beginner
472 pages
13h 5m
English
We'll write some test code that lets the user type a value in degrees and make the servo move to it. The library we are already using for the robot has a PWM module. We start our test code by importing the PWM module and creating the object to work with it. Note we must specify the address here—it's the same I2C device as we are using for the motors, and has the same address. This code is located in the servo_type_position.py file:
from Raspi_MotorHAT.Raspi_PWM_Servo_Driver import PWMimport atexitpwm = PWM(0x6f)# This sets the timebase for it allpwm_frequency = 60pwm.setPWMFreq(pwm_frequency)
Observe that we have atexit again, so we can ensure the controller stops signalling the motor. The servo works in cycles at ...