Processor Architecture and Interfacing Lab Manual
Processor Architecture and Interfacing Lab Manual
Lab Manual
Second Year
Information Technology
i. Mission
To prepare students for employment/entrepreneurship/higher studies through
curricular, extracurricular and extension activities.
ii. To promote research and professional activities through industry involvement and
professional bodies
iii. To instil professional ethics and lifelong learning skills with concern for the society.
Programme Educational Objectives
Graduates will
i. Excel in diverse career paths with core professional skills.
ii. Engage in multi domain research/professional activities.
iii. Cater to the needs of society with IT solutions/applications.
Program Specific Outcomes
Graduates will be able to
1. Use database, networking and programming technologies for solving real life problems.
2. Develop applications in the field of computing, networking, security and analytics.
Program Outcomes
Graduates will be able to
Course Objectives
1 To explain embedded C programming concepts to interface different I/O.
2 To apply knowledge of programming for interfacing of different I/O.
3 To make use of Python Programming to interface I/O using Raspberry Pi.
List of Experiments
Sr.
Page
No Problem Statement
No.
.
Arduino IDE – ESP32 GPIO programming, LED blinking and button input
1 7
and print on serial terminal (UART).
2 Arduino IDE – ESP32 OLED display interfacing (I2C interface).
3 Arduino IDE – ESP32 generate PWM signal and operate servo motor.
4 ESP-IDF – ESP32 UART, read, write/ print data (RTOS)
ESP-IDF – ESP32 4x4 keypad, display key pressed on OLED display.
5
(RTOS, separate tasks)
ESP-IDF – using NIMBLE send data to mobile/ PC Bluetooth terminal
6
(RTOS)
7 ESP-IDF – using Wi-Fi send data to AWS IOT core via MQTT (RTOS).
8 Raspberry Pi – flashing Raspberry Pi OS and setting up Raspberry Pi.
9 Raspberry Pi – write a basic python script to blink an LED and print data.
Raspberry Pi – MQTT server data posting and subscribing (in Python
10
script)
11 Raspberry Pi – interfacing DHT sensor with Raspberry Pi.
12* Mini project using ESP 32, Raspberry Pi or any other microcontroller.
Page | 5
Processor Architecture and Interfacing
Department of Information Technology
Experiment – 1
Aim
To program the ESP32 for controlling GPIO pins for various tasks such as blinking LEDs,
taking button input, and printing with real-time data output on the serial terminal(UART).
Problem Statement
Arduino IDE – ESP32 GPIO programming, LED blinking and button input and print on serial
terminal (UART).
Hardware Required
ESP32-Microcontroller Development board.
Objectives
1. To understand the ESP32 GPIO pin configuration for input and output tasks.
2. To implement LED blinking using multiple GPIO pins.
3. To integrate button input functionality and replicate its state on LEDs.
4. To print messages or outputs on the serial terminal using UART communication.
Theory
1. GPIO (General Purpose Input/Output):
o ESP32 microcontroller supports multiple GPIO pins that can be configured for
input or output purposes.
o The pinMode function is used to set a pin as INPUT or OUTPUT.
2. LED Blinking:
o LEDs are controlled by applying HIGH (ON) or LOW (OFF) signals to the
GPIO pins.
o digitalWrite(pin, state) is used for controlling the state of the LED.
3. Button Input:
o Buttons can be connected to GPIO pins to detect their state (pressed or not
pressed).
o digitalRead(pin) is used to read the input state of a button.
4. Serial Communication (UART):
Page | 6
Processor Architecture and Interfacing
Department of Information Technology
o Serial communication allows data transfer between the ESP32 and a computer
for debugging and monitoring.
o The Serial.begin(baudRate) function initializes the UART at a specified baud
rate.
o 3 UART’s are present in ESP32
o UART initialisation:
1. Setting Communication Parameters - Setting baud rate, data bits, stop
bits, etc.
2. Setting Communication Pins- Assigning pins for connection to a
device.
3. Driver Installation - Allocating ESP32’s resources for the UART
driver.
4. Running UART Communication - Sending / receiving data
5. Using Interrupts - Triggering interrupts on specific communication
events
6. Deleting a Driver- Freeing allocated resources if a UART
communication is no longer required
5. Delays:
o The delay(ms) function introduces pauses between operations for timing
control.
Conclusion
By completing this project, you:
Learned the basics of GPIO programming on the ESP32.
Successfully implemented LED blinking using GPIO pins.
Understood how to use buttons as inputs and replicate their state on LEDs.
Sent real-time output to the serial terminal, demonstrating UART communication.
This project forms a foundation for understanding ESP32 GPIO programming and can
be extended for more complex IoT applications.
Page | 7
Processor Architecture and Interfacing
Department of Information Technology
Experiment – 2
Aim
To interface an ESP32 microcontroller with an OLED display using the I2C communication
protocol and display text or graphical information on the OLED screen.
Problem Statement
Arduino IDE – ESP32 OLED display interfacing (I2C interface).
Hardware Required
ESP32-Microcontroller Development board
OLED Display
Objectives
1. To understand the I2C communication protocol and its implementation with ESP32.
2. To learn how to interface an OLED display with the ESP32.
3. To display text, shapes, and basic graphical information on the OLED screen.
4. To implement libraries and functions for OLED screen control in the Arduino IDE.
Theory
ESP32 Microcontroller
ESP32 is a low-cost, low-power system on a chip (SoC) with integrated Wi-Fi and
Bluetooth capabilities. It is widely used in IoT projects. It has GPIO pins that can be
configured for I2C communication.
OLED Display
An OLED (Organic Light-Emitting Diode) display is a lightweight and efficient
display technology. It is commonly used in IoT devices for visual output. The
SSD1306 OLED is one of the popular modules, typically having a resolution of
128x64 pixels.
I2C Protocol
I2C (Inter-Integrated Circuit) is a communication protocol that uses two lines:
SDA (Data Line): Transfers data between devices.
SCL (Clock Line): Synchronizes the data transfer.
Multiple devices can communicate over the same I2C bus using unique addresses.
ESP32 has 2 I2C pins
Page | 8
Processor Architecture and Interfacing
Department of Information Technology
The ESP32 has two I²C (Inter-Integrated Circuit) interfaces, which means it
supports two I²C buses that can be used independently.
I²C Details on ESP32:
Number of I²C interfaces: 2
Default I²C pins:
o I²C0 (Default for Wire Library)
SDA (Data Line): GPIO21
SCL (Clock Line): GPIO22
o I²C1 (Can be customized)
SDA: Any GPIO
SCL: Any GPIO
Maximum Clock Speed: 400 kHz (Fast Mode)
Working
1. The ESP32 communicates with the OLED using the I2C protocol.
2. The SDA and SCL pins of the ESP32 are connected to the respective pins of the
OLED module.
3. Libraries such as Adafruit_SSD1306 and Adafruit_GFX are used for easy interfacing
and graphical display.
Connections
ESP32 Pin OLED Pin
GPIO21 (SDA) SDA
GPIO22 (SCL) SCL
GND GND
3.3V VCC
Conclusion
By interfacing the ESP32 with the OLED display using the I2C protocol, we successfully
displayed text and graphical information. This experiment enhanced our understanding of I2C
Page | 9
Processor Architecture and Interfacing
Department of Information Technology
communication and the use of libraries for display control. The setup can be extended for
various IoT applications such as displaying sensor data or interactive UI elements.
Page | 10
Processor Architecture and Interfacing
Department of Information Technology
Experiment – 3
Aim
To generate a PWM (Pulse Width Modulation) signal using the ESP32 microcontroller and
use it to control the movement of a servo motor.
Problem Statement
Arduino IDE – ESP32 generate PWM signal and operate servo motor.
Hardware Required
ESP32-Microcontroller Development board
Servo Motor
Objectives
1. To understand the concept of PWM and its implementation using ESP32.
2. To control a servo motor using PWM signals generated by ESP32.
3. To learn how to vary the servo motor's angle by modifying the PWM signal.
4. To implement ESP32's built-in PWM functionalities using the Arduino IDE.
Theory
Pulse Width Modulation (PWM):
PWM is a technique for generating analogue results using digital signals. It involves
varying the width of the pulses in a signal to control the power delivered to a device.
The duty cycle of a PWM signal determines the average voltage level, which can be
used to control devices like LEDs, motors, or servos.
ESP32 PWM Capabilities:
The ESP32 microcontroller has built-in PWM support and can generate PWM signals
on multiple GPIO pins.
The frequency, duty cycle, and resolution of the PWM signal can be configured
programmatically.
Servo Motor Control:
A servo motor is an actuator that uses PWM signals to control its shaft's angular
position, speed, and direction.
Page | 11
Processor Architecture and Interfacing
Department of Information Technology
Typical servo motors operate with a PWM frequency of 50 Hz, where:
o A 1 ms pulse width corresponds to 0°.
o A 1.5 ms pulse width corresponds to 90°.
o A 2 ms pulse width corresponds to 180°.
Working Principle:
1. ESP32 generates a PWM signal on a GPIO pin configured as an output.
2. The signal is sent to the control pin of the servo motor.
3. The pulse width determines the servo motor's shaft position.
Connections:
ESP32 Servo Pin
Pin
GPIO18 Control (Signal)
GND GND
3.3V/5V VCC (Power)
Conclusion
By generating a PWM signal using ESP32 and controlling a servo motor, we successfully
demonstrated:
The use of ESP32's PWM functionality.
How varying the duty cycle controls the servo's angular position.
This experiment has applications in robotics, IoT systems, and other projects
requiring precise motor control.
Page | 12
Processor Architecture and Interfacing
Department of Information Technology
Experiment – 4
Aim
To demonstrate UART (Universal Asynchronous Receiver-Transmitter) communication on
ESP32 using ESP-IDF and Real-Time Operating System (RTOS) by reading and
writing/printing data.
Problem Statement
ESP-IDF – ESP32 UART, read, write/ print data (RTOS)
Hardware Required
ESP32-Microcontroller Development board
Objectives
1. To understand UART communication and its role in data exchange between devices.
2. To learn how to configure and use UART communication using the ESP-IDF
framework.
3. To implement reading and writing of data through UART in an RTOS-based
environment.
4. To explore multi-tasking capabilities of RTOS for efficient UART data handling.
Theory
ESP32 UART Communication:
UART is a hardware communication protocol used for asynchronous serial
communication.
It involves two main pins:
o TX (Transmit): Sends data.
o RX (Receive): Receives data.
The baud rate determines the speed of communication (e.g., 9600, 115200 bps).
ESP32 and UART:
ESP32 supports three UART controllers (UART0, UART1, and UART2).
It is commonly used for debugging, sensor interfacing, and communication with
external modules like GPS, GSM, etc.
Page | 13
Processor Architecture and Interfacing
Department of Information Technology
ESP-IDF and RTOS:
ESP-IDF (Espressif IoT Development Framework) is the official framework for
programming ESP32 devices.
FreeRTOS, integrated into ESP-IDF, allows multi-tasking and resource sharing.
UART tasks can be handled in parallel using separate RTOS threads.
Working:
1. UART Configuration:
o Configure the UART parameters (baud rate, data bits, parity, stop bits).
o Initialize the UART driver in ESP-IDF.
2. Data Transmission:
o Use uart_write_bytes() to send data through UART.
3. Data Reception:
o Use uart_read_bytes() to read data received on UART.
4. RTOS Integration:
o Create tasks for transmitting and receiving data to demonstrate concurrent
operation.
Connections:
ESP32 UART Function
Pin
GPIO1 TX (Transmit)
GPIO3 RX (Receive)
GND GND
Conclusion
By implementing UART communication on ESP32 using ESP-IDF and RTOS, we
successfully:
Configured UART for transmitting and receiving data.
Page | 14
Processor Architecture and Interfacing
Department of Information Technology
Demonstrated real-time handling of UART tasks using FreeRTOS.
Gained insights into the advantages of multi-tasking in communication systems.
This setup can be extended for advanced IoT projects involving data exchange
between multiple devices.
Page | 15
Processor Architecture and Interfacing
Department of Information Technology
Experiment – 5
Aim
To interface a 4x4 keypad with an ESP32 and display the key pressed on an OLED display
using ESP-IDF, with separate RTOS tasks for keypad scanning and OLED control.
Problem Statement
ESP-IDF – ESP32 4x4 keypad, display key pressed on OLED display. (RTOS, separate
tasks)
Objectives
1. To understand the working of a 4x4 matrix keypad and its interfacing with ESP32.
2. To learn how to control an OLED display using the I2C protocol.
3. To use RTOS to implement separate tasks for keypad scanning and OLED control.
4. To display the key pressed on the keypad in real-time on the OLED display.
Theory
4x4 Matrix Keypad:
A 4x4 keypad consists of 16 keys arranged in rows and columns.
Each key press creates a short circuit between a row and a column, which can be
detected by scanning the keypad.
Working:
o The microcontroller sets rows as outputs and columns as inputs.
o By sequentially driving each row high and reading the columns, the pressed
key can be identified.
OLED Display:
OLED is a display technology used for showing text and graphics.
The SSD1306 OLED module communicates via the I2C protocol, requiring two pins:
o SDA: Serial Data.
o SCL: Serial Clock.
Page | 16
Processor Architecture and Interfacing
Department of Information Technology
Libraries such as Adafruit_SSD1306 and Adafruit_GFX simplify the display's
operation.
ESP-IDF and RTOS:
ESP-IDF is the official framework for ESP32 programming, providing drivers for
keypad and OLED.
FreeRTOS, integrated into ESP-IDF, enables multi-tasking. Tasks for keypad
scanning and OLED control can run independently.
Working:
1. Keypad Task:
o Continuously scan the keypad matrix for a pressed key.
o Send the detected key to a shared queue.
2. OLED Task:
o Wait for key data from the queue.
o Display the key on the OLED screen.
3. RTOS Synchronization:
o Use a FreeRTOS queue to send data between the keypad and OLED tasks.
Connections:
Keypad ESP32 GPIO Pin
Pin
Row1 GPIO4
Row2 GPIO5
Row3 GPIO18
Row4 GPIO19
Col1 GPIO21
Col2 GPIO22
Col3 GPIO23
Col4 GPIO25
Page | 17
Processor Architecture and Interfacing
Department of Information Technology
OLED:
OLED Pin ESP32 GPIO Pin
SDA GPIO26
SCL GPIO27
VCC 3.3V
GND GND
Conclusion
By interfacing a 4x4 keypad and an OLED display with ESP32 using ESP-IDF and RTOS,
we successfully:
Implemented multi-tasking for real-time keypad scanning and OLED control.
Displayed the key pressed on the OLED in real time.
Demonstrated the effective use of RTOS queues for task communication.
This experiment provides a foundation for building interactive IoT applications, such
as keypads for input in smart devices.
Page | 18
Processor Architecture and Interfacing
Department of Information Technology
Experiment – 6
Aim
To demonstrate how to send data from an ESP32 to a mobile or PC Bluetooth terminal using
the NIMBLE Bluetooth stack in ESP-IDF, with RTOS handling tasks for data transmission.
Problem Statement
ESP-IDF – using NIMBLE send data to mobile/ PC Bluetooth terminal (RTOS)
Objectives
1. To understand the BLE (Bluetooth Low Energy) communication protocol and its
application.
2. To configure the ESP32 as a BLE server using the NIMBLE stack in ESP-IDF.
3. To learn how to send data to a Bluetooth terminal on a mobile or PC.
4. To use RTOS for handling BLE tasks and data management.
Theory
Bluetooth Low Energy (BLE):
BLE is a low-power wireless communication protocol designed for IoT applications.
It operates in client-server architecture:
o Server: Broadcasts data.
o Client: Receives and processes data.
NIMBLE:
NIMBLE is a lightweight and efficient BLE stack integrated into ESP-IDF.
Provides features like GATT (Generic Attribute Profile) for defining services and
characteristics.
ESP32 and BLE:
ESP32 can act as a BLE server or client.
A GATT Server is created to send data to a connected BLE client (e.g., a mobile/PC
terminal app).
RTOS in ESP-IDF:
Page | 19
Processor Architecture and Interfacing
Department of Information Technology
FreeRTOS enables efficient task management in ESP32.
BLE-related tasks, such as advertising and data transmission, can be handled in
separate threads.
Working:
1. BLE Initialization:
o Initialize the NIMBLE stack.
o Define a BLE service and characteristic to hold the data.
2. Advertising:
o Start advertising to allow the BLE client to connect.
3. Data Transmission:
o Once connected, periodically send data to the client using a characteristic.
4. RTOS Integration:
o Create separate RTOS tasks for:
BLE advertising and connection management.
Sending data to the BLE client.
Conclusion
By using NIMBLE in ESP-IDF, we successfully:
Configured the ESP32 as a BLE server.
Sent data to a Bluetooth terminal on a mobile or PC.
Utilized RTOS to manage BLE tasks and data handling efficiently.
This experiment highlights the potential of ESP32 for BLE-based IoT applications,
such as health monitoring, smart home control, and wearable devices.
Page | 20
Processor Architecture and Interfacing
Department of Information Technology
Experiment – 7
Aim
To connect an ESP32 to AWS IoT Core using Wi-Fi and send data using the MQTT protocol,
with RTOS managing the tasks for Wi-Fi connectivity, MQTT communication, and data
transmission.
Problem Statement
ESP-IDF – using Wi-Fi send data to AWS IOT core via MQTT (RTOS).
Objectives
1. To understand the MQTT protocol and its application in IoT communication.
2. To configure the ESP32 for Wi-Fi connectivity and MQTT communication using
ESP-IDF.
3. To connect the ESP32 to AWS IoT Core and send data to a specific topic.
4. To use RTOS tasks to manage Wi-Fi connectivity, MQTT publishing, and task
synchronization.
Theory
AWS IoT Core:
AWS IoT Core is a cloud platform for connecting IoT devices and managing their
data.
Devices communicate with AWS IoT Core via secure protocols like MQTT and
HTTPS.
MQTT Protocol:
Message Queuing Telemetry Transport (MQTT) is a lightweight protocol for
sending messages between devices.
Uses a publish-subscribe model:
o Publisher: Sends messages to a topic.
o Subscriber: Receives messages from the subscribed topic.
Commonly used in IoT due to its low bandwidth and efficiency.
ESP32 and AWS IoT Core:
Page | 21
Processor Architecture and Interfacing
Department of Information Technology
ESP32 acts as an MQTT client.
Requires:
o AWS IoT Core endpoint.
o Device certificate and private key for secure communication.
o Root CA certificate for TLS connection.
RTOS in ESP-IDF:
FreeRTOS is used for task management.
Tasks for Wi-Fi connection, MQTT initialization, and data publishing are executed
independently.
Workflow:
1. Wi-Fi Task:
o Connects ESP32 to a Wi-Fi network.
o Monitors and maintains the connection.
2. MQTT Task:
o Initializes MQTT client and connects to AWS IoT Core.
o Publishes data to a specified topic.
3. Data Task:
o Prepares and sends sensor or simulated data to the MQTT task.
4. RTOS Synchronization:
o Queues or semaphores ensure proper communication between tasks.
Conclusion
By connecting the ESP32 to AWS IoT Core via MQTT using Wi-Fi and RTOS, we
successfully:
Implemented secure communication between the ESP32 and AWS IoT Core.
Used MQTT to publish data to the cloud.
Leveraged RTOS for efficient task management and system responsiveness.
Page | 22
Processor Architecture and Interfacing
Department of Information Technology
This experiment demonstrates a robust IoT architecture for real-time data
transmission, which can be extended to applications like smart homes, remote
monitoring, and predictive analytics.
Page | 23
Processor Architecture and Interfacing
Department of Information Technology
Experiment – 8
Aim
To flash the Raspberry Pi OS onto an SD card, boot up the Raspberry Pi, and set it up for use
in various applications.
Problem Statement
Raspberry Pi – flashing Raspberry Pi OS and setting up Raspberry Pi.
Objectives
1. To learn how to flash the Raspberry Pi OS onto an SD card using tools like Raspberry
Pi Imager.
2. To understand the initial setup of Raspberry Pi, including keyboard, mouse, display,
and power connection.
3. To configure basic settings such as network, SSH, VNC, and system preferences.
4. To make the Raspberry Pi ready for future development projects, such as IoT, AI, or
automation.
Theory
Raspberry Pi:
Raspberry Pi is a small, affordable, and powerful single-board computer designed for
educational and developmental purposes.
It can run Linux-based operating systems like Raspberry Pi OS (formerly Raspbian).
Raspberry Pi OS:
Raspberry Pi OS is the official operating system for Raspberry Pi. It is based on
Debian and optimized for the Raspberry Pi hardware.
Features:
o Graphical user interface (GUI).
o Pre-installed software tools for coding and system management.
o Support for GPIO for IoT applications.
Flashing the OS:
Tools Required:
Page | 24
Processor Architecture and Interfacing
Department of Information Technology
o Raspberry Pi Imager (official tool for flashing Raspberry Pi OS).
o An SD card (minimum 16GB recommended).
Steps:
1. Download the Raspberry Pi Imager from the official Raspberry Pi website.
2. Insert the SD card into the computer.
3. Use the Raspberry Pi Imager to select the OS and flash it onto the SD card.
Setting Up the Raspberry Pi:
1. Insert the flashed SD card into the Raspberry Pi.
2. Connect peripherals (keyboard, mouse, and display).
3. Connect the power supply to boot the Raspberry Pi.
4. Complete the setup wizard, including:
o Language and keyboard settings.
o Wi-Fi connection.
o Software updates.
o Enabling remote access (SSH, VNC) if needed.
Applications:
The Raspberry Pi can be used for a variety of projects, including:
o IoT systems.
o Robotics.
o Media centers.
o Web servers.
o Educational programming.
Conclusion
By flashing Raspberry Pi OS and completing the initial setup, we:
Learned how to prepare the Raspberry Pi for various applications.
Page | 25
Processor Architecture and Interfacing
Department of Information Technology
Understood the process of configuring the operating system, network settings, and
remote access.
Made the Raspberry Pi ready for development in fields like IoT, AI, and automation.
This foundational experiment is critical for leveraging the full potential of Raspberry
Pi in future projects.
Page | 26
Processor Architecture and Interfacing
Department of Information Technology
Experiment – 9
Aim
To write a basic Python script to blink an LED connected to the Raspberry Pi and print data
to the terminal.
Problem Statement
Raspberry Pi – write a basic python script to blink an LED and print data.
Hardware Required
1. Raspberry Pi (any model with GPIO pins)
2. Breadboard
3. LED (1)
4. Resistor (220Ω)
5. Jumper wires
Objectives
1. To learn how to control GPIO pins of the Raspberry Pi using Python.
2. To interface and control an LED with the Raspberry Pi.
3. To implement a simple Python script to toggle the LED state and print data on the
terminal.
Theory
Raspberry Pi GPIO:
The General Purpose Input/Output (GPIO) pins on Raspberry Pi are programmable
and can be configured for input or output.
GPIO pins are commonly used to control external devices like LEDs, sensors, and
motors.
LED Basics:
An LED (Light Emitting Diode) emits light when current flows through it in the
correct direction.
A current-limiting resistor (220Ω) is connected in series with the LED to prevent
damage.
Page | 27
Processor Architecture and Interfacing
Department of Information Technology
Python GPIO Control:
RPi.GPIO Library:
o A Python library used to control the GPIO pins of Raspberry Pi.
o Provides functions to set pin modes, read inputs, and write outputs.
Blinking LED Workflow:
1. Set up the GPIO pin as an output.
2. Turn the LED ON and OFF at regular intervals using the time.sleep() function.
3. Print a message to the terminal each time the LED state changes.
Circuit Connections:
Raspberry Pi Pin Component Connection Details
GPIO17 (Pin 11) LED Positive leg to GPIO17
GND (Pin 6) LED Negative leg to resistor
Conclusion
By successfully blinking an LED and printing data using a Python script:
1. We learned to control Raspberry Pi GPIO pins programmatically.
2. Understood the basic interfacing of an LED with the Raspberry Pi.
3. Demonstrated the use of the RPi.GPIO library for GPIO control.
4. This experiment provides a foundation for building more advanced IoT or automation
projects with Raspberry Pi.
Page | 28
Processor Architecture and Interfacing
Department of Information Technology
Experiment – 10
Aim
To set up an MQTT broker on the Raspberry Pi and implement Python scripts for posting and
subscribing to messages via MQTT.
Problem Statement
Raspberry Pi – MQTT server data posting and subscribing (in Python script)
Hardware Required
1. Raspberry Pi (any model with internet connectivity)
2. Power supply for Raspberry Pi
3. A computer or mobile device (to verify MQTT communication)
4. Internet connection
5. Optional: Sensors or other hardware for data generation
Objectives
1. To understand the MQTT protocol and its role in IoT communication.
2. To set up an MQTT broker on the Raspberry Pi.
3. To implement Python scripts for publishing and subscribing to data over MQTT.
4. To demonstrate message exchange between the MQTT client and server.
Theory
What is MQTT?
MQTT (Message Queuing Telemetry Transport) is a lightweight messaging protocol
designed for low-bandwidth, high-latency, or unreliable networks.
It operates on a client-server (broker) architecture, where:
o Publisher: Sends messages to a specific topic.
o Subscriber: Receives messages from subscribed topics.
o Broker: Routes messages between publishers and subscribers.
Why MQTT on Raspberry Pi?
Page | 29
Processor Architecture and Interfacing
Department of Information Technology
Raspberry Pi serves as an excellent platform to act as an MQTT broker or client for
IoT applications due to its low power consumption and connectivity options.
MQTT Workflow:
1. Broker Setup: The MQTT broker (e.g., Mosquitto) runs on Raspberry Pi.
2. Publisher: A client script publishes data to a topic (e.g., test/topic).
3. Subscriber: Another client subscribes to the same topic and receives the data.
Required Libraries:
paho-mqtt: A Python library to implement MQTT publish/subscribe functionality.
Installation:
Install Mosquitto broker:
sudo apt update
sudo apt install mosquitto mosquitto-clients
sudo systemctl enable mosquitto
Install paho-mqtt library:
pip install paho-mqtt
Conclusion
By setting up an MQTT server and using Python scripts to publish and subscribe to data:
1. We gained an understanding of the MQTT protocol and its applications in IoT.
2. Successfully demonstrated message exchange between MQTT clients using the
Raspberry Pi as a broker.
3. Laid the foundation for advanced IoT applications, such as real-time data monitoring
and device communication.
4. This experiment highlights the Raspberry Pi’s capability to act as an IoT hub for
MQTT communication.
Page | 30
Processor Architecture and Interfacing
Department of Information Technology
Experiment – 11
Aim
To interface a DHT sensor (DHT11 or DHT22) with a Raspberry Pi to measure and display
temperature and humidity values.
Problem Statement
Raspberry Pi – interfacing DHT sensor with Raspberry Pi.
Hardware Required
1. Raspberry Pi (any model with GPIO pins)
2. DHT11 or DHT22 sensor
3. 10kΩ resistor (for pull-up configuration)
4. Breadboard
5. Connecting wires
6. Power supply for Raspberry Pi
7. Internet connection (for library installation)
Objectives
1. To understand how the DHT sensor measures temperature and humidity.
2. To learn how to interface the DHT sensor with the GPIO pins of the Raspberry Pi.
3. To use Python to read data from the DHT sensor.
4. To display the temperature and humidity values on the console or a display module.
Theory
y
DHT Sensor:
The DHT series sensors (DHT11 and DHT22) are commonly used temperature and
humidity sensors.
DHT11:
o Temperature range: 0–50°C
o Humidity range: 20–90%
Page | 31
Processor Architecture and Interfacing
Department of Information Technology
o Lower accuracy compared to DHT22.
DHT22:
o Temperature range: -40–80°C
o Humidity range: 0–100%
o Higher accuracy and wider range compared to DHT11.
Working Principle:
The DHT sensor uses a thermistor for temperature measurement and a capacitive
sensor for humidity measurement.
The sensor sends digital data to the Raspberry Pi using a single GPIO pin.
GPIO Interface:
A pull-up resistor (10kΩ) is required to ensure stable communication between the
DHT sensor and Raspberry Pi.
The data pin of the DHT sensor is connected to one of the GPIO pins of the Raspberry
Pi.
Python Library:
Adafruit provides a Python library to read data from DHT sensors.
Install the library:
pip install Adafruit-DHT
Circuit Connections
DHT Sensor Raspberry Pi Pin Notes
Pin
VCC (Power) 3.3V Provide 3.3V power
GND GND Ground connection
Data GPIO4 (or any GPIO) Add a 10kΩ pull-up resistor
Conclusion
1. The DHT sensor was successfully interfaced with the Raspberry Pi.
Page | 32
Processor Architecture and Interfacing
Department of Information Technology
2. Temperature and humidity values were read and displayed using Python scripts.
3. This experiment demonstrates the Raspberry Pi's ability to interact with
environmental sensors, enabling its use in IoT and weather monitoring projects.
4. The setup can be extended to store data in a database or send it to cloud platforms for
real-time monitoring.
Page | 33
Processor Architecture and Interfacing