0
0
Raspberry Piprogramming~10 mins

GPIO cleanup on exit 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 GPIO library.

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

Complete the code to set the GPIO mode to BCM.

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

Fix 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'
AGPIO.setup
BGPIO.setmode
CGPIO.cleanup
DGPIO.output
Attempts:
3 left
💡 Hint
Common Mistakes
Calling GPIO.setmode() instead of cleanup.
Forgetting to call cleanup leading to warnings.
4fill in blank
hard

Fill 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'
A18
BGPIO.OUT
CGPIO.IN
D17
Attempts:
3 left
💡 Hint
Common Mistakes
Using pin 17 instead of 18.
Setting pin mode to GPIO.IN instead of GPIO.OUT.
5fill in blank
hard

Fill 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'
A23
BGPIO.OUT
D18
Attempts:
3 left
💡 Hint
Common Mistakes
Using pin 18 instead of 23.
Forgetting to set pin mode before output.