Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the 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 'time' instead of 'RPi.GPIO'.
Using 'os' or 'sys' which are unrelated to GPIO.
✗ Incorrect
The RPi.GPIO library is used to control the GPIO pins on a Raspberry Pi.
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 GPIO.OUT or GPIO.IN as mode settings.
✗ Incorrect
GPIO.BCM sets the pin numbering to use the Broadcom chip-specific numbering.
3fill in blank
hardFix the error in setting up pin 18 as an 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 or GPIO.INPUT instead of GPIO.OUT.
Using GPIO.PWM which is for pulse-width modulation, not basic output.
✗ Incorrect
GPIO.OUT configures the pin as an output pin to control the LED.
4fill in blank
hardFill both blanks to turn the LED on and then off.
Raspberry Pi
GPIO.output(18, [1]) time.sleep(1) GPIO.output(18, [2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.OUT or GPIO.IN as output values.
Reversing HIGH and LOW.
✗ Incorrect
GPIO.HIGH turns the LED on, GPIO.LOW turns it off.
5fill in blank
hardFill the blanks to clean up GPIO after blinking.
Raspberry Pi
try: GPIO.output(18, [1]) finally: GPIO.[2]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not calling GPIO.cleanup() after use.
Using GPIO.HIGH instead of GPIO.LOW to turn off LED.
✗ Incorrect
Turn LED off with GPIO.LOW, then call GPIO.cleanup() to reset pins.