Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the GPIO library.
Raspberry Pi
import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'time' instead of the GPIO library.
Forgetting to alias the library as GPIO.
✗ Incorrect
The Raspberry Pi GPIO library is imported as RPi.GPIO as GPIO to control the pins easily.
2fill in blank
mediumComplete the code to set the GPIO mode to BCM.
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 input/output modes with pin numbering modes.
✗ Incorrect
Setting GPIO mode to GPIO.BCM means you use the Broadcom chip pin numbers.
3fill in blank
hardFix the error in the code to clean up GPIO on program exit.
Raspberry Pi
try: # Your code here pass finally: [1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling GPIO.setmode() instead of cleanup.
Forgetting to call cleanup leading to warnings.
✗ Incorrect
The GPIO.cleanup() function resets all GPIO pins used by the program, preventing warnings on next run.
4fill in blank
hardFill both blanks to set up a GPIO pin 18 as output and then clean up on exit.
Raspberry Pi
GPIO.setup([1], [2]) try: # Use the pin pass finally: GPIO.cleanup()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pin 17 instead of 18.
Setting pin mode to GPIO.IN instead of GPIO.OUT.
✗ Incorrect
Pin 18 is set as an output pin using GPIO.OUT. Cleanup is called after usage.
5fill in blank
hardFill all three blanks to write a high signal to pin 23, then clean up GPIO on exit.
Raspberry Pi
GPIO.setup([1], [2]) GPIO.output([3], GPIO.HIGH) try: pass finally: GPIO.cleanup()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pin 18 instead of 23.
Forgetting to set pin mode before output.
✗ Incorrect
Pin 23 is set as output, then set to HIGH signal. Cleanup resets pins on exit.