0
0
Raspberry Piprogramming~10 mins

Servo motor control with PWM in Raspberry Pi - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the PWMOutputDevice class from the gpiozero library.

Raspberry Pi
from gpiozero import [1]
Drag options to blanks, or click blank then click option'
APWM
BPWMOutputDevice
CServo
DLED
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Servo' instead of 'PWMOutputDevice' because Servo is a different class.
Using 'LED' which is unrelated to PWM control.
2fill in blank
medium

Complete the code to create a PWM object on GPIO pin 17.

Raspberry Pi
servo = PWMOutputDevice([1], frequency=50)
Drag options to blanks, or click blank then click option'
A18
B27
C22
D17
Attempts:
3 left
💡 Hint
Common Mistakes
Using pin 18 which is often used for PWM but not the one specified here.
Using pin 22 or 27 which are valid GPIO pins but not the correct one.
3fill in blank
hard

Fix the error in setting the servo pulse width to 1.5 milliseconds.

Raspberry Pi
servo.value = [1]
Drag options to blanks, or click blank then click option'
A0.075
B1.5
C0.5
D1500
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1.5 directly which is out of range.
Using 1500 which is a pulse width in microseconds, not a fraction.
4fill in blank
hard

Fill both blanks to create a dictionary mapping angles to PWM values for 0 and 90 degrees.

Raspberry Pi
angle_to_pwm = {0: [1], 90: [2]
Drag options to blanks, or click blank then click option'
A0.0
B0.075
C0.05
D1.0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0.0 for 0 degrees which gives no pulse.
Using 1.0 for 90 degrees which is maximum duty cycle.
5fill in blank
hard

Fill all three blanks to complete the code that sets the servo to 45 degrees using the angle_to_pwm dictionary.

Raspberry Pi
angle = 45
pwm_value = (angle_to_pwm[0] + angle_to_pwm[90]) / 2
servo.value = [1]
Drag options to blanks, or click blank then click option'
Apwm_value
Bangle
C0.25
Dservo.value
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'angle' which is just the angle, not the PWM value.
Using 'servo.value' which is the property, not a value.