What is Esp32 and setup guide

 




Introduction

When we think about using a microcontroller for a project we usually consider an Arduino. It’s inexpensive, easy to use and has a generous number of digital I/O ports, and a few analog inputs as well.

But the Arduino, for all of its wonderful benefits, is lacking in a number of areas. The first one is speed, the popular Arduino AVR series of boards run at 16 MHz. That’s certainly fast enough to build thousands of applications, but it’s a bottleneck for others.

The Arduino certainly has enough digital outputs and inputs to satisfy most requirements, and its analog inputs are also useful. But adding features like WiFi and Bluetooth requires external components.

Let’s face it, the Arduino has been around since 2005. That’s fifteen years, which in terms of technology is eons. 

The Arduino is well-loved here in the DroneBot Workshop and I’ll continue to use it for many projects and experiments. But I also feel that it’s time to explore other microcontrollers.

Introducing ESP32

The ESP32 is actually a series of microcontroller chips produced by Espressif Systems in Shanghai.  It is available in a number of low-cost modules.

ESP32 Introduction

The ESP32 is an updated version of the ESP8266, which was a chip that took experimenters in the western world by “surprise” in 2014. The original ESP8266 was introduced on a module called the ESP-01, which had very little English documentation so it’s capabilities were largely unknown at the time. Once the documentation was translated into English many experimenters soon became aware of the power of the ESP8266, and it quickly became very popular.

The ESP32 improved upon the ESP32 design in a number of ways.  It offers both Bluetooth and BLE (Bluetooth Low Energy), whereas the ESP8266 only has WiFi (which, of course, the ESP32 also has). It is faster and is available in a dual-core design. It is also capable of operating in an ultra-low-power mode, ideal for battery-powered applications.

Other features of the ESP32 include:

  • Up to 18 12-bit Analog to Digital converters.
  • Two 8-bit Digital to Analog converters.
  • 10 capacitive touch switch sensors.
  • Four SPI channels.
  • Two I2C interfaces.
  • Two I2S interfaces (for digital audio).
  • Three UARTs for communications.
  • Up to 8 channels of IR remote control.
  • Up to 16 channels of LED PWM (pulse width modulation).
  • An integrated Hall-effect sensor.
  • An ultra-low-power analog preamp.
  • An internal low-dropout regulator.

Note that many of the pins on the ESP32 share a number of the above functions, so not all of them are available concurrently.

ESP32 Modules

There are many ESP32 modules available for experimenters. Just about any of them can be used for the experiments here.

Many of these boards have an integrated micro-USB connector that will simplify programming. Some boards don’t have this feature and require an external FTDI adapter for programming.

Most of these boards are based upon the ESP32-WROOM chip.

The ESP32 DEV KIT and ESP32 NODEMCU boards are quite popular and available at Amazon and eBay.

Adafruit makes the HUZZAH32 board.

Sparkfun has the ESP32-Thing board.

And the popular ESP32-Cam board integrates a small video camera and a microSD card socket along with an ESP32 (this board will require an FTDI adapter for programming).

Please note that these boards share many features but they don’t have the same pinouts.  In our experiments, I’ll be referring to the pin function (i.e. GPIO 4) instead of an actual pin number. This will allow you to use a different board than the one I am using.

Programming the ESP32

The ESP32 can be programmed using many different development environments.  Code can be written in C++ (like the Arduino) or in MicroPython.

To make use of all of the ESP32 features Espressif provided the Espressif IoT Development Framework, or ESP-IDF.

For beginners, an easy way to get started is by using the familiar Arduino IDE. While this is not necessarily the best environment for working with the ESP32, it has the advantage of being a familiar application, so the learning curve is flattened.

We will be using the Arduino IDE for our experiments.

Getting started with the Arduino IDE

Before we can use the Arduino IDE with an ESP32 board we will need to add the ESP32 boards using the Arduino IDE Board Manager.

If you look online for instructions for setting up the IDE you may run into a long and complex procedure that actually isn’t necessary anymore. As long as you are using a recent version of the Arduino IDE you can use the following instructions, which are much simpler.

ESP32 for Arduino IDE

In order to be able to work with the ESP32 you will need to add an additional source to the Arduino IDE Board Manager and then install the ESP32 boards.

This is actually a lot simpler than it sounds thanks to the folks at Espressif. They have provided a link to a JSON file that takes care of almost everything for you.

If you are not familiar with JSON it is a format of text file that allows structured information to be shared between computers. In this respect, it is similar to XML.

Add Boards Manager Entry

Here is what you need to do to install the ESP32 boards into the Arduino IDE:

  1. Open the Arduino IDE. Make sure that you are at version 1.8 or higher, if not then update your IDE with the latest version.
  2. Click on the File menu on the top menu bar.
  3. Click on the Preferences menu item. This will open a Preferences dialog box.
  4. You should be on the Settings tab in the Preferences dialog box by default.
  5. Look for the textbox labeled “Additional Boards Manager URLs”.
  6. If there is already text in this box add a coma at the end of it, then follow the next step.
  7. Paste the following link into the text box – https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
  8. Click the OK button to save the setting.

The textbox with the JSON link in it is illustrated here:

ESP32 Add Board Manager JSON

Next, you will need to use the new entry to actually add the ESPO32 boards to your Arduino IDE. You do that by following this procedure:

  1. In the Arduino IDE click on the Tools menu on the top menu bar.
  2. Scroll down to the Board: entry (i.e. Board: Arduino/Genuino Uno).
  3. A submenu will open when you highlight the Board: entry.
  4. At the top of the submenu is Boards Manager. Click on it to open the Boards Manager dialog box.
  5. In the search box in the Boards Manager enter “esp32”.
  6. You should see an entry for “esp32 by Espressif Systems”. Highlight this entry and click on the Install button.
  7. This will install the ESP32 boards into your Arduino IDE

ESP32 Arduino Board Manager

If you go back into the Boards: submenu you should now see a number of ESP32 boards. You’ll need to select the board that matches (or is equivalent to) the ESP32 board you have purchased.

For the record, I used an ESP-32S NodeMCU board and chose the “Node32s” board in the Boards Manager.

You have probably finished setting up your Arduino IDE! The reason I say “probably” is that it is possible that you may need to install some additional Python files. 

The easiest way to figure that out is to compile and upload a program to your ESP32 board and see if you get an error.  Don’t worry, I’ll show you how to fix that error if you do!

Experiment Hookup

Before we can upload a test program we will need to hookup our ESP32 board. 

The following diagram shows the connections we’ll need to perform all of the experiments and demos included in this article. Note that the ESP32 pins are specified by their GPIO names and not pin numbers, as different ESP32 boards will have different pin numbers. 

ESP32 Hookup

You can use pretty well any LED, for a dropping resistor any values between 150 and 470 ohms will work well. Any momentary-contact push button will suffice.

The small gold square in the diagram is a Touchpad. You can use any metallic object that you can connect a wire to, a small piece of PCB would work great. I just used a small piece of bare wire on my breadboard.

Now that we are all hooked up it’s time to try our first program.

Hello World – Blink for ESP32

When using a new development environment or programming for a new device it is traditional to create a “Hello World” program.  Far be it from me to dispense with tradition!

The “Hello World” for microcontrollers is the Blink sketch which, as I’m sure you already know, simply flashes an LED on and off.  While “Hello World” programs and sketches are usually of little practical use they serve a number of functions:

  • They familiarize you with the operation of your development library.  In this particular case they let you practice uploading programs to the ESP32 which, as you will soon see, is done a bit differently than an Arduino.
  • They get you familiar with the programming syntax. In this case we are using the same C++ that the Arduino uses, so you are likely already familiar with the programming syntax.
  • They let you verify that your hardware is working correctly.

Here is the classic Arduino Blink sketch, rewritten for the ESP32 module.

Aside from using GPIO pin 2 (instead of Arduino digital output pin 13) and adding the serial monitor it’s no different from the Arduino Blink sketch.

Note that the serial monitor is run at a higher baud rate than most Arduino sketches. While it isn’t really necessary with this sketch it is often done with ESP32 sketches, as the microcontroller runs much faster than the Arduino AVR boards do.

Uploading the program

After you load the sketch into your Arduino IDE it will need to be compiled and then transferred to the ESP32 board.

With an Arduino you just have to hit the Upload button and both of these steps will proceed automatically.   With the ESP32, however, there is an additional step.

You begin by doing exactly the same thing you would with an Arduino – hit the Upload button (the one with the right-pointing arrow).  This will start the compiler. You’ll probably notice that it takes longer to compile ESP32 programs than it does for Arduino sketches.

ESP32 Buttons

Watch the status screen at the bottom of the Arduino IDE. When the compiling process is finished it will print “Connecting”, followed by a string of periods.

When you see this you’ll need to press the BOOT button (sometimes labeled IO0) and hold it down until you see the upload progressing, which you’ll know is happening when you see the upload progress displayed in percentage.

After the program is uploaded you will need to press the ENABLE or RESET button to start it  (some boards don’t require this step).

ESP32 Connecting

And if all goes well you’ll be rewarded with a flashing LED!

But it’s also possible that you’ll get an error message about a missing module named “serial”. If that happens don’t worry, there is a fix.

Problem with “No module named serial”

This issue occurs because one or more of the underlying Python programs is not installed on your computer. The compiler is looking for a program called pyserial and is not finding it.

On Mac and Linux machines this is usually already installed, but not always – in fact the computer I used in the video (Ubuntu Linux 16.04) didn’t have pyserial installed. So I downloaded and installed it using this (very long) command-line string:

 sudo usermod -a -G dialout $USER && sudo apt-get install git && wget https://bootstrap.pypa.io/get-pip.py && sudo python get-pip.py && sudo pip install pyserial && mkdir -p ~/Arduino/hardware/espressif && cd ~/Arduino/hardware/espressif && git clone https://github.com/espressif/arduino-esp32.git esp32 && cd esp32 && git submodule update –init –recursive && cd tools && python3 get.py

As you need to sudo you’ll need to enter your password to supply permissions.

Windows users may have additional difficulties installing pyserialAdafruit published some detailed instructions that should be of assistance.




this content by dronebotworkshop

https://dronebotworkshop.com/esp32-intro/  this link

1 Comments