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

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

Python libraries: RPi.GPIO and GPIO Zero Easy
A. Servo
B. LED
C. Motor
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. Read a pin's voltage
D. Remove event detection

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 increases the supply voltage
C. It changes the board model
D. It adds more physical pins

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 installs the operating system
B. A function that supplies motor power
C. A function run when an event occurs
D. A function that changes pin numbering

8 Why is switch debouncing used with GPIO interrupts?

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

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. Reverse a motor's direction
D. Store a motor's position

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

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. Pulse-width modulation
B. File system mounting
C. Network address translation
D. Serial text encoding

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. A short circuit may occur
B. The GPIO count may increase
C. The motor becomes a sensor
D. The program gains more memory

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. Random voltage spikes
D. Stored network packets

14 How does a stepper motor normally move?

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

15 What is an acceleration profile in motor control?

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

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

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

17 What does DMA stand for?

Real-time GPIO control using DMA Easy
A. Direct Memory Access
B. Data Measurement Array
C. Dynamic Module Allocation
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 consistent signal timing
C. More physical GPIO pins
D. Higher GPIO voltage levels

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. Generating precisely timed pulses
C. Displaying static text documents
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=False, initial_value=False)
B. OutputDevice(17, active_high=False, initial_value=True)
C. OutputDevice(17, active_high=True, initial_value=True)
D. OutputDevice(17, active_high=True, 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()
C. GPIO.cleanup(18)
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 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. Read the input twice per loop
B. Configure the pin as an output first
C. Increase the polling delay to ms
D. Register a rising-edge event callback

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. Replace the callback with a longer blocking delay
B. Place event data in a queue and return quickly
C. Increase the callback's debounce interval substantially
D. Move the network request into every GPIO callback

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. Toggle channel B whenever channel A changes
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=HIGH, IN2=HIGH, and retain PWM
B. Set IN1=LOW, IN2=LOW, 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. A larger resistor in series with each GPIO input
B. A capacitor connected only across the logic supply
C. A pull-down resistor on the PWM control input
D. Flyback diodes across the motor current paths

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. Start long and gradually decrease
C. Start short and gradually increase
D. Alternate randomly between long and short

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. Apply an acceleration ramp before reaching full speed
B. Reduce the number of motor phases being energized
C. Reverse the direction signal before each step pulse
D. Replace all timing delays with a fixed short delay

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 transfers timed data with less CPU scheduling jitter
B. DMA removes the need to configure GPIO pin directions
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. Assign non-conflicting supported DMA channels or use one timing service
B. Configure all controlled GPIO pins as inputs during waveform playback
C. Increase every waveform delay until the conflict becomes less visible
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 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 PWM duty cycle forces the processor clock to stop periodically
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. BCM GPIO11, not header pin 11
B. BCM GPIO17, corresponding to header pin 11
C. Header pin 11 through automatic BOARD detection
D. BCM GPIO27, because GPIO Zero remaps output pins

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() leaves the pin HIGH
B. Initially floating; on() drives the pin LOW
C. Initially LOW; on() drives the pin HIGH
D. Initially HIGH; 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. Increase the Python callback thread's debounce interval
B. Call GPIO.cleanup() after every PWM duty update
C. Replace BCM numbering with physical BOARD numbering
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. Alternate BCM and BOARD modes before each individual pin operation
C. Create a separate software PWM instance for every library operation
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. Each physical pulse will generate callbacks on both edges
B. Valid pulses within the suppression window may be discarded
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. Timestamp and enqueue events quickly, then process them in workers
C. Replace edge detection with repeated calls to GPIO.cleanup()
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. Integer variables are stored directly in GPIO peripheral memory
C. The GIL forces every callback to execute in another process
D. Edge callbacks bypass Python and modify the counter using DMA

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. Add a long debounce interval to both encoder channels
C. Capture transitions with hardware counters or DMA sampling
D. Trigger only on channel A and ignore channel B entirely

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. Reduced PWM frequency caused by armature inductance
B. Permanent coasting because both motor terminals float
C. Loss of motor torque caused only by back-EMF cancellation
D. Shoot-through current directly across the supply

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 motor winding resistance falls nearly to zero
D. The H-bridge PWM frequency becomes exactly doubled

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. 10% to 20%
C. 5% to 10%
D. 2% to 4%

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 constant-speed profile operating at
D. A triangular profile peaking near

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 remains constant until maximum speed is reached
B. It increases approximately in proportion to
C. It decreases linearly in direct 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 driver removes all holding torque between microstep positions
B. Microstepping multiplies the motor's physical step angle by 16
C. Incremental microstep torque may not overcome friction and load
D. The rotor completes 16 revolutions for each commanded revolution

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 disables interrupts and pauses the operating system permanently
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 raises Python thread priority before every individual GPIO transition

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 number of callbacks registered on unrelated input pins
B. The Python interpreter's recursion and thread-switch limits
C. The configured peripheral clock and DMA request pacing
D. The GPIO input pull-up resistance and output drive strength

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. The sampled pulse will always be recorded as two HIGH values
D. Every pulse is guaranteed to appear in at least one sample

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