Unit 1: Setting Up and GPIO Handling - Subjective Questions
ECE140 — Workshop On Iot For Digital Society • Practice Questions with Detailed Answers
20 questions
Define the Raspberry Pi and explain its importance in Internet of Things applications.
Raspberry Pi is a low-cost, credit-card-sized single-board computer developed to support computer education, programming, electronics, and embedded-system development.
Important features include:
- A processor, memory, USB ports, display output, networking, and storage support on one board.
- A general-purpose input/output (GPIO) header for connecting electronic components.
- Support for operating systems such as Raspberry Pi OS.
- Communication interfaces including I2C, SPI, UART, Wi-Fi, Bluetooth, and Ethernet, depending on the model.
Importance in IoT:
- It can collect data from sensors through GPIO pins.
- It can control actuators such as LEDs, relays, motors, and buzzers.
- It can process data locally at the edge.
- It can transmit data to cloud platforms through a network.
- It supports programming languages such as Python, C, and Java.
Thus, the Raspberry Pi provides an effective platform for prototyping smart homes, environmental monitoring systems, industrial automation, and other digital-society applications.
Describe the procedure for downloading and installing the Raspberry Pi Imager.
The Raspberry Pi Imager is an official utility used to write Raspberry Pi OS and other operating-system images to a microSD card.
Procedure:
- Visit the official Raspberry Pi website and open the software or downloads section.
- Select Raspberry Pi Imager for the host operating system, such as Windows, macOS, or Linux.
- Download the installer package.
- Run the installer with the necessary system permissions.
- Follow the installation instructions and launch Raspberry Pi Imager.
- Insert a suitable microSD card into the computer using a card reader.
- In the Imager, select the Raspberry Pi model, operating system, and storage device.
- Configure optional settings such as hostname, username, password, wireless network, locale, and remote access.
- Select Write and wait for writing and verification to finish.
- Safely eject the card and insert it into the Raspberry Pi.
All important files on the selected storage device are erased during writing, so the device must be selected carefully.
Explain how Raspberry Pi OS can be installed and initially configured using Raspberry Pi Imager.
Installation and initial configuration involve the following stages:
- Prepare the hardware: Obtain a Raspberry Pi, compatible power supply, microSD card, and a computer with a card reader.
- Launch Raspberry Pi Imager: Open the installed Imager application.
- Select the device: Choose the correct Raspberry Pi model when this option is available.
- Choose the operating system: Select Raspberry Pi OS. The desktop, full, or Lite version may be chosen according to the application.
- Choose storage: Select the correct microSD card or supported storage device.
- Configure customization options: Set the hostname, username, secure password, Wi-Fi details, time zone, keyboard layout, and remote-access settings.
- Write the image: Confirm the erase warning and allow the Imager to write and verify the operating-system image.
- First boot: Insert the card into the Raspberry Pi, connect required peripherals, and power it on.
- Complete setup: Follow any first-boot prompts and connect the system to the network.
- Test the installation: Open a terminal, check network access, and verify that peripherals are recognized.
Preconfiguring the system in Raspberry Pi Imager is especially useful for a headless setup, where no dedicated monitor or keyboard is connected.
Why should Raspberry Pi OS be updated after installation? Describe the commands and precautions involved.
Updating Raspberry Pi OS provides recent security fixes, software corrections, stability improvements, and compatible device drivers.
Common update procedure:
- Refresh the package index using
sudo apt update. - Review the list of available updates if required.
- Install available package upgrades using
sudo apt full-upgrade. - Remove unneeded packages, when appropriate, using
sudo apt autoremove. - Restart with
sudo rebootif the kernel, firmware, or major system components were updated.
Difference between the main commands:
apt updatedownloads current information about packages; it does not install the updates.apt full-upgradeinstalls updates and can resolve changing dependencies by adding or removing packages when required.
Precautions:
- Use a stable power supply and network connection.
- Avoid switching off the Raspberry Pi during an update.
- Back up important files before major upgrades.
- Maintain sufficient free storage space.
- Do not use unrelated third-party package repositories without verifying their reliability.
Regularly updating the system reduces vulnerabilities and improves the reliability of IoT deployments.
Describe the installation and configuration of RealVNC for remotely accessing a Raspberry Pi desktop.
RealVNC allows the Raspberry Pi desktop to be viewed and controlled from another computer over a network.
Typical procedure:
- Connect the Raspberry Pi and client computer to an accessible network.
- Install RealVNC Server from the supported Raspberry Pi OS repository or official package when it is not already available.
- Enable the VNC service through the Raspberry Pi configuration utility or the relevant service settings.
- Reboot or restart the VNC service if requested.
- Find the Raspberry Pi IP address using the network settings or the
hostname -Icommand. - Install VNC Viewer on the client computer.
- Enter the Raspberry Pi hostname or IP address in VNC Viewer.
- Authenticate with the configured credentials and accept the connection only after verifying the device.
Security measures:
- Use a strong password and a non-default username.
- Keep the VNC software and operating system updated.
- Do not expose the VNC port directly to the public Internet.
- Prefer a trusted local network, VPN, SSH tunnel, or supported encrypted cloud connection.
The exact VNC server and desktop-session compatibility may depend on the Raspberry Pi OS release and display system.
Explain the purpose of the Raspberry Pi GPIO header and classify its major pin functions.
The GPIO header is a group of physical pins used to connect the Raspberry Pi with external electronic circuits.
Major pin categories are:
- General-purpose input pins: Read digital signals from switches, sensors, and other devices.
- General-purpose output pins: Generate digital HIGH or LOW signals for LEDs and control circuits.
- Power pins: Supply regulated or , subject to board and power limitations.
- Ground pins: Provide the common electrical reference and return path.
- I2C pins: Support two-wire communication using SDA and SCL.
- SPI pins: Support high-speed synchronous communication using signals such as MOSI, MISO, SCLK, and chip enable.
- UART pins: Support serial communication through transmit and receive signals.
- PWM-capable pins: Certain GPIO pins can provide hardware PWM functions through their alternate modes.
A pin may have more than one alternate function, but only one configured function can be used at a time. The GPIO header therefore enables the Raspberry Pi to interact with a wide range of IoT sensors and actuators.
Distinguish between physical pin numbering, BCM GPIO numbering, and wiring-library numbering on a Raspberry Pi.
Physical numbering:
- Refers to the actual sequential positions on the GPIO header.
- For example, physical pin 1 is the first pin on the header.
- It includes power, ground, and GPIO pins.
BCM numbering:
- Refers to the GPIO numbers assigned by the Broadcom system-on-chip.
- For example, BCM GPIO17 may be located at a different physical pin number.
- It is widely used by modern GPIO libraries and technical documentation.
Wiring-library numbering:
- Some older libraries use their own logical numbering scheme.
- These numbers may not match either the physical position or the BCM number.
- Such schemes should only be used when the selected library explicitly requires them.
Importance:
- A program and circuit diagram must use the same numbering convention.
- Confusing physical and BCM numbers may activate the wrong pin.
- Connecting a component to a power pin instead of a GPIO pin can damage the circuit.
The pinout diagram for the exact Raspberry Pi model should always be checked before making connections.
Describe how to identify power, ground, GPIO, and alternate-function pins on the Raspberry Pi header.
Pins should be identified using a reliable pinout diagram for the exact Raspberry Pi model and header orientation.
Identification process:
- Locate the board orientation and physical pin 1.
- Identify the dedicated power pins used by compatible low-voltage components.
- Identify the power pins, which must not be connected directly to a GPIO input.
- Locate the multiple GND pins, all of which provide a common ground reference.
- Identify GPIO pins by their BCM numbers.
- Check each pin's alternate functions, such as I2C, SPI, UART, clock, or PWM.
- Confirm which numbering mode is used in the program.
Good practices:
- Power off the board before changing wiring.
- Never identify pins by wire color alone.
- Do not assume that every GPIO supports every peripheral function.
- Avoid using pins reserved by an attached hardware module.
- Confirm voltage and current requirements before connecting a device.
Correct pin identification prevents wiring errors and ensures that software controls the intended circuit.
Explain the circuit and program logic required to blink an LED using a Raspberry Pi GPIO pin.
Circuit:
- Connect a GPIO output pin to a current-limiting resistor.
- Connect the resistor to the LED anode.
- Connect the LED cathode to a Raspberry Pi GND pin.
- A resistor in the approximate range of a few hundred ohms is commonly used, but it should be calculated for the chosen LED.
Program logic:
- Import a supported GPIO-control library.
- Select BCM or physical numbering.
- Configure the chosen GPIO pin as an output.
- Set the output HIGH to turn the LED on.
- Wait for a specified time.
- Set the output LOW to turn the LED off.
- Wait again and repeat the sequence.
- On program termination, release or reset the GPIO resource when required by the library.
Conceptual pseudocode:
- Configure LED pin as output.
- Repeat:
- LED ON.
- Delay.
- LED OFF.
- Delay.
The resistor protects both the LED and the GPIO pin by limiting current. The actual HIGH and LOW behavior may be reversed if the LED is wired in an active-low arrangement.
Derive the current-limiting resistor value for an LED connected to a Raspberry Pi GPIO. Assume a GPIO HIGH voltage of , an LED forward voltage of , and a desired current of .
The resistor must drop the voltage remaining after the LED forward voltage is subtracted from the GPIO output voltage.
Step 1: Calculate the resistor voltage
Step 2: Apply Ohm's law
The required current is:
Therefore:
Step 3: Select a standard resistor
A standard value equal to or greater than the result should be selected. For example, a or resistor can be used. The larger value produces slightly less current and provides a greater safety margin.
Power check:
At approximately , the resistor dissipates only a few milliwatts, so a typical low-power resistor is sufficient.
The selected current must remain within the LED rating and the Raspberry Pi GPIO electrical limits.
Describe how a push-button switch can be interfaced with a Raspberry Pi using a pull-up resistor.
In a pull-up configuration, the input remains at a defined HIGH level while the switch is open.
Connections:
- Configure a GPIO pin as an input.
- Connect one terminal of the push button to the GPIO input.
- Connect the other terminal to GND.
- Enable the Raspberry Pi's internal pull-up resistor, or connect a suitable external resistor between the input and .
Operation:
- Switch open: The pull-up resistor holds the input at logic HIGH.
- Switch pressed: The switch connects the input to GND, producing logic LOW.
Therefore, the switch is active-low, meaning that a LOW value indicates a press.
Program logic:
- Configure the pin as an input with pull-up enabled.
- Read its digital state.
- If the state is LOW, perform the required action.
- Apply debouncing so that a single press is not interpreted as multiple presses.
The GPIO should never be connected directly between and GND through a closed switch. The pull-up resistor limits current and establishes a stable default state.
Compare pull-up and pull-down resistor configurations used in Raspberry Pi switch interfacing.
| Feature | Pull-up configuration | Pull-down configuration |
|---|---|---|
| Default connection | Input is weakly connected to | Input is weakly connected to GND |
| Open-switch state | HIGH | LOW |
| Typical pressed state | LOW when switched to GND | HIGH when switched to |
| Logic type | Usually active-low | Usually active-high |
| Main purpose | Prevents a floating input | Prevents a floating input |
Pull-up operation:
- A resistor holds the GPIO input HIGH.
- Pressing the switch connects it to GND.
Pull-down operation:
- A resistor holds the GPIO input LOW.
- Pressing the switch connects it to .
Both configurations provide a known logic level when the switch is open. Raspberry Pi GPIO libraries generally allow compatible internal pull-up or pull-down resistors to be enabled in software. A direct connection from a GPIO input to must not be used because Raspberry Pi GPIO pins are not normally tolerant.
What is switch bouncing? Explain hardware and software methods of debouncing a switch connected to a Raspberry Pi.
Switch bouncing is the rapid making and breaking of electrical contact that occurs for a short time when a mechanical switch is pressed or released. Instead of one clean transition, the GPIO may detect several HIGH-to-LOW and LOW-to-HIGH transitions.
Effects:
- One press may be counted multiple times.
- Interrupt or event callbacks may execute repeatedly.
- An LED or actuator may behave unpredictably.
Software debouncing methods:
- Add a short delay after detecting a state change.
- Ignore additional events for a defined debounce interval.
- Sample the input repeatedly and accept the new state only if it remains stable.
- Use a library's built-in debounce or event-suppression option.
Hardware debouncing methods:
- Use a resistor-capacitor network to filter rapid transitions.
- Add a Schmitt-trigger buffer to produce a clean digital edge.
- Use a dedicated debounce integrated circuit for demanding applications.
A simple delay is suitable for basic experiments, whereas stable sampling or hardware filtering is more reliable when fast response and accurate event detection are required.
Define pulse-width modulation and explain duty cycle, frequency, and its use in controlling an LED.
Pulse-width modulation (PWM) is a technique in which a digital output is switched rapidly between HIGH and LOW. The average power supplied to a load is controlled by changing the fraction of time for which the signal remains HIGH.
The duty cycle is:
where:
- is the HIGH time.
- is the total period.
- is the duty cycle.
The frequency is:
LED control:
- At a duty cycle, the LED is off.
- At a duty cycle, the LED receives approximately half of the maximum average drive.
- At a duty cycle, the LED is continuously on.
When the PWM frequency is sufficiently high, the human eye does not observe individual pulses. Instead, it perceives a change in brightness.
PWM can be produced by hardware peripherals or by software timing. Hardware PWM generally provides more stable timing, while software PWM is convenient but may be affected by operating-system activity.
Distinguish between digital GPIO output, software PWM, and hardware PWM on a Raspberry Pi.
Digital GPIO output:
- Produces a steady HIGH or LOW logic level.
- Suitable for turning an LED, logic input, or control signal fully on or off.
- It does not directly provide intermediate output levels.
Software PWM:
- Generates pulses by changing a GPIO state according to software timing.
- Can often be used on many GPIO pins.
- Is simple and flexible for basic LED dimming.
- Timing can be disturbed by operating-system scheduling and processor load.
Hardware PWM:
- Is generated by dedicated hardware peripherals.
- Provides more accurate and stable frequency and duty cycle.
- Is available only on GPIO pins that support the appropriate alternate function.
- Is preferred for applications requiring precise timing.
Comparison:
- Digital output is best for basic ON/OFF control.
- Software PWM is adequate for non-critical applications.
- Hardware PWM is more suitable for stable brightness control, audio-related signals, and other timing-sensitive tasks.
PWM is still a sequence of digital pulses; it is not automatically a true analog voltage.
Explain how a switch can be used to control the brightness or operating mode of a PWM-driven LED.
A switch can act as a user input while PWM controls the average power delivered to an LED.
Hardware arrangement:
- Connect the LED to a PWM-capable or software-PWM GPIO through a current-limiting resistor.
- Connect the switch to a separate GPIO input.
- Use an internal or external pull-up or pull-down resistor.
- Join all circuit grounds to the Raspberry Pi ground.
Possible program operation:
- Configure the LED pin for PWM output.
- Configure the switch pin as a digital input.
- Start PWM at a selected frequency and duty cycle.
- Detect a valid switch press after debouncing.
- Increase the duty cycle in steps, such as , , , , and .
- Return to after the highest level.
- Stop PWM and release GPIO resources when the program exits.
Alternatively, the LED can remain bright only while the button is pressed, or a long press can select a different operating mode.
The program should use edge detection or controlled polling and should include debouncing to avoid multiple unwanted brightness changes.
Explain the major electrical characteristics of Raspberry Pi GPIO pins that must be considered while designing an interface.
Important GPIO electrical characteristics include:
- Logic voltage: Raspberry Pi GPIO uses approximately logic.
- Lack of normal tolerance: Applying directly to a GPIO input can damage the processor.
- Output current limitation: A GPIO pin is intended for small logic-level loads, not for directly powering motors, relays, or high-current lamps.
- Total current limitation: The combined current drawn from multiple GPIO pins and power rails must remain within model-specific limits.
- Input state: An input without a pull-up or pull-down resistor may float and produce unpredictable readings.
- Power-on behavior: GPIO states and alternate functions may change during startup, so connected hardware must tolerate safe initial states.
- Shared functions: Some pins are used by interfaces such as I2C, SPI, and UART.
- Common ground: Externally powered circuits usually require a common reference ground unless electrical isolation is used.
The exact electrical limits should be verified using official documentation for the particular Raspberry Pi model rather than relying on one universal current figure.
Describe the protection methods required when interfacing LEDs, relays, motors, and higher-voltage signals with Raspberry Pi GPIO.
LED protection:
- Use a series current-limiting resistor.
- Check LED polarity and current requirements.
Relay and motor protection:
- Do not drive a relay coil or motor directly from a GPIO pin.
- Use a transistor or logic-level MOSFET as a driver.
- Add an appropriate base or gate resistor.
- Place a flyback diode across an inductive DC load to suppress the voltage spike generated when it is switched off.
- Use a separate power supply when the load requires more current than the Raspberry Pi can provide.
Higher-voltage signal protection:
- Use a resistor divider, level shifter, buffer, or optocoupler as appropriate.
- Never apply or a higher voltage directly to a GPIO input.
General protection:
- Connect grounds correctly when isolation is not used.
- Add fuses or current limiting where appropriate.
- Protect against reverse polarity, electrostatic discharge, and wiring mistakes.
- Keep mains-voltage circuitry isolated and use certified modules and safe enclosures.
These methods prevent overcurrent, overvoltage, and inductive transients from damaging the Raspberry Pi.
Compare polling and event-driven methods for detecting a switch press on a Raspberry Pi.
Polling:
- The program repeatedly reads the GPIO input in a loop.
- It is simple to understand and suitable for introductory programs.
- Frequent polling can waste processor time.
- Slow polling may miss short-duration events.
- A delay is often added to reduce processor usage and support debouncing.
Event-driven detection:
- The GPIO library monitors a selected edge, such as rising, falling, or both.
- A callback or waiting function is triggered when the edge occurs.
- The main program can perform other tasks while waiting.
- It is generally more efficient for occasional events.
- Callback functions should be short, thread-safe where applicable, and properly debounced.
Comparison:
- Polling is preferable for simple learning exercises and programs that already have a regular control loop.
- Event-driven detection is preferable for responsive multitasking applications.
- Both methods can produce false events if switch bouncing is not handled.
The chosen edge depends on the circuit. For an active-low pull-up circuit, pressing the button normally creates a falling edge.
Design a safe Raspberry Pi experiment in which a push button controls an LED, and explain the circuit, algorithm, testing procedure, and safety precautions.
Circuit design:
- Select one GPIO pin as the LED output.
- Connect the output to a calculated current-limiting resistor and then to the LED anode.
- Connect the LED cathode to GND.
- Select a second GPIO pin as the switch input.
- Connect the switch between the input and GND.
- Enable the internal pull-up resistor so the switch operates as an active-low input.
Algorithm:
- Initialize the GPIO library.
- Configure the LED pin as an output and set it to the safe OFF state.
- Configure the switch pin as an input with a pull-up resistor.
- Read the switch by polling or edge detection.
- After debouncing, turn the LED on when the switch is pressed.
- Turn the LED off when the switch is released, or toggle it once per press according to the design.
- Handle program termination and release GPIO resources.
Testing procedure:
- Verify all pin numbers against the board pinout.
- Inspect LED polarity and resistor placement with the power disconnected.
- Start the program and confirm the default LED state.
- Press and release the switch several times.
- Check for false multiple activations and adjust debouncing if necessary.
Safety precautions:
- Use only logic at GPIO inputs.
- Never short a power pin to GND.
- Do not change connections while the board is powered.
- Use a stable power supply and avoid exceeding GPIO current limits.
Define the Raspberry Pi and explain its importance in Internet of Things applications.
Raspberry Pi is a low-cost, credit-card-sized single-board computer developed to support computer education, programming, electronics, and embedded-system development.
Important features include:
- A processor, memory, USB ports, display output, networking, and storage support on one board.
- A general-purpose input/output (GPIO) header for connecting electronic components.
- Support for operating systems such as Raspberry Pi OS.
- Communication interfaces including I2C, SPI, UART, Wi-Fi, Bluetooth, and Ethernet, depending on the model.
Importance in IoT:
- It can collect data from sensors through GPIO pins.
- It can control actuators such as LEDs, relays, motors, and buzzers.
- It can process data locally at the edge.
- It can transmit data to cloud platforms through a network.
- It supports programming languages such as Python, C, and Java.
Thus, the Raspberry Pi provides an effective platform for prototyping smart homes, environmental monitoring systems, industrial automation, and other digital-society applications.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →