Unit 2: Advanced GPIO & Peripheral Control - Practice Quiz

ECE140 — Workshop On Iot For Digital Society 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 Which Python library provides low-level control of Raspberry Pi GPIO pins?

Python libraries: RPi.GPIO and GPIO Zero Easy
A. NumPy
B. Tkinter
C. RPi.GPIO
D. GPIO Zero

2 Which GPIO Zero class is commonly used to control an LED?

Python libraries: RPi.GPIO and GPIO Zero Easy
A. Motor
B. Servo
C. LED
D. Button

3 What is the purpose of GPIO.setup() in RPi.GPIO?

Python libraries: RPi.GPIO and GPIO Zero Easy
A. Configure a pin's mode
B. Close the Python program
C. Remove event detection
D. Read a pin's voltage

4 Which RPi.GPIO function releases GPIO resources after a program finishes?

Python libraries: RPi.GPIO and GPIO Zero Easy
A. GPIO.start()
B. GPIO.cleanup()
C. GPIO.input()
D. GPIO.output()

5 What is the main advantage of interrupt-driven GPIO programming?

Interrupt-driven GPIO programming Easy
A. It avoids continuous polling
B. It adds more physical pins
C. It changes the board model
D. It increases the supply voltage

6 Which signal change is called a rising edge?

Interrupt-driven GPIO programming Easy
A. LOW to HIGH
B. LOW to LOW
C. HIGH to HIGH
D. HIGH to LOW

7 What is a callback function in GPIO event handling?

Interrupt-driven GPIO programming Easy
A. A function that supplies motor power
B. A function that changes pin numbering
C. A function run when an event occurs
D. A function that installs the operating system

8 Why is switch debouncing used with GPIO interrupts?

Interrupt-driven GPIO programming Easy
A. To prevent repeated false triggers
B. To reverse the pin direction
C. To increase the logic voltage
D. To generate an analog signal

9 What is the main purpose of an H-bridge circuit?

Motor control using H-bridge and motor driver ICs Easy
A. Measure a motor's temperature
B. Convert a motor into a sensor
C. Store a motor's position
D. Reverse a motor's direction

10 Why is a motor driver IC used between a GPIO pin and a DC motor?

Motor control using H-bridge and motor driver ICs Easy
A. To store the Python program
B. To expand the file system
C. To provide the required current
D. To measure network traffic

11 Which technique is commonly used to control the speed of a DC motor?

Motor control using H-bridge and motor driver ICs Easy
A. Serial text encoding
B. File system mounting
C. Network address translation
D. Pulse-width modulation

12 What can happen if both sides of an H-bridge are switched incorrectly at the same time?

Motor control using H-bridge and motor driver ICs Easy
A. The GPIO count may increase
B. The program gains more memory
C. The motor becomes a sensor
D. A short circuit may occur

13 What input signal is commonly used to set a hobby servo's position?

Servo and stepper motor control with acceleration profiles Easy
A. Continuous audio samples
B. Timed control pulses
C. Stored network packets
D. Random voltage spikes

14 How does a stepper motor normally move?

Servo and stepper motor control with acceleration profiles Easy
A. Only at maximum speed
B. In fixed angular steps
C. Only in one direction
D. In random angular jumps

15 What is an acceleration profile in motor control?

Servo and stepper motor control with acceleration profiles Easy
A. A list of Python libraries
B. A record of supply voltage
C. A map of GPIO pin names
D. A planned change in speed

16 Why is gradual acceleration useful when starting a stepper motor?

Servo and stepper motor control with acceleration profiles Easy
A. It reduces missed steps
B. It increases the GPIO voltage
C. It changes the motor type
D. It adds extra motor coils

17 What does DMA stand for?

Real-time GPIO control using DMA Easy
A. Direct Memory Access
B. Digital Motor Adjustment
C. Dynamic Module Allocation
D. Data Measurement Array

18 What is a key benefit of using DMA for GPIO timing?

Real-time GPIO control using DMA Easy
A. Higher GPIO voltage levels
B. Larger storage capacity
C. More consistent signal timing
D. More physical GPIO pins

19 How does DMA reduce CPU workload during GPIO control?

Real-time GPIO control using DMA Easy
A. It converts outputs into inputs
B. It rewrites the operating system
C. It transfers data independently
D. It removes the power supply

20 Which application benefits most directly from DMA-based GPIO control?

Real-time GPIO control using DMA Easy
A. Editing a Python comment
B. Displaying static text documents
C. Generating precisely timed pulses
D. Renaming files in a folder

21 A push button is physically connected to header pin 11 on a Raspberry Pi. Which RPi.GPIO configuration correctly refers to this pin by its Broadcom GPIO number?

Python libraries: RPi.GPIO and GPIO Zero Medium
A. GPIO.setmode(GPIO.BOARD) and use channel 17
B. GPIO.setmode(GPIO.BOARD) and use channel 27
C. GPIO.setmode(GPIO.BCM) and use channel 11
D. GPIO.setmode(GPIO.BCM) and use channel 17

22 An active-low relay module connected to GPIO17 turns on when its input is LOW. Which GPIO Zero declaration gives relay.on() the expected meaning?

Python libraries: RPi.GPIO and GPIO Zero Medium
A. OutputDevice(17, active_high=True, initial_value=True)
B. OutputDevice(17, active_high=False, initial_value=True)
C. OutputDevice(17, active_high=True, initial_value=False)
D. OutputDevice(17, active_high=False, initial_value=False)

23 An RPi.GPIO PWM output operates at kHz with a duty cycle of . What are the approximate HIGH and LOW times in each cycle?

Python libraries: RPi.GPIO and GPIO Zero Medium
A. HIGH for ms and LOW for ms
B. HIGH for ms and LOW for ms
C. HIGH for ms and LOW for ms
D. HIGH for ms and LOW for ms

24 A program uses several GPIO channels but must release only channel 18 before assigning it to another module. Which RPi.GPIO call is most appropriate?

Python libraries: RPi.GPIO and GPIO Zero Medium
A. GPIO.output(18, GPIO.LOW)
B. GPIO.cleanup(18)
C. GPIO.cleanup()
D. GPIO.setup(18, GPIO.IN)

25 A mechanical button generates several transitions within ms of one press. Which event configuration best prevents multiple callbacks from the same press?

Interrupt-driven GPIO programming Medium
A. Use repeated polling with no delay
B. Use a rising-edge event with bouncetime=20
C. Use both-edge detection without a callback
D. Use a falling-edge event with bouncetime=1

26 A sensor produces HIGH pulses lasting only microseconds, while the main loop checks the pin every ms. What is the best way to detect each pulse?

Interrupt-driven GPIO programming Medium
A. Register a rising-edge event callback
B. Configure the pin as an output first
C. Increase the polling delay to ms
D. Read the input twice per loop

27 A GPIO callback currently performs a slow network request, causing later input events to be delayed. Which redesign is most appropriate?

Interrupt-driven GPIO programming Medium
A. Place event data in a queue and return quickly
B. Replace the callback with a longer blocking delay
C. Move the network request into every GPIO callback
D. Increase the callback's debounce interval substantially

28 A quadrature encoder has channels A and B. When an edge occurs on channel A, how can the program determine the rotation direction?

Interrupt-driven GPIO programming Medium
A. Toggle channel B whenever channel A changes
B. Read channel B and compare its level with channel A
C. Measure only how long channel A remains HIGH
D. Count channel A edges without reading channel B

29 A DC motor is running through an H-bridge with IN1=HIGH, IN2=LOW, and a PWM signal on the enable pin. How should its direction be reversed while keeping approximately the same speed?

Motor control using H-bridge and motor driver ICs Medium
A. Set IN1=LOW, IN2=LOW, and retain PWM
B. Set IN1=LOW, IN2=HIGH, and retain PWM
C. Set IN1=HIGH, IN2=HIGH, and retain PWM
D. Keep both inputs unchanged and use PWM

30 A V motor is controlled by ideal PWM at a duty cycle of . What approximate average voltage is applied to the motor?

Motor control using H-bridge and motor driver ICs Medium
A. V
B. V
C. V
D. V

31 A custom H-bridge controlling an inductive DC motor causes voltage spikes when the motor is switched off. Which addition directly protects the switching transistors?

Motor control using H-bridge and motor driver ICs Medium
A. Flyback diodes across the motor current paths
B. A pull-down resistor on the PWM control input
C. A capacitor connected only across the logic supply
D. A larger resistor in series with each GPIO input

32 A motor must rapidly change from forward to reverse without damaging the H-bridge. Which control sequence is safest?

Motor control using H-bridge and motor driver ICs Medium
A. Float the GPIO pins and immediately apply reverse PWM
B. Drive every bridge input HIGH before changing direction
C. Disable PWM, allow dead time, change direction, then ramp PWM
D. Change direction inputs while maintaining maximum PWM

33 A servo maps to a ms pulse and to a ms pulse in a ms period. Which pulse width and duty cycle approximately command ?

Servo and stepper motor control with acceleration profiles Medium
A. ms and
B. ms and
C. ms and
D. ms and

34 A stepper motor must accelerate smoothly from rest to a high target speed. How should the delay between consecutive step pulses change during acceleration?

Servo and stepper motor control with acceleration profiles Medium
A. Remain constant at the minimum value
B. Alternate randomly between long and short
C. Start long and gradually decrease
D. Start short and gradually increase

35 A stepper motor has a full-step angle and is driven using microsteps per full step. How many step pulses are required for one complete revolution?

Servo and stepper motor control with acceleration profiles Medium
A. pulses
B. pulses
C. pulses
D. pulses

36 A loaded stepper motor misses steps when commanded to start immediately at high speed but works correctly when started slowly. What is the best software solution?

Servo and stepper motor control with acceleration profiles Medium
A. Reverse the direction signal before each step pulse
B. Apply an acceleration ramp before reaching full speed
C. Replace all timing delays with a fixed short delay
D. Reduce the number of motor phases being energized

37 A Raspberry Pi must generate a precise pulse train while simultaneously handling network traffic. Why is DMA-based GPIO control preferable to a Python timing loop?

Real-time GPIO control using DMA Medium
A. DMA removes the need to configure GPIO pin directions
B. DMA transfers timed data with less CPU scheduling jitter
C. DMA converts every digital output into an analog output
D. DMA increases the GPIO pins' maximum voltage level

38 A DMA waveform keeps a GPIO pin HIGH for microseconds and LOW for microseconds in each cycle. What are its frequency and duty cycle?

Real-time GPIO control using DMA Medium
A. kHz and
B. kHz and
C. kHz and
D. kHz and

39 Two GPIO timing libraries attempt to use the same DMA channel, and waveform output becomes unreliable. What is the most appropriate correction?

Real-time GPIO control using DMA Medium
A. Configure all controlled GPIO pins as inputs during waveform playback
B. Run both libraries in separate Python functions on the same thread
C. Assign non-conflicting supported DMA channels or use one timing service
D. Increase every waveform delay until the conflict becomes less visible

40 A precomputed DMA waveform remains stable under heavy CPU load, but gaps appear when a continuously streamed waveform runs for several minutes. What is the most likely cause?

Real-time GPIO control using DMA Medium
A. The operating system disables all DMA transfers after a fixed duration
B. The DMA data buffer is not being refilled before it becomes empty
C. The GPIO pin automatically changes from output mode to input mode
D. The PWM duty cycle forces the processor clock to stop periodically

41 An LED is physically connected to header pin 11. The code GPIO.setmode(GPIO.BOARD); GPIO.setup(11, GPIO.OUT) controls it correctly. If the program is rewritten as LED(11) using GPIO Zero's default numbering, which pin is addressed?

Python libraries: RPi.GPIO and GPIO Zero Hard
A. BCM GPIO17, corresponding to header pin 11
B. BCM GPIO27, because GPIO Zero remaps output pins
C. Header pin 11 through automatic BOARD detection
D. BCM GPIO11, not header pin 11

42 A GPIO Zero device is created as LED(17, active_high=False, initial_value=False). What electrical levels are expected immediately after construction and after calling led.on()?

Python libraries: RPi.GPIO and GPIO Zero Hard
A. Initially HIGH; on() drives the pin LOW
B. Initially LOW; on() drives the pin HIGH
C. Initially HIGH; on() leaves the pin HIGH
D. Initially floating; on() drives the pin LOW

43 A Python program generates a 1 kHz PWM signal using RPi.GPIO.PWM. Under heavy CPU and I/O load, pulse widths occasionally vary. Which modification most directly addresses the timing mechanism causing this problem?

Python libraries: RPi.GPIO and GPIO Zero Hard
A. Replace BCM numbering with physical BOARD numbering
B. Increase the Python callback thread's debounce interval
C. Call GPIO.cleanup() after every PWM duty update
D. Use a DMA-timed pin factory such as pigpio

44 A program mixes direct RPi.GPIO calls with GPIO Zero devices on the same pins. It sometimes reports numbering-mode conflicts and leaves outputs active after exceptions. Which design is most robust?

Python libraries: RPi.GPIO and GPIO Zero Hard
A. Disable warnings and depend on process termination to reset all pins
B. Use one abstraction consistently and release devices in finally or context managers
C. Create a separate software PWM instance for every library operation
D. Alternate BCM and BOARD modes before each individual pin operation

45 A flow sensor can produce valid pulses only apart. An RPi.GPIO rising-edge callback is configured with bouncetime=5. What is the most important measurement consequence?

Interrupt-driven GPIO programming Hard
A. Each physical pulse will generate callbacks on both edges
B. The GPIO hardware will stretch every pulse to 5 ms
C. Valid pulses within the suppression window may be discarded
D. The callback timestamps will automatically be averaged

46 An edge callback parses JSON, writes to a database, and updates a display. At high event rates, edges are lost and callback latency grows. Which redesign best preserves event responsiveness?

Interrupt-driven GPIO programming Hard
A. Increase callback computation so several events can be batched
B. Replace edge detection with repeated calls to GPIO.cleanup()
C. Timestamp and enqueue events quickly, then process them in workers
D. Perform all processing inside the callback under one global lock

47 A main thread reads and resets a pulse counter while an interrupt callback executes count += 1. Why can counts still be lost in CPython, despite the Global Interpreter Lock?

Interrupt-driven GPIO programming Hard
A. The GIL forces every callback to execute in another process
B. Edge callbacks bypass Python and modify the counter using DMA
C. The read-modify-write sequence is not a protected transaction
D. Integer variables are stored directly in GPIO peripheral memory

48 A high-speed quadrature encoder changes state faster than Python callbacks can reliably execute. Direction and position must remain correct. Which solution is most appropriate?

Interrupt-driven GPIO programming Hard
A. Run two unrestricted callbacks that update one shared integer
B. Trigger only on channel A and ignore channel B entirely
C. Capture transitions with hardware counters or DMA sampling
D. Add a long debounce interval to both encoder channels

49 During an H-bridge direction reversal, the high-side transistor is enabled before the previously conducting low-side transistor has fully turned off. What is the principal hazard?

Motor control using H-bridge and motor driver ICs Hard
A. Loss of motor torque caused only by back-EMF cancellation
B. Reduced PWM frequency caused by armature inductance
C. Shoot-through current directly across the supply
D. Permanent coasting because both motor terminals float

50 A brushed DC motor has winding resistance . It is driven from 12 V through an H-bridge whose total conducting voltage drop is 2 V. Ignoring inductance, what approximate stall current must the driver tolerate?

Motor control using H-bridge and motor driver ICs Hard
A.
B.
C.
D.

51 A motor is rapidly decelerated using regenerative braking, and the shared DC supply cannot absorb returned energy. Which failure mode is most likely without additional protection?

Motor control using H-bridge and motor driver ICs Hard
A. The H-bridge PWM frequency becomes exactly doubled
B. The logic inputs permanently change their threshold voltage
C. The supply rail rises above its safe voltage
D. The motor winding resistance falls nearly to zero

52 An H-bridge datasheet defines IN1 = IN2 = 0 as coast and IN1 = IN2 = 1 as brake. Why is assuming that equal inputs always mean the same motor state unsafe?

Motor control using H-bridge and motor driver ICs Hard
A. Coast and brake truth tables differ among driver architectures
B. Equal inputs always reverse the motor at maximum duty cycle
C. Coast and brake become identical whenever PWM exceeds 50%
D. Equal inputs bypass the bridge and power the motor from logic

53 A hobby servo expects pulses from 1.0 ms to 2.0 ms in a 20 ms frame. If PWM is configured at 50 Hz, which nominal duty-cycle range represents those pulse widths?

Servo and stepper motor control with acceleration profiles Hard
A. 20% to 40%
B. 5% to 10%
C. 2% to 4%
D. 10% to 20%

54 A stepper must move 1000 steps from rest and stop at the destination. The acceleration magnitude is , and the requested maximum speed is . Ignoring discrete-step effects, what profile is feasible?

Servo and stepper motor control with acceleration profiles Hard
A. A trapezoidal profile cruising at
B. A triangular profile peaking near
C. A triangular profile peaking near
D. A constant-speed profile operating at

55 For a stepper accelerating from rest with constant angular acceleration, how should the interval between successive step pulses change approximately as the step index increases?

Servo and stepper motor control with acceleration profiles Hard
A. It decreases linearly in direct proportion to
B. It remains constant until maximum speed is reached
C. It increases approximately in proportion to
D. It decreases approximately in proportion to

56 A designer changes a stepper from full-step to 16× microstepping and assumes usable positioning accuracy improves exactly 16× under load. Which limitation most directly invalidates that assumption?

Servo and stepper motor control with acceleration profiles Hard
A. The rotor completes 16 revolutions for each commanded revolution
B. Microstepping multiplies the motor's physical step angle by 16
C. The driver removes all holding torque between microstep positions
D. Incremental microstep torque may not overcome friction and load

57 Why can a DMA-generated GPIO waveform have substantially lower timing jitter than a Python loop that repeatedly writes GPIO registers?

Real-time GPIO control using DMA Hard
A. DMA raises Python thread priority before every individual GPIO transition
B. DMA executes a prearranged transfer schedule without per-edge task scheduling
C. DMA disables interrupts and pauses the operating system permanently
D. DMA converts all GPIO pins into independent hardware PWM channels

58 A DMA waveform engine uses PWM or PCM requests to pace writes to GPIO set and clear registers. What primarily determines the waveform's base time resolution?

Real-time GPIO control using DMA Hard
A. The Python interpreter's recursion and thread-switch limits
B. The GPIO input pull-up resistance and output drive strength
C. The number of callbacks registered on unrelated input pins
D. The configured peripheral clock and DMA request pacing

59 A DMA engine samples an input pin every . An asynchronous pulse can remain HIGH for only . Which statement is correct?

Real-time GPIO control using DMA Hard
A. Some pulses can occur entirely between samples and be missed
B. The sampled pulse will always be recorded as two HIGH values
C. Every pulse is guaranteed to appear in at least one sample
D. DMA automatically stretches each pulse to the sampling period

60 A program builds DMA control blocks and data buffers in normal cached memory, then starts DMA immediately. The DMA engine occasionally reads stale descriptors. Which remedy addresses the underlying issue?

Real-time GPIO control using DMA Hard
A. Run a second Python thread that repeatedly rewrites the buffers
B. Use DMA-coherent memory and required synchronization barriers
C. Increase GPIO debounce time before submitting each descriptor
D. Change all output pins from BCM numbering to BOARD numbering