IOT

How to Program ESP32 with Arduino IDE?

In this article, we’ll discover how to install the ESP32 Board in the Arduino IDE and how to programme the ESP32 using the IDE. As long as you have Arduino IDE installed, this tutorial is relevant to all of the popular operating systems, including Windows, macOS, and Linux. Let’s get started.

Getting-Started-with-ESP32

Do you have the Arduino IDE installed?

The Arduino IDE is the first item you require. Visit the official Arduino download page and download the installation file for your selected operating system if you don’t already have Arduino IDE installed on your computer.

ESP32-Arduino-IDE-1

Make sure the Arduino IDE is up to date if you have already installed it.

Preparing Arduino IDE

Go to File -> Preferences in the Arduino IDE after starting it up.

ESP32-Arduino-IDE-2

A fresh window opens. There is a selection labelled “Additional Boards Manager URLs” near the end. Paste the following URL into the box next to this choice, then click OK.

https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
ESP32-Arduino-IDE-3

NOTE: Use commas to separate URLs if you want to add more than one.

The above URL will now be used by the Arduino IDE to search for other boards beyond those that are already installed.

Installing ESP32 Board in Arduino IDE

You are now prepared to install the ESP32 boards in the Arduino IDE after adding the URL. Select the option under Tools -> Board -> Boards Manager. It will open a Boards Manager window.

ESP32-Arduino-IDE-4

Type “esp32” into the top search bar and press Enter. The output will read “esp32 by Espressif Systems.” Click the install button after selecting this. The ESP32 boards, tools, programmer, and other resources are now downloaded from the internet via the Arduino IDE.

ESP32-Arduino-IDE-5

Ensure that your computer can connect to the internet. This could take one or two minutes. You can close the Boards Manager once the installation has been completed successfully.

Selecting ESP32 Development Board

Now, you must first choose the appropriate board in order to build programmes for ESP32 devices (the board which you have). Go to Tools -> Board once again to accomplish this. You can notice that the list of boards now includes a brand-new selection called ESP32 Arduino.

ESP32-Arduino-IDE-6

A list of ESP32 Boards supported by the Arduino IDE will emerge when you hover over ESP32 Arduino. I chose ESP32 Dev Module because I already own a generic ESP32 DevKit. Most of the generic 30-pin ESP32 boards that are currently available can use this board.

Choose the proper board if you have a different board from a different manufacturer, such as SparkFun or WEMOS.

Go back to the Tools menu now to observe that the board options have changed and are now particular to the ESP32 Board that you choose. Don’t alter or edit any settings just yet. When necessary, I will specify the changes that must be made.

ESP32-Arduino-IDE-7

Your First ESP32 Program

Let’s develop a short program to, well, blink an LED to show how the ESP32 Arduino IDE installation functions. One user LED is built into and wired to GPIO2 of my ESP32 Development Board.

ESP32-LED-Blink

The LED is probably attached to the same GPIO if you use a generic 30-pin ESP32 board. You may still use the following software even if your board doesn’t come with any built-in LEDs by attaching a 5mm LED to GPIO2 (labelled as D2 on the board) and using a 220 current-limiting resistor.

  #define ledPin 2
   
  void setup()
  {
  pinMode(ledPin, OUTPUT);
   
  digitalWrite(ledPin, HIGH);
  delay(5000);
  }
   
  void loop()
  {
  digitalWrite(ledPin, HIGH);
  delay(1000);
   
  digitalWrite(ledPin, LOW);
  delay(1000);
  }

Programming ESP32 with Arduino IDE

 The ESP32 board should be connected to a micro-USB cable, with the other end being plugged into a USB port on your computer. You won’t experience any driver troubles with the CP2102 USB to UART Bridge if your PC is running Windows 10 and is up to date.

Troubleshooting Tip

However, if your computer was unable to recognise the device, you must install the Virtual COM Port Drivers from the CP2102 manufacturer’s website (manufacturer is Silicon Labs). To download the correct driver for your operating system, click this link.

A COM port will be assigned to the device if Windows recognises it. Go to Device Manager in Windows OS to find the correct COM Port number.

CP2102-COM-Port

Go to the Tools menu in the Arduino IDE and choose the ESP32 COM Port. It was COM4 in my situation.

ESP32-COM-Port

Click the Upload button after entering the code in the Arduino IDE (or copying it from above). If all goes according to plan, the board will automatically switch the ESP32 into programming mode, upload the code to the embedded flash memory, and reset the microcontroller to normal mode.

ESP32-Arduino-IDE-8

You can see the LED Blinking.

ESP32-LED-Blink-GIF

Common Problems

The first issue you might have with the ESP32 Board has to do with the CP2102 USB to UART Bridge Drivers. I’ve previously provided the driver download link.

Not placing the ESP32 in programming mode while uploading the code is another issue. If the Serial Monitor is open, close it before selecting the Upload button on the Arduino IDE and holding down the BOOT button on the ESP32 chip.

You can let off of the BOOT button after it recognizes the chip, and the code will upload. Press the EN button once to restart the microcontroller.

Conclusion

I hope all of you understand the basics of  Programming ESP32 with Arduino IDE. We MATHA ELECTRONICS will be back soon with more informative blogs.

Leave a Reply

Your email address will not be published. Required fields are marked *