Session_22b_GPIO Programming
Session_22b_GPIO Programming
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
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:
8
Press the “Upload” button in the Arduino IDE to upload your
Troubleshooting sketch:
Having the right board name and COM por selected, follow
these steps:
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);
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)
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)
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)
6. How can you set the state of an output pin to HIGH on the ESP32 board (A)
7. What are the advantages of setting up the ESP32 board in the Arduino IDE (D)
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)
10. How can you control the intensity of an LED connected to the ESP32 board (B)
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
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