Arduino To ESP32: How to Get Started!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
If you're looking to upgrade your Arduino projects with wireless capabilities, this is how to get started with the ESP32. We'll cover quick spec comparisons, Picking your first board, how to program it, and other key features of the ESP32. Let's start by comparing the two boards. We use a classic Arduino Uno and the ESP32 DevKitC which is a Espressif’s entry-level development board. Both have a microcontroller chip, which is like the brains for each one. The UNO sports the 16MHz ATmega328P whilst the ESP’s got a 240MHz D0WDQ6 chip underneath this metal RF shield. Let's test their processing power by running a program that will make them find as many prime numbers as they can in 30 seconds. The Arduino Uno managed to find over 3000 primes, but the ESP32 destroys it with over 125,000 primes. The other sections on each board are for voltage regulation programing ICs and GPIO pins to connect to other components. They've both got reset buttons, but the ESP has an additional boot button. Also, when I refer to Arduino, I'm referring to the original boards that use the ATmega chips and not the recent Arduinos that have ESP chips in them. If you're just getting started, you may be wondering what ESP32 model should I get? Checking the official website, You can see that Espressif produces their own chips. These chips create their series, which includes development boards or 'DevKits' that you can buy from their distributors. You may also come across ESP boards made by other companies like NodeMCU, Sparkfun and Adafruit. This is because Espressif open sources their schematics and PCBs! for simplicity though start with the ESP32 DevKitC. This is the one that has the standard ESP32 chip. A simple search on Amazon shows this model mass produced by other manufacturers. The one used for this video is a clone and they pretty much work all the same. It has a built in PCB antenna and 38 pins, so you can do more than a 30 pin one. There's a link in the description for a 3-pack of these DevKitC boards So if you happen to fry one or something, it's no big deal. Now onto the programming stuff The easiest way to program the ESP32 is with the Arduino IDE. It's just like working with an Arduino. There's just a bit of setup though... You need to get the ESP32 board package. Here's how. Open the Board Manager in the IDE search for ESP32 and install the latest version. Once installed, you can pick your board in the IDE. For this ESP32 Dev one choose the ESP32 Dev Module and now our code runs just fine. And also if you use Arduino functions in your sketch, make sure to include Arduino.h at the top. Some libraries are incompatible with the ESP and only work with Arduinos like the Servo and the TimerOne. Not to worry though, most popular libraries have an ESP32 version that does basically the same thing like ESP32Servo and ESP32TimerInterrupt. Now after the software is all set up, we need to know how to power this thing. You can power the ESP32 in three ways. 1. using the cable and plugging it in. 2. supplying 5V to the 5V and GND pins or 3. supplying 3.3V to 3.3V and GND pins. But be careful not to supply more voltage at this pin or it's gonna be fried. The only exception on this board is the 5V pin since it's got a voltage regulator. Great! Now everything is powered, Let's look at the pinout this ESP has 38 pins, 6 of which are for power and 6 can't be used. So that leaves us with 26 GPIO pins. These 26 are extremely versatile. 22 of them can output PWM with a resolution of 16 bits. So on Arduino, you're used to analogWriting values from 0 to 255, but with 16 bits on an ESP32, you can analogWrite from 0 to 65535. 16 pins can read analog signals with its 12 bit ADCs. 12 bits means it can read analog values from a range of 0 to 4095. The Arduino for comparison has a 10 bit ADC, so when you use the analogRead function, it will read analog values from a range of 0 to 1023. ESPs also have 2 DACs or Digital to Analog Converters, so you can generate analog signals. For a more detailed look of the pinout, you can pause right here to see the official diagram of the DevKitC. with the specs and the legend at the bottom. Now you know the pinout let's connect peripherals like sensors, drivers and displays. ESPs operate on 3.3V, while Arduinos operate on 5V. This means that all peripherals, whether they’re input or output ones, can only use 3.3V when sending data to or receiving data from the ESP. For components that will send signals to the ESP like this IR sensor, we need to check if it will output a signal of 3.3V or lower. If the module can operate on 3.3V, it will output signals at or below 3.3V, which is suitable for interfacing with the ESP. Let's keep going!💥 For components that receive signals from the ESP32, like this motor driver, We need to check the datasheet to know if a 3.3 volt signal was sent to the motor driver is considered as HIGH. It says input high voltage 2.3 volts, which means that the motor driver will see anything above this as a high signal. Nice! However, some peripherals like this ultrasonic sensor require 5V. Most of the time there are 3.3V alternatives like this module. But if you absolutely must use a component that operates on 5V, then you can use a level shifter. For example, if you wanted to have an Arduino communicating to an ESP, a level shifter would go in between and convert the 5V signals to 3.3V and the 3.3V signals to 5V. This way we can establish communication between the Arduino and the ESP. Let's see how the ESP and Arduino communicate. Hey ESP32 Wanna hear a joke? Yeah, What? Why did the ESP32 go to the beach? Why? To surf the net! Bruh... So all jokes aside, the communication actually goes pretty quick. Just like that. Now, here's a brief rundown of the code. First, we define the pins for each board. Then we start serial communication for the computer, since we'll be printing to the serial monitor. They will also need to print to each other, so we begin that one too. There's a two second delay to give everything time to fully setup. I then initiated the first line from the Arduino with the println command and the ESP has an If statement, so when the line reaches the ESP through the level shifter, it will say received from Arduino. And then the ESP will spit back another line and they will just keep talking. You may have heard of communication protocols such as UART, I2C and SPI. Different devices require you to talk to it in the specific protocol. For UART, The Uno has one port, while the ESP32 has 3. For I2C and SPI, Uno has one dedicated port each while ESP32 is a little more complex. Many GPIO pins can be software configured for SPI or I2C. Now onto Wi-Fi and Bluetooth capabilities, the stuff that really sets the ESP32 apart! The ESP32 can operate in three Wi-Fi modes: Station, Access Point and Dual Mode. In Station Mode, the ESP32 connects to an existing Wi-Fi network, just like a smartphone or a laptop. This mode enables the ESP32 to access Internet services, download data and interact with web based APIs. This gives you the ability to build weather displays and even integrate GPT abilities into your projects. In Access Point Mode, The ESP creates its own wireless network that other devices can discover and connect to. You can also create a web server so that devices can send information to your ESP. Here I created a network that I connected to with my phone and by using a web browser, I can access this web server and send information wirelessly. Lastly, there's Dual Mode where it can simultaneously connect to an existing Wi-Fi network and also act as an access point. This means it can maintain Internet access while providing a direct connection for other devices. So if we had data received from local devices, in Access Point Mode, you then forward this to a server on the internet in Station Mode or vice versa. ESP also supports Bluetooth connectivity. Just like how you can pair your headphones to your phone, you can pair your ESP32 with any other devices to transmit information to each other. I'm using an app called “Dabble” and this lets me send information from my phone to the ESP. In addition to Wi-Fi and Bluetooth, the ESP has another communication feature, the ESP-NOW protocol. It's a unique protocol developed by Espressif, which basically allows two ESPs to communicate. This protocol operates on the Wi-Fi band, meaning it's the same radio frequency as Wi-Fi, but doesn't need a router or Access Point. It's like Bluetooth in terms of efficiency and low power usage, but as a greater range and faster data transfer. So it sits between Wi-Fi and Bluetooth. So yeah, that's just a quick briefer on the differences, features, what board to get and how to use it. If you're looking for a high performance microcontroller with some wireless perks, the ESP32 is a pretty good next step from standard Arduinos. If you want to get started with ESP32, there's a link down below and that's pretty much all the basics. Have fun!
Info
Channel: Robonyx
Views: 217,149
Rating: undefined out of 5
Keywords: ESP, ESP32
Id: RiYnucfy_rs
Channel Id: undefined
Length: 9min 26sec (566 seconds)
Published: Tue Mar 12 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.