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 unrelated libraries like 'time' or 'os'.
Using 'gpiozero' which is a different GPIO library.
✗ 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 mode constants with pin direction constants.
✗ Incorrect
Using GPIO.BCM sets the pin numbering to the 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 or GPIO.INPUT which are for input pins.
Using GPIO.PWM which is for pulse-width modulation, not basic output.
✗ Incorrect
To control an LED, the pin must be set as an output using GPIO.OUT.
4fill in blank
hardComplete the code to turn the LED on connected to pin 18.
Raspberry Pi
GPIO.output(18, [1]) GPIO.cleanup()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.LOW to turn the LED on (it turns it off).
Passing the pin number to cleanup which expects no arguments.
✗ Incorrect
Setting the pin to GPIO.HIGH turns the LED on. The GPIO.cleanup() function is called without arguments to reset all pins.
5fill in blank
hardFill all three blanks to blink the LED once with a 1 second delay.
Raspberry Pi
GPIO.output([1], GPIO.HIGH) time.sleep([2]) GPIO.output([3], GPIO.LOW)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different pin numbers for on and off.
Using too short or too long delay values.
✗ Incorrect
The LED is connected to pin 18, so we set pin 18 HIGH, wait 1 second, then set pin 18 LOW to blink once.