0
0
Raspberry Piprogramming~10 mins

Software PWM with RPi.GPIO 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 RPi.GPIO library.

Raspberry Pi
import [1] as GPIO
Drag options to blanks, or click blank then click option'
ARPi.GPIO
Bos
Ctime
Dgpiozero
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'gpiozero' instead of 'RPi.GPIO'.
Forgetting to import the library.
2fill in blank
medium

Complete the code to set the GPIO mode to BCM numbering.

Raspberry Pi
GPIO.setmode([1])
Drag options to blanks, or click blank then click option'
AGPIO.IN
BGPIO.BOARD
CGPIO.OUT
DGPIO.BCM
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.BOARD instead of GPIO.BCM.
Confusing mode constants with pin directions.
3fill in blank
hard

Fix the error in setting up pin 18 as output.

Raspberry Pi
GPIO.setup(18, [1])
Drag options to blanks, or click blank then click option'
AGPIO.IN
BGPIO.PWM
CGPIO.OUT
DGPIO.OUTP
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.IN instead of GPIO.OUT.
Using a non-existent mode like GPIO.PWM.
4fill in blank
hard

Fill both blanks to create a PWM instance on pin 18 with 100Hz frequency.

Raspberry Pi
pwm = GPIO.[1](18, [2])
Drag options to blanks, or click blank then click option'
APWM
B50
C100
DPin
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Pin' instead of 'PWM'.
Setting frequency to 50 instead of 100.
5fill in blank
hard

Fill all three blanks to start PWM with 50% duty cycle and then stop it.

Raspberry Pi
pwm.start([1])
# ... some code ...
pwm.[2]()
GPIO.[3]()
Drag options to blanks, or click blank then click option'
A50
Bstop
Ccleanup
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'start' instead of 'stop' to stop PWM.
Forgetting to call GPIO.cleanup().