Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the RPi.GPIO library.
Raspberry Pi
import [1] as GPIO
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'gpiozero' instead of 'RPi.GPIO'.
Forgetting to import the library.
✗ Incorrect
The RPi.GPIO library is imported with import RPi.GPIO as GPIO to control GPIO pins.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.BOARD instead of GPIO.BCM.
Confusing mode constants with pin directions.
✗ Incorrect
Use GPIO.BCM to set the pin numbering to Broadcom SOC channel numbers.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.IN instead of GPIO.OUT.
Using a non-existent mode like GPIO.PWM.
✗ Incorrect
Pin 18 must be set as GPIO.OUT to output signals for PWM.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Pin' instead of 'PWM'.
Setting frequency to 50 instead of 100.
✗ Incorrect
Use GPIO.PWM to create a PWM object and set frequency to 100Hz.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'start' instead of 'stop' to stop PWM.
Forgetting to call GPIO.cleanup().
✗ Incorrect
Start PWM with 50% duty cycle, stop it with stop(), and clean GPIO with cleanup().