When programming the ESP32 using the Arduino IDE, you typically use the ESP32 Arduino core, which provides a set of libraries and APIs to facilitate development. In this tutorial, we can discuss ESP32 ArduinoCore Interface Basic Example of Serial, GPIO, Timer, etc
Explore the fundamental features of the ESP32 microcontroller through an introductory example utilizing the ArduinoCore interface. This tutorial covers Serial communication, GPIO configuration for digital input and output, and Timer usage for precise timing operations. Ideal for beginners and hobbyists, this basic example demonstrates how to implement essential functionalities such as blinking an LED, reading button inputs, and handling timer interrupts, providing a solid foundation for further exploration and development with the ESP32 platform.”
Contents
Use
- Serial communication is used to print messages to the serial monitor.
- GPIO pins are used to control an LED and read the state of a button.
- A timer interrupt is used to toggle the LED state and print a message at regular intervals.
Serial (UART Communication) Interface
Required Hardware and Software
- Arduino IDE (Arduino Core for ESP32 )
- ESP-WROOM-32 Development Kit
Connection Diagram
- Just Connect ESP32 module with PC using USB cable
Code of printing Strings
/* http://esp8266iot.blogspot.in/ http://aruneworld.blogspot.com/ Tested By : Arun(20170219) Example Name : AEW_ESP32_HelloWorld_UARTSerialCommunication.ino */ void setup() { Serial.begin(115200); // You can Change the Baudrate } void loop() { Serial.println("ArunEworld"); Serial.println("ESP32 Tutorials : Hello World"); Serial.println("[********************************]"); delay(2000); //2 sec delay }
Output
ArunEworld ESP32 Tutorials : Hello World [********************************]
Get ESP32 Chip ID
Note : You can use arduino example code instead of below code because both are same (File > Example > ESP32 > ChipID
uint64_t chipid; void setup() { Serial.begin(115200); } void loop() { chipid=ESP.getEfuseMac();//The chip ID is essentially its MAC address(length: 6 bytes). Serial.printf("ESP32 Chip ID = %04X",(uint16_t)(chipid>>32));//print High 2 bytes Serial.printf("%08X\n",(uint32_t)chipid);//print Low 4bytes. delay(3000); }
Output
ets Jun 8 2016 00:22:57 rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) ets Jun 8 2016 00:22:57 rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0x00 clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:1 load:0x3fff0008,len:8 load:0x3fff0010,len:160 load:0x40078000,len:10632 load:0x40080000,len:252 entry 0x40080034 ESP32 Chip ID = EC5502A4AE30 ESP32 Chip ID = EC5502A4AE30
GPIO Interface (LED, Buzzer)
LED-Blink Using Loop_Delay
Connection Diagram
Code
Note: You can use Arduino example code instead of below code because both are the same (File > Example > Basic > Blink
/* Blink Turns on an LED on for one second, then off for one second, repeatedly. Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to the correct LED pin independent of which board is used. If you want to know what pin the on-board LED is connected to on your Arduino model, check the Technical Specs of your board at https://www.arduino.cc/en/Main/Products This example code is in the public domain. modified 8 May 2014 by Scott Fitzgerald modified 2 Sep 2016 by Arturo Guadalupi modified 8 Sep 2016 by Colby Newman */ // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(23, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(23, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(23, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second }
Remember
To upload this code to your ESP32 board using the Arduino IDE:
- Make sure you have the ESP32 board installed in the Arduino IDE. You can follow the instructions provided by Espressif or other tutorials online.
- Connect your ESP32 board to your computer via USB.
- Select the appropriate board and port from the Arduino IDE’s Tools menu.
- Click the Upload button to compile and upload the code to your ESP32 board.
Next
Arduino-Core Get Start (Soon) |
|
ArduinoCore Interface Basics |
ArduinoCore Interface WiFi |
ArduinoCore Interface – LED |
ArduinoCore Interface ADC |
ArduinoCore Interface DS18B20 |
|
ArduinoCore Project – WebServer |
|
Arduino-Core Sitemap |
Arduino-Core All Post |