IoT_practice_lab_1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

VIETNAM NATIONAL UNIVERSITY

UNIVERSITY OF ENGINEERING AND TECHNOLOGY

PRACTICAL LABS

Programming IoT
Applications

Ph.D. Nguyen Ngoc Tan

Ha Noi, 2023
Getting familiar with ESP8266

Lab 1: IoT Nodes - Get familiar with ESP8266

Purpose
The aim of this lab is for students to be able to confidently work with a popular develop-
ment KIT, i.e., ESP8266, and an embedded software development environment, i.e., Arduino
IDE.

Important Information
- Please do not power electronic devices, e.g., ESP8266, sensors, actuators, before
getting the confirmation from your tutor,

- Be gentle with the hardware.

Preparation
• Hardware: In this practice class, you will be using ESP8266 boards to explore all lab
exercises and develop your own projects for the final exams. Each student group (5
students per group) need to prepare hardware components for the labs in the following
list: https://1drv.ms/x/s!AtpR7GXvzh0wh5Awyxye8faeeNhvnA?e=pNI0xc

Note: If your laptop does not have a USB type A socket, you will need to buy the USB
type C to micro usb cable instead (no. 17 in the list).

• Tools: We will use the Arduino IDE software to program the ESP8266. The first thing
you should do is download the Arduino IDE if you do not already have it installed on
your computer. You can do that from this link: https://www.arduino.cc/en/software/.

Figure 1.1: Downloading Arduino IDE.

Week 1 1 Programming IoT Applications


Getting familiar with ESP8266

The web page will appear as shown in Fig. 1.1. It features that latest version of the
Arduino IDE. Select your operating system and download the latest version that is
available when you access the link (it was 2.0.4 at the time of writing).

Note: Installing Arduino IDE from the repository or Microsoft/Apple store is not
recommended because it might install an outdated/flawed version.

ESP8266 Pinout
The ESP8266 12-E NodeMCU kit pinout diagram is shown below.

Figure 1.2: ESP8266 Pinout.

GPIO (General-Purpose Input/Output)


• A general-purpose input/output is an uncommitted digital signal pin on an integrated
circuit or electronic circuit board which may be used as an input or output, or both, and
is controllable by software,

• Maximum current of GPIO pins is 12mA,

• All GPIO pins are pulled HIGH,

• GPIO01 & GPIO03 are TX and RX of UART0 which is used to flash the ESP8266 →
Should not use when flashing,

• GPIO0, GPIO2, GPIO15 are used for mode configuration of ESP8266 → Should not
use when flashing,

Week 1 2 Programming IoT Applications


Getting familiar with ESP8266

• GPIO9 & GPIO10 are used to connect with External Flash of ESP8266 → Should not
use,
• GPIO4 (D2), GPIO5 (D1), GPIO12 (D6), GPIO13 (D7), GPIO14 (D5), & GPIO16 (D0)
can be used for any purpose.

Figure 1.3: The use of ESP8266’s pins.

Getting the ESP8266 Ready


When the installation of Arduino IDE is complete, it is time to get the ESP8266 definitions.
- Open the preference window in the Arduino IDE from File → Preferences or by press-
ing CTRL + Comma.
- Copy and paste the following line to the “Additional Boards Manager URLs” field.

Week 1 3 Programming IoT Applications


Getting familiar with ESP8266

http://arduino.esp8266.com/stable/package esp8266com index.json.

Figure 1.4: Insert the additional URL.

- Open the Boards Manager. You can go to Tools → Board → Boards Manager. . . or
you can simply click the Boards Manager icon in the left-side corner.

Figure 1.5: Adding the link of ESP8266 package source.

The board manager will download the ESP8266 board definition files from the link
provided in the preferences window and install them. When the installation is complete,
the ESP8266 board definitions should appear as shown in the screenshot. Now you
can select your ESP8266 board from the Tools | Board menu:

Task 1: Uploading the first sketch to the ESP8266


1. Connect the ESP8266 board using the USB cable to your computer which is running
Arduino IDE.
2. Select Board: Go to Tools menu on your Arduino IDE → Board → esp8266 → Select
“NodeMCU 1.0 (ESP-12E module)” as shown in Figure
3. Select Port: Go to Tools menu on your Arduino IDE → Port → Select the port to
which your ESP8266 is connected.

Week 1 4 Programming IoT Applications


Getting familiar with ESP8266

Note 1: The port number might vary for each computer. So select the one that is
applicable to you.

Note 2: In the case the Port option is disabled, it means the driver of CP2102 chip
to be outdated. So you must update the driver manually:

• First, you need to download the “CP210x Universal Windows Driver” from the
following website: https://www.silabs.com/developers/usb-to-uart-bridge-
vcp-drivers?tab=downloads. Then uncompress the downloaded zip file.
• Then, open the Device Manager window from Search window. You might find
the line with a yellow exclamation mark at the beginning “CP210x....”, right-
click on that line and choose Update Driver. Then choose the “....” and select
the folder that contains the downloaded driver.

Figure 1.6: Adding the link of ESP8266 package source.

4. Go to Files menu on your Arduino IDE → Examples → esp8266 → Select the “Blink”
example to open the first sketch of ESP8266. The sketch allows ESP8266 blink a
built-in LED on ESP8266 board.

5. Next, Verify (Compile) the code using “Sketch” drop-down menu (or verify button tick
symbol ). Upload the code to your Arduino board using the “Upload” option from the
“Sketch” drop-down menu or using the right arrow icon (→) on the Arduino IDE.

6. You should now see the LED on the ESP8266 board blinking. Please ask your tutor for
help if this doesn’t work.

Week 1 5 Programming IoT Applications

You might also like