Introduction: Introduction to ESP8266
Today, we will talk a little about the ESP8266, Espressif system microcontroller, which has WiFi capability. This chip was launched in 2014, like the ESP01, and allows for a connection to a wireless network through a set of commands.
Step 1:
I can say that for those of us in the world of electronics, the emergence of the ESP8266 was a revolution. Initially, it was designed to be used on tablets and cell phones, and became wildly popular after Espressif created firmware and made our lives easier.
Step 2: Main Features
Chip with built-in WiFi: 802.11 B / G / N standard
Approximate range: 90 meters
Operating voltage: 3.3 VDC
CPU that operates in 80MHz, with a possibility to operate in 160MHz;
32-bit RISC architecture;
32KBytes of RAM for instructions;
96KB of RAM for data;
64KBytes of ROM for boot;
It has a Winbond W25Q40BVNIG SPI Flash memory from 512KBytes to 4 Mb * (support up to 16 Mb)
The core is non-IP based Diamond Standard LX3 from Tensilica;
Modes of operation: Client, Access point, Client + Access point
Step 3: Types of ESP8266
I already bought all these models, but this is the cheapest, and it's NodeMCU, because it has USB input. The processor of all these microcontrollers is the same, but what changes is the quantity of pins.
Step 4: WiFi ESP8266 NodeMCU ESP12E
As I mentioned above, I really like NodeMCU, because it has USB input, that is, you get the software via USB. That means it's a lot like the Arduino, but an Arduino with WiFi.
This NodeMCU even has a voltage regulator, which is low speed, from 5 volts from USB to 3.3 - and already powered. Here, the images show the layout of the ESP12E, which is quite similar to the Arduino. It is important to remember, however, that the ESP12E has 32 bits, which means much more power than the Arduino Uno and even the Mega.
Step 5: ESP8266 As Serial Bridge Wifi
Here, the ESP8266 is used as if it were a WiFi card only. It picks up data from the Arduino series and transmits it to a given IP. It's as if the ESP is an Arduino communication board.
Step 6: ESP8266 Without Arduino
Another way is to use the ESP as if it were the Arduino itself. This is the way I use it most of the time, and our next videos and assemblies should include using the ESP as a single microcontroller.
Step 7: How to Use ESP8266:
Another way is to use the ESP as if it were the
Arduino itself. This is the way I use it most of the time, and our next videos and assemblies should include using the ESP as a single microcontroller.
How to use ESP8266:
- AT commands (similar to a modem)
- Moon Script with NodeMCU firmware
- MicroPython
- Arduino IDE (C ++)
- Native SDK Espressif C / C ++
We have several ways to program the ESP8266. If you are going to use this feature as a serial bridge, the most appropriate is the AT Command, much like modem commands. Another way to program ESP is by using the Lua Script language that even comes in the NodeMCU firmware. However, I believe that less than 1% of users use this language, since 99% opt for the C language, diffused by Arduino, the most-used microcontroller in the world, we can say. So, in my opinion, the smartest thing the community did was to port the language of the Arduino to the ESP, despite the gigantic amount of Arduino Lib that serves for the ESP.
The third way to program an ESP is by MicroPython which, for me, was not well accepted. Concerning this, my viewpoint is the same as my opinion about the language Lua Script: it is not standard.
I should tell you that in the electronics world, when a company launches a chip, the first thing it does is configure the GCC to compile this new device, that is, the company adjusts the set of instructions from the microcontroller to the GCC compiler. All this is for the adaptation to the C language, which, as I said, is the most used language in the world of chip programming.
We also have the native SDK of Espressif, which, as with most languages, is used in specific cases when it is not possible to use Arduino's C language.
The most prominent in terms of language, therefore, is the Arduino IDE, undoubtedly the easiest and most used so far.
Step 8: Blink
Now I'm going to show you a simple program that flashes a led. Below we have the scheme, where an ESP01 with the GPIO is connected to a led and a resistor.
Step 9: ESP8266 in the Arduino IDE
You can use the Arduino IDE to program to the ESP8266. For this, you should have the IDE in version 1.6.4 or higher. Now go to the preferences and in "Additional Board Manager URLs", add the url:
http://arduino.esp8266.com/stable/package_esp8266com_index.json
Then go to Tools>Boards>Boards Manager...
In the search, type ESP8266 and install the package "ESP8266 by ESP8266 Community"
Now you can select your ESP8266 from the list of cards
Step 10: Code
The first thing to do is declare a constant that will tell us which pin is our led. It is important to use constants, because if we change the pin, we are changing the value in just one place, because all other places in our code will be just referencing our constant, and without any necessity to change anything else.
//A constant with the value of the gpio that we are going to use, gpio2 in this case #define LED 2
Step 11: Configuração
Setup is the startup function of our program.
It runs only once at the beginning of the program, before the main loop. This is the function we will use for configurations that are only needed once, such as the way we will use the pin. In our case, as we want to freely control the output signal of the pin that is led, we will use the OUTPUT mode.
//Function with the initialization code that will be executed only one time on the program start up, before the main loop execution void setup() { //Instruction to put the gpio that we are using into output mode, so we can change it's value to HIGH or LOW pinMode(LED, OUTPUT); }
Step 12: Loop
The loop function will run without stopping while the program is running. When the last statement is executed, the program returns to the first statement and continues to the next, and so on.
The digitalWrite function allows you to control the selected pin so that it has the HIGH or LOW values, respectively, to turn the LED on or off.
Still in the loop, we have the delay function that interrupts the execution of the program by milliseconds. The logic of our loop is to light the led (with HIGH signal), wait 1 second (1000ms), turn off the led (with LOW signal), wait a second again, and repeat everything again while the program is running.
//This function will be executed continuously, starting from the first instruction in sequence until the last one<br>//and then back to first instruction again and repeating until the program stops void loop() { //Changes the signal of the chosen gpio, so it's value is now HIGH and the LED is lit digitalWrite(LED, HIGH); //Waiting 1000 miliseconds, that is 1 second, before executing the next command delay(1000); //Changes the signal of the chosen gpio, so it's value is now LOW and the LED is off digitalWrite(LED, LOW); //Waiting 1000 miliseconds, that is 1 second, before executing the next command. //After finishing the last command of the loop the program will return to the first instruction of the loop //and execute again all of the instructions within the loop in sequence until the program stops delay(1000); }
Step 13: Files
Download all my files in: www.fernandok.com