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. GPIO Zero
B. NumPy
C. RPi.GPIO
D. Tkinter

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. Remove event detection
B. Configure a pin's mode
C. Close the Python program
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.output()
B. GPIO.cleanup()
C. GPIO.start()
D. GPIO.input()

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

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

6 Which signal change is called a rising edge?

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

7 What is a callback function in GPIO event handling?

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

8 Why is switch debouncing used with GPIO interrupts?

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

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

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

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 measure network traffic
B. To expand the file system
C. To store the Python program
D. To provide the required current

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. Network address translation
B. Serial text encoding
C. File system mounting
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 motor becomes a sensor
B. The program gains more memory
C. A short circuit may occur
D. The GPIO count may increase

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

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

14 How does a stepper motor normally move?

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

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 map of GPIO pin names
C. A planned change in speed
D. A record of supply voltage

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 adds extra motor coils
C. It changes the motor type
D. It increases the GPIO voltage

17 What does DMA stand for?

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

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

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

19 How does DMA reduce CPU workload during GPIO control?

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

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

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

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.BCM) and use channel 11
C. GPIO.setmode(GPIO.BCM) and use channel 17
D. GPIO.setmode(GPIO.BOARD) and use channel 27

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=True, initial_value=False)
C. OutputDevice(17, active_high=False, initial_value=True)
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.cleanup(18)
B. GPIO.cleanup()
C. GPIO.setup(18, GPIO.IN)
D. GPIO.output(18, GPIO.LOW)

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 a rising-edge event with bouncetime=20
B. Use repeated polling with no delay
C. Use a falling-edge event with bouncetime=1
D. Use both-edge detection without a callback

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. Increase the polling delay to ms
B. Configure the pin as an output first
C. Register a rising-edge event callback
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. Increase the callback's debounce interval substantially
B. Move the network request into every GPIO callback
C. Replace the callback with a longer blocking delay
D. Place event data in a queue and return quickly

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. Read channel B and compare its level with channel A
B. Count channel A edges without reading channel B
C. Measure only how long channel A remains HIGH
D. Toggle channel B whenever channel A changes

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=HIGH, IN2=HIGH, and retain PWM
C. Keep both inputs unchanged and use PWM
D. Set IN1=LOW, IN2=HIGH, and retain 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 capacitor connected only across the logic supply
C. A pull-down resistor on the PWM control input
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. Drive every bridge input HIGH before changing direction
B. Change direction inputs while maintaining maximum PWM
C. Float the GPIO pins and immediately apply reverse PWM
D. Disable PWM, allow dead time, change direction, then ramp 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. Start long and gradually decrease
B. Remain constant at the minimum value
C. Alternate randomly between long and short
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. Reduce the number of motor phases being energized
B. Reverse the direction signal before each step pulse
C. Replace all timing delays with a fixed short delay
D. Apply an acceleration ramp before reaching full speed

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 converts every digital output into an analog output
C. DMA transfers timed data with less CPU scheduling jitter
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. Assign non-conflicting supported DMA channels or use one timing service
B. Increase every waveform delay until the conflict becomes less visible
C. Configure all controlled GPIO pins as inputs during waveform playback
D. Run both libraries in separate Python functions on the same thread

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 PWM duty cycle forces the processor clock to stop periodically
B. The DMA data buffer is not being refilled before it becomes empty
C. The operating system disables all DMA transfers after a fixed duration
D. The GPIO pin automatically changes from output mode to input mode

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. Header pin 11 through automatic BOARD detection
B. BCM GPIO11, not header pin 11
C. BCM GPIO27, because GPIO Zero remaps output pins
D. BCM GPIO17, corresponding to 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 floating; on() drives the pin LOW
B. Initially HIGH; on() drives the pin LOW
C. Initially LOW; on() drives the pin HIGH
D. Initially HIGH; on() leaves the pin HIGH

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. Call GPIO.cleanup() after every PWM duty update
B. Use a DMA-timed pin factory such as pigpio
C. Replace BCM numbering with physical BOARD numbering
D. Increase the Python callback thread's debounce interval

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. Create a separate software PWM instance for every library operation
B. Alternate BCM and BOARD modes before each individual pin operation
C. Disable warnings and depend on process termination to reset all pins
D. Use one abstraction consistently and release devices in finally or context managers

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. Valid pulses within the suppression window may be discarded
B. Each physical pulse will generate callbacks on both edges
C. The callback timestamps will automatically be averaged
D. The GPIO hardware will stretch every pulse to 5 ms

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. Perform all processing inside the callback under one global lock
B. Replace edge detection with repeated calls to GPIO.cleanup()
C. Timestamp and enqueue events quickly, then process them in workers
D. Increase callback computation so several events can be batched

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 read-modify-write sequence is not a protected transaction
B. The GIL forces every callback to execute in another process
C. Edge callbacks bypass Python and modify the counter using DMA
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. Trigger only on channel A and ignore channel B entirely
B. Add a long debounce interval to both encoder channels
C. Capture transitions with hardware counters or DMA sampling
D. Run two unrestricted callbacks that update one shared integer

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. Shoot-through current directly across the supply
B. Reduced PWM frequency caused by armature inductance
C. Loss of motor torque caused only by back-EMF cancellation
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 supply rail rises above its safe voltage
B. The logic inputs permanently change their threshold voltage
C. The H-bridge PWM frequency becomes exactly doubled
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. Equal inputs always reverse the motor at maximum duty cycle
B. Coast and brake truth tables differ among driver architectures
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. 2% to 4%
C. 10% to 20%
D. 5% to 10%

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 decreases approximately in proportion to
D. It increases 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. Microstepping multiplies the motor's physical step angle by 16
B. The rotor completes 16 revolutions for each commanded revolution
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 converts all GPIO pins into independent hardware PWM channels
C. DMA executes a prearranged transfer schedule without per-edge task scheduling
D. DMA disables interrupts and pauses the operating system permanently

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 GPIO input pull-up resistance and output drive strength
B. The number of callbacks registered on unrelated input pins
C. The Python interpreter's recursion and thread-switch limits
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. DMA automatically stretches each pulse to the sampling period
B. Some pulses can occur entirely between samples and be missed
C. Every pulse is guaranteed to appear in at least one sample
D. The sampled pulse will always be recorded as two HIGH values

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. Increase GPIO debounce time before submitting each descriptor
B. Use DMA-coherent memory and required synchronization barriers
C. Change all output pins from BCM numbering to BOARD numbering
D. Run a second Python thread that repeatedly rewrites the buffers