0
0
Raspberry Piprogramming~10 mins

Raspberry Pi hardware overview (GPIO, USB, HDMI) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set up a GPIO pin as an output on a Raspberry Pi.

Raspberry Pi
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup([1], GPIO.OUT)
Drag options to blanks, or click blank then click option'
AGPIO.IN
BGPIO.OUT
C17
DGPIO.BOARD
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.OUT instead of a pin number
Using GPIO.BOARD instead of a pin number
2fill in blank
medium

Complete the code to turn on an LED connected to GPIO pin 18.

Raspberry Pi
GPIO.output([1], GPIO.HIGH)
Drag options to blanks, or click blank then click option'
A18
B17
CGPIO.HIGH
DGPIO.LOW
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong pin number
Using GPIO.LOW which turns the LED off
3fill in blank
hard

Fix the error in the code to read the state of a button connected to GPIO pin 23.

Raspberry Pi
button_state = GPIO.input([1])
Drag options to blanks, or click blank then click option'
AGPIO.OUT
BGPIO.HIGH
CGPIO.IN
D23
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.IN instead of a pin number
Using GPIO.OUT which is for output pins
4fill in blank
hard

Fill both blanks to create a dictionary mapping USB port numbers to their status.

Raspberry Pi
usb_status = [1]((port, 'connected' if port [2] [1, 2] else 'disconnected') for port in range(1, 5))
Drag options to blanks, or click blank then click option'
Adict
Bin
Cnot in
Dlist
Attempts:
3 left
💡 Hint
Common Mistakes
Using list instead of dict
Using 'not in' which reverses the condition
5fill in blank
hard

Fill all three blanks to create a dictionary of HDMI ports with their resolutions if active.

Raspberry Pi
hdmi_info = [1]: [2] if status [3] 'active' else 'inactive' for [1], status in [('HDMI1', 'active'), ('HDMI2', 'inactive')]}}
Drag options to blanks, or click blank then click option'
Aport
Bresolution
C==
D'1920x1080'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '=='
Using a wrong key name
Using a wrong resolution string