Uploaded by John Dwight

EECE425 625 LAB1

advertisement
American University of Beirut
Maroun Semaan Faculty of Engineering and Architecture
Department of Electrical and Computer Engineering
EECE 425/625: Embedded and IoT Systems
Lab #1
In this lab you will install the tools that you will use to write ESP32 programs for the Adafruit
Huzzah32 development board. You will also complete three short experiments to consolidate the
material covered in Module 2 on general-purpose input/output (GPIO).
To complete this lab, please borrow the following components from the ECE labs:
1. Adafruit Huzzah32 development board
2. USB-to-micro-USB power/data cable
3. Breadboard
4. Ten jumper wires (male-male)
5. Three LEDs
6. Three 470-ohm resistors
7. One 1K ohm resistor
8. One NPN bipolar junction transistor (BJT)
9. One push-button
IMPORTANT: The pins of the ESP32 development board are very delicate and can easily
snap off. If you receive the development board already mounted on the breadboard, please do
not remove it. If your development board is not mounted on the breadboard, please mount it
– carefully! – on the breadboard making sure it straddles the trough down the middle of the
board. Once mounted, please do not remove it. You can use your mounted development board
for all your lab experiments and projects.
1
Installing Visual Studio Code and PlatformIO
We will use Microsoft’s Visual Studio Code (VSC) to develop and edit ESP32 programs. VSC
is a powerful code editor that can be installed on Windows, MacOS, and Linux computers. We
will also use the VSC PlatfomIO extension to build programs and download them to the ESP32.
PlatformIO is a popular platform for embedded software development that relieves programmers
from managing code libraries, resolving code dependencies, and keeping libraries up-to-date.
1
A good tutorial on installing VSC and PlatformIO can be found on the Random Nerd Tutorials web site. The site contains a rich set of tutorials on using the Arduino IDE to develop
applications for the ESP32. Feel free to explore these tutorials and use them as references for
your lab experiments and/or projects. The VSC/PlatformIO installation tutorial can be found on
the following link:
https :// randomnerdtutorials . com / vs - code - platformio - ide - esp32 - esp8266 - arduino /
Once you have installed VSC and PlatformIO, please test your installation by typing the
“Blinky” Arduino sketch (you will later use the ESP-IDF to implement the same code). When
creating a new PlatformIO project, please select the following Board: Adafruit ESP32 Feather.
Open the platform.ini configuration file and confirm that it contains the following configuration values:
[ env : featheresp32 ]
platform = espressif32
board = featheresp32
framework = arduino
If you want to use PlatformIO’s serial monitor emulator, add the following line to platform.ini:
monitor_speed = < your computer 's serial input baud rate >
When typing your main.cpp file, define LED as 13 instead of 2. This is because GPIO port 13
is hardwired to an on-board LED on the Huzzah32 board. Finally, for this lab, skip the section
on installing ESP32/ESP8266 libraries on the PlatformIO IDE. We will cover these in future labs.
2
Multi-Output Blinky
Your first assignment is to connect three LEDs to the ESP32 development board and write
a “Blinky” program that blinks the LEDs simultaneously.
Use the Huzzah32 pinout diagram on Module 1, Slide 25 to connect your development board
to the LEDs using GPIO ports 16, 17, and 21. Use the breadboard and jumper wires to connect
the LED anodes (positive terminals) to the GPIO ports. Connect the LED cathodes (negative terminals) in series with 470-ohm current-limiting resistors, and connect the other resistor terminals
to ground. Use the ESP32 development board’s ground port to provide a common ground for
your circuit.
Write your “Blinky” program using the ESP-IDF GPIO API functions, but use the Arduino
IDE’s delay() function to produce the desired blinking interval (e.g. 500 ms ON/OFF, respectively). Run your code on the development board and verify that it works as expected. Save your
program as L1P1.cpp.
3
Controlling Blink Speed
Your second assignment is to add a push-button to your circuit to control the blink speed. Pressing the button should toggle blinking between slow (500 ms) and fast (100 ms) speeds. Use the
ESP-IDF GPIO API functions to configure GPIO port 19 as an input port and enable its internal
pull-down resistor. Connect one end of the button to GPIO port 19 and the other end to the
2
ESP32 development board’s 3.3V output pin. Run your code on the development board and
verify that it works as expected. Save your program as L1P2.cpp.
4
Using a Transistor to Switch Multiple LEDs Simultaneously
Your last assignment is to use an NPN bipolar junction transistor (BJT) to control the LEDs as
shown in the following Figure:
Connect the LED anodes (positive terminals) to the ESP32 development board’s 5V output
pin and connect their cathodes (negative terminals) to the 470-ohm current-limiting resistors.
Next connect the three (parallel) resistors to the BJT collector. Connect the BJT emitter to ground,
and connect the BJT base to GPIO port 21 through a 1K ohm resistor. This enables a single output
port to control the switching of the three LEDs simultaneously. Modify the code you developed
to control the LED blinking speed and use the ESP-IDF GPIO API to use GPIO port 21 as the
only port for controlling the blinking of the LEDs. Also modify the code so that the push-button
is now only used to toggle the LEDs ON/OFF. Save your program as L1P3.cpp and use a digital
multimeter to answer the following questions:
1. When LEDs are turned ON, what are the voltage drops across each LED?
2. When LEDs are turned ON, what is the current passing through each LED?
3. When LEDs are turned ON, what is the voltage across the collector and emitter (VCE )? How
does this compare to the saturation VCE reported in the BJT datasheet?
4. When LEDs are turned ON, what is the value of the collector current, IC ?
5. When LEDs are turned ON, what is the value of the base current, IB ?
6. According to the BJT datasheet, what is the minimum value of its gain (at saturation)?
According to your base and collector current measurements when LEDs are turned ON,
how much is the actual gain?
3
5
Deliverables
Please type up your answers and submit them to Moodle along with copies of your three programs, L1P1.cpp, L1P2.cpp, and L1P3.cpp, by 12:00 noon on Thursday September 15, 2022.
4
Download