Dokumen Dari Kurniiarizkyy

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 21

Mikrokontroller

•Introduction to
•ESP32/NodeMCU/WeMOS/Lolin
•And its derivatives
Hardware and
Appearance

Typeset
Roboto Light
Inconsolata
This is what
ESP32/ESP8266
actually is
This is a “development board”
Often branded as Wemos /
LoLin / NodeMCU
More in depth about the difference

The ESP32 supports


analog measurements on
The ESP32 comes with
The ESP32 is faster than 18 channels (analog-
more GPIOs with
the ESP8266; enabled pins) versus just
multiple functions;
one 10-bit ADC pin on
the ESP8266;

The ESP32 supports The ESP32 is dual-core The ESP32 is a bit more
Bluetooth while the (most models), and the expensive than the
ESP8266 doesn’t; ESP8266 is single core; ESP8266.
These are the variations of
“Development Boards”
the thing that separates them are
the Built in features
This is what we will be using most of the time
About the dev-kit
• We cannot directly “program” the microprocessor (we can but
requires different hardware)
• The dev-kit integrates the flasher so that we can flash our program
through microUSB
• The dev-kit makes it easier for user to connect different modules
(sensors, actuators)
Prerequisites

• MicroUSB cable
• Windows/Mac/Linux based PC
• Basic concept of C language
• Arduino IDE
Readme.txt
• Main Screen of Arduino IDE
Readme.txt
• Go to tools > Board > Board
manager
• Install the esp32 board
Readme.txt
• Select your board according to
which brand you buy (if you are
unsure, select the ESP32 Dev
Module)
COM port
• Make sure Arduino IDE is using the
correct COM port
• Open Device Manager in Windows to
check which COM port is connected to
your Microcontroller
• Go to Tools > Port on Arduino IDE and
select corresponding port
Ready.. Set.. Go!

• On the main screen, there are 2


main functions that you cannot
delete, setup() and loop()
• Anything inside setup function
will be run once every boot
• Everything inside loop will be
run in a loop as long as the
device is powered
• Variables in setup cannot be accessed from loop
and vice versa
This doesn’t work • Usually, you do GPIO initialization inside setup
and do programming logic in loop
Tips
• Use the Serial Monitor to monitor the output of your device
• Debugging is a little tricky, so use your own way to debug your code
• To make an output, use the Serial.println() function
• Serial.println() will make a new line each time the function is called
• Serial.print() will append the output (Be aware of spacing and newlines)
• Pay close attention to capitalization as C language is case sensitive!
• int abc; is different than int ABC;
Setup function

• Initialize the serial speed rate and GPIO ports


here!
• Serial.begin(x);
• x is the rate
• pinMode(<pin number>, INPUT); if you
use the pin as input
• pinMode(<pin number>, OUTPUT); if
you use the pin as output
Loop function

• Do your magic here, you can access GPIO pin,


write HIGH or LOW digital output to GPIO pin
• You can use standard C codes such as, for, if, if
else, switch case
• There are hundreds of libraries to explore!
Example code to output some text
Exercise
• Try the code in slide 18, What is the output in Serial Monitor?
• Explain what do you see in Serial Monitor
• Analyze why the output is repeated indefinitely
• Modify the code so the output only happen each second
• Modify the code to generate the output only ONCE as long as your device is running!

You might also like