Skip to content

Class : 1 Duration : 3 Hours

Syed Razwanul Haque Nabil edited this page Sep 4, 2018 · 4 revisions

Topics :

  • What is IoT and its Use ?
  • ESP32 and the board description , Input-Output , etc
  • CP210X Chip Install (if needed)
  • Download and Install Arduino & ESP32
  • Brief Description about Arduino & Arduino IDE
  • Other platform to Develop ESP32 based board
  • Blinking Code Upload
  • Programming Options for ESP32
  • Description about Output and Input
  • LED Output and Button Input
  • Troubleshot a Practice

What is IoT ?

https://en.wikipedia.org/wiki/Internet_of_things https://internetofthingsagenda.techtarget.com/definition/Internet-of-Things-IoT

The Internet of Things (IoT) is the network of physical devices, vehicles, home appliances, and other items embedded with electronics, software, sensors, actuators, and connectivity which enables these things to connect and exchange data,creating opportunities for more direct integration of the physical world into computer-based systems, resulting in efficiency improvements, economic benefits, and reduced human exertions. The number of IoT devices increased 31% year-over-year to 8.4 billion in 2017 and it is estimated that there will be 30 billion devices by 2020. The global market value of IoT is projected to reach $7.1 trillion by 2020. IoT involves extending internet connectivity beyond standard devices, such as desktops, laptops, smartphones and tablets, to any range of traditionally dumb or non-internet-enabled physical devices and everyday objects. Embedded with technology, these devices can communicate and interact over the internet, and they can be remotely monitored and controlled.

ESP32 and the board description , Input-Output , etc :

ESP32 is a series of low-cost, low-power system on a chip microcontrollers with integrated Wi-Fi and dual-mode Bluetooth. The ESP32 series employs a Tensilica Xtensa LX6 microprocessor in both dual-core and single-core variations and includes in-built antenna switches, RF balun, power amplifier, low-noise receive amplifier, filters, and power-management modules. ESP32 is created and developed by Espressif Systems, a Shanghai-based Chinese company, and is manufactured by TSMC using their 40 nm process. It is a successor to the ESP8266 microcontroller.

ESP32 Block Diagram

Features Features of the ESP32 include the following:
Processors:
CPU: Xtensa dual-core (or single-core) 32-bit LX6 microprocessor, operating at 160 or 240 MHz and performing at up to 600 DMIPS
Ultra low power (ULP) co-processor
Memory: 520 KiB SRAM
Wireless connectivity:
Wi-Fi: 802.11 b/g/n
Bluetooth: v4.2 BR/EDR and BLE
Peripheral interfaces:
12-bit SAR ADC up to 18 channels
2 × 8-bit DACs
10 × touch sensors (capacitive sensing GPIOs)
Temperature sensor
4 × SPI
2 × I²S interfaces
2 × I²C interfaces
3 × UART
SD/SDIO/CE-ATA/MMC/eMMC host controller
SDIO/SPI slave controller
Ethernet MAC interface with dedicated DMA and IEEE 1588 Precision Time Protocol support
CAN bus 2.0
Infrared remote controller (TX/RX, up to 8 channels)
Motor PWM
LED PWM (up to 16 channels)
Hall effect sensor
Ultra low power analog pre-amplifier
Security:
IEEE 802.11 standard security features all supported, including WFA, WPA/WPA2 and WAPI
Secure boot
Flash encryption
1024-bit OTP, up to 768-bit for customers
Cryptographic hardware acceleration: AES, SHA-2, RSA, elliptic curve cryptography (ECC), random number generator (RNG)
Power management:
Internal low-dropout regulator
Individual power domain for RTC
5uA deep sleep current
Wake up from GPIO interrupt, timer, ADC measurements, capacitive touch sensor interrupt

### ESP 32 Module :

Various company produce various ESP-32 based module for easy prototyping. Those boards includes USB communication, Power management, Display ,etc depends on manufacturer.

Module that we are using :

http://s.click.aliexpress.com/e/cnLGXW0o

CP210X Chip Install (if needed):

Install From This Link https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers

Download and Install Arduino & ESP32:

  1. Install Arduino IDE from this link https://www.arduino.cc/en/Main/Donate

  2. Install CP210X Driver if needed
    https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers

  3. Open Arduino IDE > File > Preferences > Additional Board Manager URLs > Copy and Paste below link https://dl.espressif.com/dl/package_esp32_index.json

if you have installed ESP8266 previously use separate above link with comma.
4) Tools > Boards > Boards Manager > “Type ESP32” > Install

Brief Description about Arduino & Arduino IDE:

https://www.arduino.cc/en/Guide/Environment
Teacher Will Explain .
https://learn.sparkfun.com/tutorials/what-is-an-arduino

Other platform to Develop ESP32 based module:

Another Alternative is VS Code with Platform IO
http://docs.platformio.org/en/latest/ide/vscode.html
http://docs.platformio.org/en/latest/ide/vscode.html http://esp32.net
https://openhomeautomation.net/getting-started-esp32

Blinking Code Upload :

Attach LED with a 1K resistor . If your module have built-in LED than make sure you enter the right GPIO(General Purpose Input Output) Pin. Now copy and paste code and upload to board.

int LED_PIN = 2;
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_PIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_PIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);                   	
  digitalWrite(LED_PIN, LOW);	// turn the LED off by making the voltage LOW
  delay(500);                
}

Programming Options for ESP32:

Input, Output, PWM, Interrupt, WiFi AP, WiFi Scan, WiFi Connect, Web server, Bluetooth Normal, Bluetooth BLE, OTP, SD Card, HTTP Connection, File Server, SPI, SPIFFS, ESP NOW, DNS Server , Smart Config etc

ESP32 support AT Command.

GPIO Output :
General Purpose Input Output (GPIO) . When HIGH output is 3.3V and 0 when LOW

In setup. Usually setup function contains code those are necessary for configure ESP32 Board.
Step 1 : pinMode(GPIO , OUTPUT);
Step 2: digitalWrite(GPIO , HIGH);

if we need delay than call delay(ms) e.g. delay(1000) means wait 1 seconds or 1000 milliseconds
we can use array to control multiple GPIO to create pattern output. e.g. running light

GPIO Input :
We can use button input to call any event.
Circuit : A button has to connect with GPIO pin and GND. Input pullup should be activated. Teacher will explain about circuit and what is input pullup and pulldown.

pinMode(4, INPUT_PULLUP); 
// GPIO 4 pin as input and also internally connected with HIGH to avoid noise
uint8_t pinState = digitalRead(0);
//uint8_t means 8 bit integer . digitalRead will read pin state(HIGH or LOW) of GPIO pin.

Toggle LED Example :

//ESP32 Toggle LED Example
// Circuit: Connect and Push Button between GPIO 13 and GND
//Edited by
//Syed Razwanul Haque Nabil , CRUX 
int ledPin =2;
int buttonPin =13;
int buttonState = 0;
int ledState = 0;

void setup() {
 pinMode(ledPin,OUTPUT);
 pinMode(buttonPin, INPUT_PULLUP);
}

void loop() {
  int reading = digitalRead(buttonPin);
  if(reading != buttonState ){
    delay(30); //debounce 
    buttonState = reading;
   if(buttonState == LOW){ 
    ledState = !ledState;
   }
   digitalWrite(ledPin, ledState);
  }
}

LED Output and Button Input with Serial communication :

Push Button 1 is attached with GPIO 4 and GND. Input Pullup is activated that means Input pin is connected with HIGH internally. When we press push button ESP32 will detect press as LOW One Led is connected with GPIO 2 or If your ESP32 module contains Builtn in LED you dont need to connect externally. (Teacher will explain what is Serial Communication and its baud rate) https://www.arduino.cc/reference/en/language/functions/communication/serial/
Difference Between Serial.Write() and Serial.Print()

/*
Push Button 1 is attached with GPIO 4 and GND.
Input Pullup is activated that means Input pin is connected with HIGH internally.
When we press push button ESP32 will detect press as LOW
One Led is connected with GPIO 2 or If your ESP32 module contains Builtn in LED   
*/

int pushButton1 = 4;
int ledPin1 = 2;
// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  // make the pushbutton's pin an input:
  pinMode(pushButton1, INPUT_PULLUP);
  pinMode(ledPin1, OUTPUT);
  
}
void loop() {
  // read the input pin:
  int buttonState1 = digitalRead(pushButton1);
  // print out the state of the button:
  Serial.println(buttonState1);
  delay(100);        // delay in between reads for stability
  if(buttonState1 == 0)
  {
    digitalWrite(ledPin1, HIGH);
  }
  else{
    digitalWrite(ledPin1, LOW);
  }
  
}

**Teacher will Explain about Button Debounce **

Clone this wiki locally