0% found this document useful (0 votes)
9 views

Session_22b_GPIO Programming

The document outlines a session on GPIO programming with the ESP32 using the Arduino IDE, aiming to familiarize students with setup, troubleshooting, and GPIO functionalities. It includes step-by-step instructions for installing the ESP32 add-on, testing installations, and controlling GPIO pins with example code. Additionally, self-assessment questions and references for further reading are provided to reinforce learning outcomes.

Uploaded by

shaikrezwana8812
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Session_22b_GPIO Programming

The document outlines a session on GPIO programming with the ESP32 using the Arduino IDE, aiming to familiarize students with setup, troubleshooting, and GPIO functionalities. It includes step-by-step instructions for installing the ESP32 add-on, testing installations, and controlling GPIO pins with example code. Additionally, self-assessment questions and references for further reading are provided to reinforce learning outcomes.

Uploaded by

shaikrezwana8812
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Department of BES-II

FUNDAMENTALS OF IOT &


SENSORS
24EC1101
Topic:

GPIO PROGRAMMING
Session – 22b
AIM OF THE SESSION
To familiarize students with the ESP32 Setup and Controlling the GPIO Programming using Arduino IDE

INSTRUCTIONAL OBJECTIVES
This Session is designed to:
1. Demonstrate the Set up of ESP32 board in the development environment for programming with Arduino IDE
2. Describe in detailed steps involved and troubleshooting the Fatal Errors
3. Diagonalize the common issues related to incorrect GPIO pin configurations.
4. Identify the different GPIO pins and their functionalities on the ESP32 board

LEARNING OUTCOMES
At the end of this session, you should be able to:
1. Interpret the Setup of ESP32 and Controlling it with Input Output Pins
2. Describe the necessary software tools required for IoT Development Framework
3. Summarize the effective use of GPIO Pins on ESP32 Controller interfacing with External devices.

2
Installing ESP32 Add-on in Arduino IDE

1. In Arduino IDE, go to File > Preferences 2. Enter https://dl.espressif.com/dl/package_esp32_index.json


into the “Additional Board Manager URLs” field as shown in
the figure below.

3
3. Open the Boards Manager. Go to Tools > Board > Boards 4. Search for ESP32 and press install button for the “ESP32 by
Manager… Espressif Systems“:

4
5. The installation will complete with in a few seconds.

5
Testing the Installation

Plug the ESP32 board to your computer. With your Arduino IDE open, follow these steps:

1. Select your board in Tools > Board menu (in my case it’s 2. Select the Port (if you don’t see the COM Port in your
the DOIT ESP32 DEVKIT V1) Arduino IDE, you need to install the CP210x USB to UART
Bridge VCP Drivers):

6
3. Open the following example under 4. A new sketch opens in your Arduino IDE:
File > Examples > Wifi(ESP32) > WiFiScan

5. Press the Upload button in the Arduino IDE. Wait a few seconds
while the code compiles and uploads to your board.

7
6. If everything went as expected, you should see a “Done 8. Press the ESP32 on-board Enable button and you should see
Uploading” message. the networks available near your ESP32:

7. Open the Arduino IDE Serial Monitor at a baud rate of


115200:

8
Press the “Upload” button in the Arduino IDE to upload your
Troubleshooting sketch:

After you see the “Connecting….” message in your Arduino IDE,


release the finger from the “BOOT” button:

Having the right board name and COM por selected, follow
these steps:

Hold-down the “BOOT” button in your ESP32 board

9
const int buttonPin = 32;
Controlling the GPIO pins in const int ledPin = 23;
ESP32 using Touch Inputs // State of the push button
int buttonState = 0;

void setup() {
Serial.begin(115200);

//Set the pin as an input pullup


pinMode(buttonPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
}

void loop() {

buttonState = digitalRead(buttonPin);
Serial.println(buttonState);

if (buttonState == LOW) {
// Switch on the led
digitalWrite(ledPin, HIGH);
} else {
// Switch off the led
digitalWrite(ledPin, LOW);
}
}

10
11
 Connect the ESP32 board to your computer using a USB cable and Install the Arduino IDE that provides a user-
friendly interface for writing and uploading code to the ESP32.

 Open the Arduino IDE and navigate to Preferences. Enter the URL provided by the ESP32 board manufacturer into
the "Additional Board Manager URLs" field. Then, access the Boards Manager and install the ESP32 board package.

 Install the necessary libraries using the Library Manager within the Arduino IDE. Use the Arduino IDE to write the
code and functions while leveraging the specific ESP32 features and GPIO pin assignments.

 Connect the ESP32 board to your computer and select the appropriate serial port in the Arduino IDE. Open the
Serial Monitor within the Arduino IDE to monitor debug output from the ESP32 board via Serial Communication.

 Verify the functionality of your code by testing the behavior of the GPIO pins on the ESP32. Debug and iterate as
necessary to refine your project.

12
SELF-ASSESSMENT QUESTIONS

1. What is the purpose of setting up the ESP32 board in the Arduino IDE (D)

(a) To access a library of pre-existing Arduino code and libraries

(b) To control the Wi-Fi connectivity and Bluetooth capabilities

(c) To simplify and beginner-friendly interface for programming

(d) All the above

2. Which menu in the Arduino IDE is used to select the ESP32 board variant (C)

(a) File
(b) Sketch
(c) Tools
(d) Edit
SELF-ASSESSMENT QUESTIONS

3. How can you initialize serial communication for debugging purposes on the ESP32 board (A)

(a) `Serial.begin()` function

(b) `Serial.print()` function

(c) `Serial.available()` function

(d) `Serial.read()` function

4. What function is used to control the state of a GPIO pin on the ESP32 board (A)

(a) `digitalWrite()`
(b) `analogWrite()`
(c) `digitalRead()`
(d) `ananlogRead()`
SELF-ASSESSMENT QUESTIONS

5. Which command is used to set a GPIO pin as an output on the ESP32 board (B)

(a) `pinMode(pin, INPUT)`


(b) `pinMode(pin, OUTPUT)`
(c) `pinMode(pin, INPUT_PULLUP)`
(d) `pinMode(pin, INPUT_PULLDOWN)`

6. How can you set the state of an output pin to HIGH on the ESP32 board (A)

(a) `digitalWrite(pin, HIGH)`


(b) `digitalWrite(pn, LOW)`
(c) `digitalRead(pin)`
(d) `ananlogWrite(pin, Value)`
SELF-ASSESSMENT QUESTIONS

7. What are the advantages of setting up the ESP32 board in the Arduino IDE (D)

(a) Access to a vast library of pre-existing Arduino code and libraries

(b) Familiar and beginner-friendly programming environment


(c) Ability to develop and upload code to the ESP32 microcontroller
(d) All the above

8. Which programming language is commonly used to develop code for the ESP32 microcontroller (B)

(a) Python
(b) C++
(c) JavaScript
(d) Java
SELF-ASSESSMENT QUESTIONS

9. What is the purpose of the `setup()` function in an Arduino sketch for the ESP32 board (A)

(a) Once at the start to initialize variables and pin modes


(b) Loop that repeatedly executes the code inside it
(c) Responsible for controlling the behavior of the ESP32s Wi-Fi Module
(d) Used to handle interrupts from External devices

10. How can you control the intensity of an LED connected to the ESP32 board (B)

(a) Using a digital pin and `digitalWrite()` function


(b) Using an analog pin and `analogWrite()` function
(c) Using a digital pin and `digitalRead()` function
(d) Using an analog pin and `analogRead()` function
TERMINAL QUESTIONS

1. Contrast the advantages and disadvantages of setting up the ESP32 board in the Arduino IDE

2. List the key components required for setting up the ESP32 board in the Arduino IDE and briefly

explain their role in the setup process.

3. Explain with an example how GPIO Programming can be done in ESP32 board

4. Recall the main purpose of setting up the ESP32 board in the Arduino IDE and describe its

significance
REFERENCES

Reference Books:
1. The Internet of Things: Connecting objects by Hakima Chaouchi Wiley Publications
2. The Internet of Things – Key applications and Protocols by Olivier Hersent, David Boswarthick, Omar
Elloumi, Wiley, 2012.
3. "Getting Started with ESP32: Programming the ESP32 with Arduino IDE and ESP-IDF" by Simon Monk

Sites and Web links:


1. https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/index.html
2. https://randomnerdtutorials.com/getting-started-with-esp32/
3. https://www.arduino.cc/
THANK YOU

Team – Fundamentals of IoT & Sensors

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy