23SDEC02A-SKILL MANUAL-Faculty
23SDEC02A-SKILL MANUAL-Faculty
Semester: 2-2
1
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
INDEX OF EXPERIMENTS
Page
S. No. Name of the Experiment Marks Faculty Sign
No.
2
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
Page
S. No. Name of the Experiment No. Marks Faculty Sign
3
Koneru Lakshmaiah Education Foundation
2023-24 EVEN SEMESTER SKILLING CONTINUOUS EVALUATION
S. Date Experiment Title Pre- In Lab Post Viva- Total Sign of
No. Lab Lab Voce (50M) Faculty
(5M) Logic Execu Result Anal (5M) (5M)
(10M) tion (10M) ysis
(10M) (5)
1.
2.
3.
5.
6.
7.
8
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
9.
10.
4
2023-24 EVEN SEMESTER SKILLING CONTINUOUS EVALUATION
S. Date Experiment Title Pre- In Lab Post Viva- Total Sign of
No. Lab Lab Voce (50M) Faculty
(5M) Logic Execu Result Anal (5M) (5M)
(10M) tion (10M) ysis
(10M) (5)
11.
12.
13.
15.
16.
17.
18
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
19.
20.
5
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
PREREQUISITE:
• General idea of clock frequency, ESP32 board
• General idea of basic circuit
PRE-LAB:
1) What is the role of the CPU clock speed in a microcontroller like the ESP32?
2) What is the default CPU clock speed of the ESP32, and how can it be configured?
OBJECTIVE:
To design and implement a serial communication port, checks the CPU clock rate & XTAL Freq &
APB bus clock.
COMPONENTS REQUIRED:
• ESP32
• Breadboard
• Jumper Wires Pack
• Micro usb cable
THEORY:
ESP32 CPU Speed (Frequency):
The ESP32 is a dual-core system with two Harvard Architecture Xtensa LX6 CPUs. All embedded
memory, external memory, and peripherals are located on the data bus and/or the instruction bus of
these CPUs.
CPU Clock:
Both CPUs can be clocked from various sources internally or externally. The most important circuitry
is the PLL (Phase-Locked Loop) which multiplies the input clock frequency (whether it’s an external
crystal or internal oscillator). This results in a much higher frequency signal that’s derived from the
main clock source (orders of magnitude in terms of frequency).
6
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
The PLL_CLK is an internal PLL clock signal with a frequency of 320 MHz or 480 MHz. Note that
this PLL clock is divided /2 or /4 before it’s fed to any CPU. The table down below from the datasheet
shows the possible configurations for the clock.
Peripherals Clock:
The APB bus clock (APB_CLK) is derived from CPU_CLK, the division factor depends on the
CPU_CLK source as shown in the table down below. The peripherals clock signals are APB_CLK,
REF_TICK, LEDC_SCLK, APLL_CLK, and PLL_D2_CLK.
With that being said, we can conclude that setting the PLL_CLK as a clock source will help us choose
the 480MHz PLL clock output as a clock source for the CPU (the CPU_CLK will be 480/2 MHz).
While the APB bus will be clocked @ 80MHz due to this option being selected.
CIRCUIT:
7
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
ESP32:
CODE:
#define GPIO_pin 5
uint32_t Freq = 0;
void setup()
{
pinMode(GPIO_pin, OUTPUT);
Serial.begin(115200);
Freq = getCpuFrequencyMhz();
Serial.print("CPU Freq = ");
Serial.print(Freq);
Serial.println(" MHz");
Freq = getXtalFrequencyMhz();
Serial.print("XTAL Freq = ");
Serial.print(Freq);
Serial.println(" MHz");
Freq = getApbFrequency();
Serial.print("APB Freq = ");
Serial.print(Freq);
Serial.println(" Hz");
}
void loop()
{
digitalWrite(GPIO_pin, 1);
digitalWrite(GPIO_pin, 0);
8
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
}
PROCEDURE:
1. Choose the board, COM port, hold down the BOOT button, click upload and keep your
finger on the BOOT button pressed.
2. When the Arduino IDE starts sending the code, you can release the button and wait for the
flashing process to be completed.
3. Now, the ESP32 is flashed with the new firmware.
RESULT:
POST LAB:
Take the snapshot of Tinker CAD simulation and paste here with your REG NO on it.
9
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
PREREQUISITE:
• General idea of Interrupts, ESP32 board
• General idea of basic circuit
PRE-LAB:
OBJECTIVE:
COMPONENTS REQUIRED:
• ESP32
• Breadboard
• Jumper Wires Pack
• Micro USB Cable
THEORY:
Interrupt Latency:
Interrupt latency is the time it takes the CPU to respond to a specific interrupt signal. It’s a measure
for the response time of an interrupt and it’s desired to be as small as possible. Upon an interrupt signal
reception, the CPU suspends the current main code executions, saves the context, switches the context
to the ISR, executes the ISR code, switches the context back to main, and finally resumes the main
code execution.
10
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
This takes some time and it’s desired to be as small as possible. The time between the hardware
interrupt signal and the start of ISR execution (interrupt latency) is what we’re going to measure in
this LAB.
CIRCUIT:
ESP32:
CODE:
#define Btn1_GPIO 35
#define LED1_GPIO 5
11
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
void setup()
{
pinMode(LED1_GPIO, OUTPUT);
pinMode(Btn1_GPIO, INPUT);
attachInterrupt(Btn1_GPIO, Ext_INT1_ISR, RISING);
}
void loop()
{
// Do Nothing...
}
PROCEDURE:
1. Choose the board, COM port, hold down the BOOT button, click upload and keep
your finger on the BOOT button pressed.
2. When the Arduino IDE starts sending the code, you can release the button and wait for
the flashing process to be completed.
RESULT:
POST LAB:
Take the snapshot of Tinker CAD simulation and paste here with your REG NO on it.
12
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
PREREQUISITE:
• General idea of Timer, ESP32 board
• General idea of basic circuit
PRE-LAB:
1. What is the primary purpose of timers in microcontroller development, such as the ESP32?
2. Explain the difference between hardware timers and software timers on the ESP32.
OBJECTIVE:
• Generate Timer Interrupt events in Arduino IDE.
COMPONENTS REQUIRED:
• ESP32
• breadboard
• Jumper Wires Pack
• Micro USB Cable
THEORY:
ESP32 Timers:
The ESP32 SoCs come with 4 hardware timers, each of which is a general-purpose 64-bit up/down
counter with a 16-bit prescaler. Except for ESP32-C3 which has only 2 timers each of which is 54 bits
instead. The ESP32 timers have the capability of auto-reloading at the end of the counting period as
well.
14
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
Each ESP32 timer uses the APB clock (APB_CLK which is normally 80 MHz in frequency) as a base
clock. This clock is then scaled downby a 16-bit prescaler which generates the time-base tick time.
Therefore, we’ll be changing the value of the prescaler in order to control the timer tick time.
The 16-Bit prescaler can divide the APB_CLK by a factor from 2 to 65536. When you set the prescaler
value to be either 1 or 2, the clock divisor is 2; when you set the prescaler to 0, the clock divisor is
65536. Any other value will cause the clock to be divided by exactly that value that you’ve written to
the prescaler register.
ESP32 timers can trigger an alarm (Event) which will cause a timer to reload and/or interrupt to occur,
depending on your configuration. The alarm event is triggered when the value you’ve stored in the
alarm register matches the current timer value. This is very useful to set periodic interrupts to execute
some pieces of logic periodically in your project as we’ll be doing hereafter.
In order to generate periodic events with ESP32, we’ll be using the alarm event generation as well as
the timer’s prescaler in order to achieve the desired interrupt periodicity. There are 3 special cases for
the Timer equation down below, which are when the prescaler value is = 0,1, and 2. When
Prescaler=1or2, it’s going to be as follows [ TOUT = TimerTicks x (2/APB_CLK) ]. When
Prescaler=0, it’s going to be as follows [ TOUT = TimerTicks x (65536/APB_CLK) ]. Otherwise, we
can generally use the equation down below.
Let’s say we’d like to toggle an LED every 1 ms without using a delay that blocks the CPU and does
much harm to the overall timing performance of your system. For this, we’ll use the timer’s equation
above, Given that the default APB_CLK is 80MHz or 80,000,000Hz. The desired TOUT for the
interrupt period in which we’ll toggle the LED is 1ms, So TOUT = 1ms or 0.001s. The only two
unknowns now are the Prescaler value and the TimerTicks count which we’ll set the alarm event to.
15
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
We can set the Prescaler to whichever value we want but for the sake of simplifying the calculations,
let’s set the Prescaler=80. This will leave us with only one unknown which is the TimerTicks count.
So, we’ll solve the equation for TimerTicks:
CIRCUIT:
ESP32:
CODE:
#define LED 21
hw_timer_t *Timer0_Cfg = NULL;
void setup()
{
pinMode(LED, OUTPUT);
Timer0_Cfg = timerBegin(0, 80, true);
timerAttachInterrupt(Timer0_Cfg, &Timer0_ISR, true);
timerAlarmWrite(Timer0_Cfg, 50000, true);
timerAlarmEnable(Timer0_Cfg);
}
void loop()
{
// Do Nothing!
}
PROCEDURE:
OUTPUT:
POST LAB:
Take the snapshot of Tinker CAD simulation and paste here with your REG NO on it.
17
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
PREREQUISITE:
• General idea of ESP32 board
• General idea of UART
PRE-LAB:
1. Identify the pins commonly used for UART communication on the ESP32.
2. What is the purpose of the TXD and RXD pins in UART?
3. Give the significance of the baud rate in UART communication.
4. Define the terms "data bits," "stop bits," and "parity" in the context of UART.
5. What is flow control in UART, and why is it necessary?
OBJECTIVE:
To perform UART or serial communication between two ESP32 boards using UART
hardware library of Arduino IDE
REQUIRED COMPONENTS:
CIRCUIT:
• Connect TX2 pin of master ESP32 board with RX2 pin of slave ESP32 board. Likewise,
connect RX2 pin of master ESP32 board with TX2 pin of slave ESP32 board.
• Anode pin of LED is connected with digital pin15 (slave) through a 220-ohm current
limiting resistor. The cathode pin is grounded.
18
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
• Also make sure both ESP32 boards have their grounds in common.
CODE:
#include <HardwareSerial.h>
19
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
void setup()
{
SerialPort.begin(15200, SERIAL_8N1, 16, 17);
}
void loop()
{
SerialPort.print(1);
delay(5000);
SerialPort.print(0);
delay(5000);
}
void setup()
{
SerialPort.begin(15200, SERIAL_8N1, 16, 17);
}
Here the master will send the number 1 and 0 to the slave after every 5 seconds.
void loop()
{
SerialPort.print(1);
20
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
delay(5000);
SerialPort.print(0);
delay(5000);
}
void setup()
{
SerialPort.begin(15200, SERIAL_8N1, 16, 17);
pinMode(LED, OUTPUT);
}
void loop()
{
if (SerialPort.available())
{
char number = SerialPort.read();
if (number == '0') {
digitalWrite(LED, LOW);
}
if (number == '1') {
digitalWrite(LED, HIGH);
}
}
}
How the Code Works?
#include <HardwareSerial.h>
21
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
A char variable called ‘number’ stores the data that the slave will receive from the master.
Inside the setup() function, we will open the serial communication of port UART2 using
SerialPort.begin (BaudRate, SerialMode, RX_pin, TX_pin). Also, set the LED pin as an output
pin using the pinMode() function. Specify the pin as the first parameter and the mode as the
second parameter.
One important point to note here is that the baud rate of both ESP32 master and slave boards
should be the same.
void setup()
{
SerialPort.begin(15200, SERIAL_8N1, 16, 17);
pinMode(LED, OUTPUT);
}
Inside the loop() function, we will check if data is present in the buffer. If some data is
available, it is stored in variable ‘number.’ If the number is ‘0’, then turn the LED will be
turned OFF. If the number is ‘1’, then the LED will be turned ON.
The master will send ‘1’ and ‘0’ with a delay of 5 seconds continuously to the slave. Hence,
the LED will stay ON for 5 seconds and then OFF for 5 seconds.
void loop()
{
if (SerialPort.available())
{
22
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
Hardware Demonstration
To see the demonstration, upload the master and sender codes to the two ESP32 boards. But,
before uploading code, make sure to select the ESP32 Dev Module from Tools > Board and
also select the correct COM port to which the board is connected from Tools > Port.
23
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
The LED will turn ON and stay ON for 5 seconds before turning OFF for 5 seconds. This
continues as the master keeps on sending 1/0 to the slave.
OUTPUT:
RESULT:
24
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
PREREQUISITE:
• General idea of ESP32 board
• General idea of I2C
PRE-LAB:
1. Identify the pins on the ESP32 commonly used for I2C communication.
2. What is the purpose of the SDA and SCL pins in the I2C interface?
3. What is the purpose of I2C device scanning?
4. How does the ESP32 discover and identify I2C devices on the bus?
5. Describe the role of the Wire library in Arduino IDE for I2C communication.
OBJECTIVE:
REQUIRED COMPONENTS:
CONNECTIONS:
25
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
CODE:
#include <Wire.h>
void setup()
{
Serial.begin(115200);
I2C_0.begin(SDA_0 , SCL_0 , I2C_Freq);
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
I2C_0.beginTransmission(address);
error = I2C_0.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknown error at address 0x");
if (address<16)
26
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(5000); // wait 5 seconds for next scan
}
Test #1 Setup & Results
For the first test, I’ve connected an MPU6050 IMU sensor to the SCL & SDA lines of I2C1
as you can see in the image down below. The I2C address for this slave device is 0x68 as
stated in the datasheet.
We can change only one bit of that address so there could be 2 MPU6050 sensors on the same
bus at maximum. Anyway, we should expect to see that address after running the example on
the “Tera Term” serial terminal on my PC.
OUTPUT:
27
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
RESULT:
In the second test, I’ve just added another I2C module to the bus lines which is the
I2C_LCD interface IO expander (PCF8574T). This module has an I2C slave address of
0x27 as a default address if no solder bridge on the module’s board is touched at all.
You can still play around with those bridges to change the device address to allow many
I2C_LCD devices on the same bus
FINAL RESULT:
28
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
PREREQUISITE:
• General idea of ESP32 board
• General idea of I2S peripherals
PRE-LAB:
OBJECTIVE:
To display the audio waveforms from the microphone using the Serial Plotter through
ESP32 in Arduino IDE.
REQUIRED COMPONENTS:
CONNECTIONS:
29
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
CODE:
// Include I2S driver
#include <driver/i2s.h>
void i2s_install() {
// Set up I2S Processor configuration
const i2s_config_t i2s_config = {
.mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_RX),
.sample_rate = 44100,
.bits_per_sample = i2s_bits_per_sample_t(16),
.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
.communication_format =
i2s_comm_format_t(I2S_COMM_FORMAT_STAND_I2S),
.intr_alloc_flags = 0,
.dma_buf_count = 8,
30
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
.dma_buf_len = bufferLen,
.use_apll = false
};
void i2s_setpin() {
// Set I2S pin configuration
const i2s_pin_config_t pin_config = {
.bck_io_num = I2S_SCK,
.ws_io_num = I2S_WS,
.data_out_num = -1,
.data_in_num = I2S_SD
};
i2s_set_pin(I2S_PORT, &pin_config);
}
void setup() {
delay(1000);
// Set up I2S
i2s_install();
i2s_setpin();
i2s_start(I2S_PORT);
delay(500);
}
void loop() {
31
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
Serial.print(rangelimit);
Serial.print(" ");
if (result == ESP_OK)
{
// Read I2S data buffer
int16_t samples_read = bytesIn / 8;
if (samples_read > 0) {
float mean = 0;
for (int16_t i = 0; i < samples_read; ++i) {
mean += (sBuffer[i]);
}
32
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
In the Setup, we set up our serial connection, as we will be using the Serial Plotter to display
our audio waveforms. We then cal our two functions to set up the I2S port, and then start it
with a third built-in function.
Our Loop starts with a “false” print statement, this just causes two constants to be printed to
steady the reading on the Serial Plotter, which otherwise will dynamically change its Y-axis
scale.
We then read data from the module and place it in our data buffer. If the data is good, we read
it out and display it on the Serial Plotter
OUTPUT:
RESULT:
33
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
PREREQUISITE:
• General idea of ESP32 board
• General idea of SPI Pins, Multiple SPI Bus Interfaces, and Peripherals (Arduino IDE)
PRE-LAB:
1. What is the role of SPI in the ESP32 and how is it utilized within the
microcontroller?
2. How do SPI pins (CLK, MOSI, MISO, CS) facilitate communication with
peripheral devices?
3. What is the default GPIO pin assignments for the SPI interface (CLK, MOSI, MISO,
CS) on the ESP32?
4. Can the default SPI pins on the ESP32 be reconfigured or changed?
OBJECTIVE:
REQUIRED COMPONENTS:
THEORY:
SPI stands for Serial Peripheral Interface, and it is a synchronous serial data protocol used by
microcontrollers to communicate with one or more peripherals. For example, your ESP32
board communicating with a sensor that supports SPI or with another microcontroller.
In an SPI communication, there is always a controller (also called master) that controls
the peripheral devices (also called slaves). Data can be sent and received simultaneously. This
34
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
means that the master can send data to a slave, and a slave can send data to the master at the
same time.
You can have only one master, which will be a microcontroller (the ESP32), but you can have
multiple slaves. A slave can be a sensor, a display, a microSD card, etc., or another
microcontroller. This means you can have an ESP32 connected to multiple sensors, but the
same sensor can’t be connected to multiple ESP32 boards simultaneously.
SPI Interface:
The ESP32 integrates 4 SPI peripherals: SPI0, SPI1, SPI2 (commonly referred to as HSPI),
and SPI3 (commonly referred to as VSPI).
SP0 and SP1 are used internally to communicate with the built-in flash memory, and you
should not use them for other tasks.
35
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
You can use HSPI and VSPI to communicate with other devices. HSPI and VSPI have
independent bus signals, and each bus can drive up to three SPI slaves.
CODE:
void loop() {
// put your main code here, to run repeatedly:
}
Note: make sure you select the board you’re using in Tools > Board, otherwise, you may not
get the right pins.
After uploading the code, open the Serial Monitor, RST your board and you’ll see the SPI
pins.
36
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
OUTPUT:
RESULT:
37
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
PREREQUISITE:
PRE-LAB:
1. What is CAN (Controller Area Network) Bus communication, and what makes it
suitable for use in various applications?
2. How does CAN Bus differ from other communication protocols like SPI or I2C?
3. What are the primary functions of the ESP32 and MCP2515 within the CAN Bus
communication setup?
4. How does the MCP2515 interface with the ESP32 for CAN Bus communication?
OBJECTIVE:
REQUIRED COMPONENTS:
• ESP32
• MCP2515 module
• Connecting wires
38
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
CIRCUIT:
CODE:
#include <OneWire.h>
#include <DallasTemperature.h>
#include <BluetoothSerial.h>
#include <SPI.h>
#include "mcp_can.h"
//------CAN BUS setting ---------------------------------------------------------
#define CAN0_INT 21 // Set INT to pin 50
const int SPI_CS_PIN = 5;
MCP_CAN CAN0(SPI_CS_PIN);
//----- DS18B20 ------------------
#define DQ_Pin 4
OneWire oneWire(DQ_Pin);
DallasTemperature sensors(&oneWire);
#define LED_BUILTIN 2
BluetoothSerial SerialBT;
39
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
40
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
String BTinputString;
String S1inputString;
int V[16];
char ctemp[30];
char I2C_Data[80];
int DC_Spped = 50;
float Voltage[16];
int Buffer[128];
int StartCnt = 0;
int ReadCnt = 0;
int sensorValue = 0;
} vUart;
vUart *Uart_Ptr;
vUart Uart;
//-------------CAN-------------------------------
typedef struct _vCAN_t
{
long unsigned int rxId;
long unsigned int txId;
unsigned char rxlen = 8;
unsigned char txlen = 8;
unsigned char rxext = 0;
unsigned char txext = 0;
unsigned char rxBuf[20];
byte data[8];
unsigned char masknum = 0;
unsigned char maskext = 0;
long unsigned int maskId;
unsigned char filternum = 0;
unsigned char filterext = 0;
long unsigned int filterId;
} vCAN_t;
vCAN_t *can_Ptr;
vCAN_t can;
//-------------------------------------------------
void setup()
{
Serial.begin(9600);
Serial.println(F("init"));
41
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
pinMode(LED_BUILTIN, OUTPUT);
SerialBT.begin("BT_BS18B20");// BTName
if (oneWire.search(address))
{
Serial.println("Slave device found!");
Serial.print("Device Address = ");
Serial.println(address[0]);
}
else
{
Serial.println("Slave device not found!");
}
//-----DS-----------
sensors.begin();
//standard frame
can.txId = 0x7D1;
can.txext = 0;
can.txlen = 8;
can.data[0] = 0x8E;
can.data[1] = 0x00;
can.data[2] = 0x00;
can.data[3] = 0x00;
can.data[4] = 0x00;
can.data[5] = 0x00;
can.data[6] = 0x00;
can.data[7] = 0x00;
}
//-----------------------------------------
void loop()
{
Serial.print(F("Main at core:"));
Serial.println(xPortGetCoreID());
while(1)
{
if(flag.LEDFlag == 1)
{
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
vTaskDelay(300);
42
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
Uart.lineIndex = 0;
Uart.inputString = "";
}
else
{
// Empty or comment line. Skip block.
}
Uart.lineIsComment = false;
Uart.lineSemiColon = false;
Serial.println(F("ok>"));
}
else
{
//Serial.println( c );
if ((Uart.lineIsComment) || (Uart.lineSemiColon))
{
if (Uart.c == ')')
Uart.lineIsComment = false; // End of comment. Resume line.
}
else
{
if (Uart.c == '/')
{ // Block delete not supported. Ignore character.
}
43
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
Serial.println(BTdata);
BTprocessCommand(BTdata);
}//while (BT.available())
if(flag.DS18B20Flag == 1)
{
vDS18B20Task();
sensors.requestTemperatures();
44
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
SerialBT.print("E");
SerialBT.println(sensors.getTempCByIndex(0));
}
if (flag.CANFlag == 1)
{
Serial.print("Temperatures --> ");
sensors.requestTemperatures();
Serial.println(sensors.getTempCByIndex(0));
//--------------------------------
float f=sensors.getTempCByIndex(0);
String mystring;
mystring = String(f);
byte float_data[mystring.length()+1];
mystring.getBytes(float_data, mystring.length()+1);
//---------------------------------------------
int size = sizeof(float_data);
for(int i=0;i<size;i++)
{
can.data[i] =float_data[i];
}
flag.CANFlag = 2;
flag.LEDFlag = 0;
delay(50);
byte sndStat = CAN0.sendMsgBuf(can.txId, can.txext, can.txlen, can.data);
if (sndStat == CAN_OK)
Serial.println("CAN Message Sent Successfully!");
else
Serial.println("Error Sending CAN Message...");
flag.CANFlag = 1;
}
/**
else
{
Serial.println("Open CAN First...");
}**/
}
}
//-------------------------------------
45
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
}
//----------------------------------------
void processCommand(char *data)
{
int len, xlen, ylen, zlen, alen;
int tempDIO;
String stemp;
len = Uart.inputString.length();
//---------------------------------------
if (strstr(data, "VER") != NULL)
{
Serial.println(F("ESP32_20230727"));
Serial.println(F("CAN_DS18B20"));
}
if (strstr(data, "DS18B20_ON") != NULL)
{
flag.DS18B20Flag = 1;
flag.LEDFlag=0;
Serial.println(F("DS18B20_ON"));
}
if (strstr(data, "DS18B20_OFF") != NULL)
{
flag.DS18B20Flag = 0;
flag.LEDFlag=1;
Serial.println(F("DS18B20_OFF"));
}
///----------CAN function ----------------
if (strstr(data, "CAN_ON_125") != NULL)
{
if (flag.CANFlag == 0)
{
if (CAN_OK != CAN0.begin(MCP_NORMAL, CAN_125KBPS, MCP_8MHZ))
{
Serial.println("CAN BUS Shield init fail");
Serial.println("Init CAN BUS Shield again");
flag.CANFlag = 0;
46
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
}
else
{
Serial.println("CAN BUS Shield init ok!");
CAN0.setMode(MCP_NORMAL); // Set operation mode to normal so the
MCP2515 sends acks to received data.
pinMode(CAN0_INT, INPUT); // Configuring pin for /INT input
flag.CANFlag = 1;
Serial.println("init ok");
}
}
else if (flag.CANFlag == 2)
{
flag.CANFlag = 1;
Serial.println("CAN BUS message ON!");
}
}
if (strstr(data, "CAN_ON_250") != NULL)
{
if (flag.CANFlag == 0)
{
if (CAN_OK != CAN0.begin(MCP_NORMAL, CAN_250KBPS, MCP_8MHZ))
{
Serial.println("CAN BUS Shield init fail");
Serial.println("Init CAN BUS Shield again");
flag.CANFlag = 0;
}
else
{
Serial.println("CAN BUS Shield init ok!");
CAN0.setMode(MCP_NORMAL); // Set operation mode to normal so the
MCP2515 sends acks to received data.
pinMode(CAN0_INT, INPUT); // Configuring pin for /INT input
flag.CANFlag = 1;
Serial.println("init ok");
}
}
else if (flag.CANFlag == 2)
{
flag.CANFlag = 1;
Serial.println("CAN BUS message ON!");
47
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
}
}
if (strstr(data, "CAN_ON_500") != NULL)
{
if (flag.CANFlag == 0)
{
if (CAN_OK != CAN0.begin(MCP_NORMAL, CAN_500KBPS, MCP_8MHZ))
{
Serial.println("CAN BUS Shield init fail");
Serial.println("Init CAN BUS Shield again");
flag.CANFlag = 0;
}
else
{
Serial.println("CAN BUS Shield init ok!");
CAN0.setMode(MCP_NORMAL); // Set operation mode to normal so the
MCP2515 sends acks to received data.
pinMode(CAN0_INT, INPUT); // Configuring pin for /INT input
flag.CANFlag = 1;
Serial.println("init ok");
}
}
else if (flag.CANFlag == 2)
{
flag.CANFlag = 1;
Serial.println("CAN BUS message ON!");
}
}
if (strstr(data, "CAN_OFF") != NULL)
{
flag.CANFlag = 2;
flag.LEDFlag = 1;
Serial.println("CAN BUS message OFF!");
}
}
//-----------------------------------------
//-------------------------------------------
void vDS18B20Task()
{
Serial.print("Temperatures --> ");
48
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
sensors.requestTemperatures();
Serial.println(sensors.getTempCByIndex(0));
}
RESULT:
49
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
PREREQUISITE:
PRE-LAB:
1. What is ADC, and how does it convert an analog signal to a digital value in
microcontrollers like the ESP32?
2. What are the characteristics and capabilities of the ADC in the ESP32
microcontroller?
3. How can Pulse Width Modulation (PWM) be used to control the brightness of an
LED?
4. How would you physically connect an LED to the ESP32 to implement LED
dimming using PWM?
5. How can the analog values read from the ADC be mapped to the PWM range for
controlling LED brightness?
OBJECTIVE:
To create an LED dimmer using an ESP32 and a potentiometer to control the LED
brightness.
REQUIRED COMPONENTS:
50
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
CIRCUIT:
We start with defining and attaching The PWM GPIO pin. The pin I’ll be using a PWM
pin is GPIO5 in this example.
Then, we’ll be configuring the PWM Channel’s frequency (1kHz) & resolution (12-Bits
to be similar to the ADC_Result). And in the main loop() function, we’ll read the ESP32
ADC analog input (potentiometer – GPIO35 pin), and write the result to the PWM duty
cycle.
CODE:
#define LED_GPIO 5
#define PWM1_Ch 0
#define PWM1_Res 12
#define PWM1_Freq 1000
#define AN_Pot1 35
int AN_Pot1_Result = 0;
void setup()
{
ledcAttachPin(LED_GPIO, PWM1_Ch);
ledcSetup(PWM1_Ch, PWM1_Freq, PWM1_Res);
}
51
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
void loop()
{
AN_Pot1_Result = analogRead(AN_Pot1);
ledcWrite(PWM1_Ch, AN_Pot1_Result);
delay(1);
}
OUTPUT:
RESULT:
52
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
PREREQUISITE:
PRE-LAB:
1. How does Pulse Width Modulation (PWM) in the ESP32 simulate analog output?
2. What factors influence the resolution and accuracy of analog-like output using PWM
on the ESP32?
3. If using PWM to control an LED's brightness, how does adjusting the PWM duty
cycle impact the perceived brightness of the LED?
4. How would you observe and measure the analog-like output generated by the ESP32,
such as using an oscilloscope or a multimeter?
5. What aspects of the signal (frequency, duty cycle) would you examine during
observation?
OBJECTIVE:
REQUIRED COMPONENTS:
THEORY:
53
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
You can typically use the ESP32 built-in DAC to generate an analog output DC voltage which
will remain constant until you update the value of the DAC buffer register. The digital input
value is 8-Bit because the ESP32 DAC is 8-Bit in resolution and the output is an analog
voltage level on the DAC_CHANNEL pin. Use the following formula to find out the analog
output that corresponds to any digital input value.
CIRCUIT:
54
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
CODE:
#define DAC_CH1 25
void setup()
{
// DO NOTHING
}
void loop()
{
// Send Output DC Voltage Raw Values To The DAC
// (0 64 128 192 255)
// Insert Delay After Each Sample Output
dacWrite(DAC_CH1, 0);
delay(3500);
dacWrite(DAC_CH1, 64);
delay(3500);
dacWrite(DAC_CH1, 128);
delay(3500);
dacWrite(DAC_CH1, 192);
delay(3500);
dacWrite(DAC_CH1, 255);
delay(3500);
}
OUTPUT:
55
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
RESULT:
56
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
PREREQUISITE:
PRE-LAB:
OBJECTIVE:
• To generate sine wave with ESP32 using the built-in DAC feature.
• To obtain clean sinusoidal waveform with controllable frequency, amplitude, and
phase.
REQUIRED COMPONENTS:
57
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
CIRCUIT:
CODE:
#include <driver/dac.h>
58
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
OUTPUT:
RESULT:
59
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
PREREQUISITE:
PRE-LAB:
1. What is EEPROM, and what distinguishes it from other types of memory like RAM
and Flash memory?
2. What are the characteristics and limitations of the EEPROM emulation on the
ESP32?
3. What is the typical size or capacity of the EEPROM space available on the ESP32
for data storage?
4. How would you verify the accuracy and consistency of data read from and written
to the EEPROM?
OBJECTIVE:
To test the EEPROM memory of ESP 32 by saving the last LED state
REQUIRED COMPONENTS:
60
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
CIRCUIT:
CODE:
// Include The EEPROM.h Library To Read & Write To The FLASH Memory
#include <EEPROM.h>
void setup() {
Serial.begin(115200);
pinMode(LED_GPIO, OUTPUT);
pinMode(BTN_GPIO, INPUT);
EEPROM.begin(EEPROM_SIZE);
ledState = EEPROM.read(eeprom_address);
digitalWrite(LED_GPIO, ledState);
61
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
void loop() {
int reading = digitalRead(BTN_GPIO);
if (reading != lastBtnState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != btnState) {
btnState = reading;
if (btnState == HIGH) {
ledState = !ledState;
digitalWrite(LED_GPIO, ledState);
EEPROM.write(eeprom_address, ledState);
EEPROM.commit();
Serial.println("State Changed & Saved To FLASH!");
}
}
}
lastBtnState = reading;
}
Code Explanation:
The code example does simply read the button input pin and debounces it to make sure it’s
not picking up any noise. And toggle the LED if the button is actually pressed. The LED
toggle event does also a write operation to the eeprom_address location and saves the current
ledState in the FLASH memory.
62
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
We also define some global variables to save the LED state, and button state, and perform
the button debouncing logic.
Serial.begin(115200);
pinMode(LED_GPIO, OUTPUT);
pinMode(BTN_GPIO, INPUT);
EEPROM.begin(EEPROM_SIZE);
We also read the last saved LED state from the FLASH memory and apply it to the LED
output. This happens only at startup, hence it’s done in setup() function.
ledState = EEPROM.read(eeprom_address);
digitalWrite(LED_GPIO, ledState);
loop()
in the loop() function, it’s mostly about reading the button and debouncing it. Once, it’s clear
that the button is held HIGH and it’s not a noise, we take the LED toggle action + saving the
current LED state to the EEPROM (Flash Memory).
63
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
if (btnState == HIGH)
{
ledState = !ledState;
digitalWrite(LED_GPIO, ledState);
EEPROM.write(eeprom_address, ledState);
EEPROM.commit();
Serial.println("State Changed & Saved To FLASH!");
}
}
}
lastBtnState = reading;
OUTPUT:
RESULT:
64
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
PREREQUISITE:
PRE-LAB:
1. What Bluetooth capabilities does the ESP32 offer, and which Bluetooth protocols or
versions does it support?
2. How does the ESP32 detect and identify Bluetooth devices within its range?
3. How does the ESP32 handle potential errors or issues during Bluetooth device
scanning?
4. Once Bluetooth devices are scanned, how is the information about discovered
devices collected and retrieved in ESP32-based code?
OBJECTIVE:
REQUIRED COMPONENTS:
THEORY:
ESP32 Bluetooth Scanner:
The ESP32 Bluetooth Scanner is also called Device Discovery which is a very simple
application that runs either Synchronously or Asynchronously and searches for all surrounding
Bluetooth devices and report their number, names, and MAC addresses. Then you can choose
which device to connect to afterward or keep rescanning in case no device is found.
65
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
As stated earlier the ESP32 Bluetooth Scanner can run Synchronously (Blocking) which means
it’ll keep searching until completion and the whole application will be stuck until the
synchronous function call is executed till completion. It’s not generally a bad thing to do as it
may be required in some applications.
In order to perform Bluetooth Scanning for Device Discovery (Synchronously), use the
SerialBT.discover(BT_DISCOVER_TIME) function. For Asynchronous scanning, you should
use SerialBT.discoverAsync() function instead.
CODE:
#include <BluetoothSerial.h>
#if !defined(CONFIG_BT_SPP_ENABLED)
#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip.
#endif
BluetoothSerial SerialBT;
void setup() {
Serial.begin(115200);
SerialBT.begin("ESP32test"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
if (btScanSync) {
Serial.println("Starting discover...");
BTScanResults *pResults = SerialBT.discover(BT_DISCOVER_TIME);
if (pResults)
pResults->dump(&Serial);
else
Serial.println("Error on BT Scan, no result!");
}
}
void loop() {
66
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
delay(100);
}
OUTPUT:
RESULT:
67
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
PREREQUISITE:
PRE-LAB:
OBJECTIVE:
To create an ESP32 Bluetooth Receiver Device and use Android Smartphone to control it
over Bluetooth.
REQUIRED COMPONENTS:
68
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
CIRCUIT:
CODE:
#include "BluetoothSerial.h"
void setup() {
pinMode(LED_GPIO, OUTPUT);
Serial.begin(115200);
SerialBT.begin(device_name); //Bluetooth device name
69
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
Serial.printf("The device with name \"%s\" is started.\nNow you can pair it with
Bluetooth!\n", device_name.c_str());
SerialBT.setPin(pin);
Serial.println("Using PIN");
}
void loop() {
// Read The Received Bytes & Add Them To Message (RxBuffer) Array
if (SerialBT.available()){
RxByte = SerialBT.read();
if (RxByte != '\n'){
RxBuffer += String(RxByte);
}
else{
RxBuffer = "";
}
Serial.write(RxByte);
}
// Check The Received Message & Update Output LED State
if (RxBuffer =="led_on"){
digitalWrite(LED_GPIO, HIGH);
}
else if (RxBuffer =="led_off"){
digitalWrite(LED_GPIO, LOW);
}
delay(25);
}
Code Explanation:
First of all, include the BluetoothSerial library and check if Bluetooth is properly enabled or
not.
#include "BluetoothSerial.h"
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
#if !defined(CONFIG_BT_SPP_ENABLED)
#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip.
#endif
Create an instance of the BluetoothSerial called SerialBT, and define a GPIO pin for LED
output which is going to be GPIO25 pin.
70
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
pinMode(LED_GPIO, OUTPUT);
Start serial communication for monitoring & debugging
Serial.begin(115200);
Start the Bluetooth device with the given name and PIN code.
In the loop() function, read the incoming data bytes and push them to the RxBuffer array.
// Read The Received Bytes & Add Them To Message (RxBuffer) Array
if (SerialBT.available()){
RxByte = SerialBT.read();
if (RxByte != '\n'){
RxBuffer += String(RxByte);
}
else{
RxBuffer = "";
}
71
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
Serial.write(RxByte);
}
Then check the received message buffer (RxBuffer) array, if it’s “led_on” turn the LED ON,
else if it was “led_off” turn the LED OFF. Otherwise, don’t take any action. And keep
repeating.
RESULT:
72
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
PREREQUISITE:
PRE-LAB:
1. What functionalities does the ESP32 offer for scanning nearby Wi-Fi networks?
2. How does the ESP32 detect and gather information about available Wi-Fi networks
within its range?
3. Outline the basic structure or algorithm of the code required to initiate Wi-Fi network
scanning using the ESP32.
OBJECTIVE:
REQUIRED COMPONENTS:
CODE:
#include "WiFi.h"
void setup()
{
Serial.begin(115200);
// Set WiFi to station mode and disconnect from an AP if it was previously connected.
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
Serial.println("Setup done");
73
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
}
void loop()
{
Serial.println("Scan start");
74
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
case WIFI_AUTH_WPA2_ENTERPRISE:
Serial.print("WPA2-EAP");
break;
case WIFI_AUTH_WPA3_PSK:
Serial.print("WPA3");
break;
case WIFI_AUTH_WPA2_WPA3_PSK:
Serial.print("WPA2+WPA3");
break;
case WIFI_AUTH_WAPI_PSK:
Serial.print("WAPI");
break;
default:
Serial.print("unknown");
}
Serial.println();
delay(10);
}
}
Serial.println("");
RESULT:
75
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
PREREQUISITE:
PRE-LAB:
1. How does the ESP32 detect and assess the signal strength of available Wi-Fi
networks within its range?
2. What metrics or units are commonly used to represent Wi-Fi signal strength, such as
dBm (decibel-milliwatts) or RSSI (Received Signal Strength Indicator)?
3. Can the ESP32 process or filter Wi-Fi network signal strength data to focus on
specific criteria (e.g., strong signals, weak signals)?
4. How would you verify the correlation between signal strength values and the actual
signal quality or network performance?
OBJECTIVE:
To get and print the RSSI (Received Signal Strength Indicator) for the WiFi network
CODE:
#include <WiFi.h>
void setup(){
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
76
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
Serial.println("\nConnecting");
// Keep Waiting Until Connection is Established
while(WiFi.status() != WL_CONNECTED){
Serial.print(".");
delay(100);
}
// Connected Successfully
Serial.println("\nConnected To The WiFi Network");
Serial.print("Local ESP32 IP: ");
Serial.println(WiFi.localIP());
// Print The RSSI (Received Signal Strength Indicator)
Serial.print("RRSI: ");
Serial.print(WiFi.RSSI());
Serial.println(" dBm");
}
void loop(){
// Do Nothing
}
Note:
RSSI is an estimated measure of the WiFi signal strength for a specific network (router or
access point). The return value has the following form and unit (-x dBm). Which means a lower
absolute value indicates a more powerful connection. Here’s how to judge the RSSI value and
decide on the signal strength rating:
OUTPUT:
77
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
RESULT:
78
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
PREREQUISITE:
PRE-LAB:
OBJECTIVE:
To learn how to Get the ESP32 MAC Address and how to Change the ESP32 MAC Address
in Arduino IDE
CODE:
#include <WiFi.h>
void setup(){
Serial.begin(115200);
Serial.print("\nDefault ESP32 MAC Address: ");
Serial.println(WiFi.macAddress());
}
79
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
void loop(){
// Do Nothing
}
OUTPUT:
RESULT:
CODE:
#include <WiFi.h>
#include <esp_wifi.h>
void setup(){
Serial.begin(115200);
WiFi.mode(WIFI_STA);
Serial.print("\nOLD ESP32 MAC Address: ");
80
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
Serial.println(WiFi.macAddress());
esp_wifi_set_mac(WIFI_IF_STA, New_MAC_Address);
Serial.print("NEW ESP32 MAC Address: ");
Serial.println(WiFi.macAddress());
}
void loop(){
// Do Nothing
}
OUTPUT:
RESULT:
81
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
PREREQUISITE:
PRE-LAB:
1. What is an IP address?
2. Explain the purpose of subnet masks.
3. How does the ESP32 handle networking tasks?
4. What is the significance of SSID and password in WiFi configuration?
OBJECTIVE:
REQUIRED COMPONENTS:
CODE:
#include <WiFi.h>
void setup(){
Serial.begin(115200);
WiFi.mode(WIFI_STA);
82
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
WiFi.begin(ssid, password);
Serial.println("\nConnecting to WiFi Network ..");
// Wait until connection is established
while(WiFi.status() != WL_CONNECTED){
Serial.print(".");
delay(100);
}
// Print network settings assigned by the DHCP
Serial.println("\nConnected to the WiFi network");
Serial.print("Local ESP32 IP: ");
Serial.println(WiFi.localIP());
Serial.print("Subnet Mask: " );
Serial.println(WiFi.subnetMask());
Serial.print("Gateway IP: ");
Serial.println(WiFi.gatewayIP());
Serial.print("DNS 1: ");
Serial.println(WiFi.dnsIP(0));
Serial.print("DNS 2: ");
Serial.println(WiFi.dnsIP(1));
}
void loop(){
// Do Nothing
}
OUTPUT:
RESULT:
83
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
PREREQUISITE:
PRE-LAB:
OBJECTIVE:
REQUIRED COMPONENTS:
84
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
CODE:
#include <WiFi.h>
void setup(){
Serial.begin(115200);
WiFi.mode(WIFI_STA);
// Configures Static IP Address
if (!WiFi.config(local_IP, gateway,
subnet, primaryDNS, secondaryDNS))
{
Serial.println("Configuration Failed!");
}
85
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
WiFi.begin(ssid, password);
Serial.println("\nConnecting to WiFi
Network ..");
// Wait until connection is established
while(WiFi.status() !=
WL_CONNECTED){
Serial.print(".");
delay(100);
}
Serial.println("\nConnected to the WiFi
network");
// Print The IP And It Should Match The
Desired Static IP That We've Defined
Serial.print("Local ESP32 IP: ");
Serial.println(WiFi.localIP());
}
void loop(){
// Do Nothing
}
Note:
Don’t forget to change the ssid and password to match your network credentials.
OUTPUT:
RESULT:
86
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
PREREQUISITE:
PRE-LAB:
OBJECTIVE:
To get the ESP32 hostname and also to modify custom hostname in Arduino IDE.
REQUIRED COMPONENTS:
ESP32 Get HostName: The ESP32 Hostname is the device name that other WiFi devices
will see on the network. You can get the ESP32 hostname by calling
87
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
the WiFi.getHostname() function. Here is an example code for getting and printing the
ESP32 WiFi hostname.
Serial.println(WiFi.getHostname());
Here is the generic (default) hostname for my ESP32 board as seen by my router.
To change the ESP32 hostname, you need to call the WiFi.setHostname() function before
calling WiFi.mode() and then WiFi.begin() in this exact same order.
CODE:
#include <WiFi.h>
void setup(){
Serial.begin(115200);
WiFi.setHostname(MyHostName);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("\nConnecting to WiFi
Network ..");
// Wait until connection is established
while(WiFi.status() !=
WL_CONNECTED){
88
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
Serial.print(".");
delay(100);
}
// Print ESP32's IP & HostName
Serial.println("\nConnected to the WiFi
network");
Serial.print("Local ESP32 IP: ");
Serial.println(WiFi.localIP());
Serial.print("ESP32 HostName: ");
Serial.println(WiFi.getHostname());
}
void loop(){
// Do Nothing
}
OUTPUT:
And now my router is seeing the new ESP32 Hostname after running the example code above
RESULT:
89
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
Session 21: Controlling the GPIO pins in ESP32 using Touch Inputs
PREREQUISITE:
PRE-LAB:
1. What type of cable should be used for ESP32? What parameters or information are
required to configure or change the hostname of an ESP32 device?
2. Specify ROM size of ESP32?
3. Mention the software which is to be installed in the laptop for ESP32 board?
4. What is the operating voltage of the GPIO pins in ESP32?
OBJECTIVE:
To interface MPU6050 module with ESP32 and WEBSERVER using Arduino IDE
Programming.
REQUIRED COMPONENTS:
CONNECTION:
90
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
CODE:
// set pin numbers
const int touchPin = 4;
const int ledPin = 16;
void setup(){
Serial.begin(115200);
delay(1000); // give me time to bring up serial monitor
// initialize the LED pin as an output:
pinMode (ledPin, OUTPUT);
}
void loop(){
// read the state of the pushbutton value:
touchValue = touchRead(touchPin);
Serial.print(touchValue);
// check if the touchValue is below the threshold
// if it is, set ledPin to HIGH
91
Koneru Lakshmaiah Education Foundation
23SDEC02A EMBEDDED SYSTEM AUTOMATION - SKILL MANUAL
if(touchValue< threshold){
// turn LED on
digitalWrite(ledPin, HIGH);
Serial.println(" - LED on");
}
else{
// turn LED off
digitalWrite(ledPin, LOW);
Serial.println(" - LED off");
}
delay(500);
}
Precautions:
1. Use insulation tools while you connect the Circuit.
2. Wear Good Insulating Shoes.
3. Avoid contacting circuits with wet hands or wet materials.
4. Maintain a work space clear of extraneous material such as books, papers, and
clothes.
5. Be careful while connecting any actuators in 230V AC Mains.
RESULTS:
92
Koneru Lakshmaiah Education Foundation