📜 ⬆️ ⬇️

Arduino + ESP8266 from scratch on the example of a Wi-Fi thermometer, part one

Part 1. Preparing ESP8266

Why this article? On Habré there are already a number of articles on the use of ESP in different configurations, but for some reason without any details about exactly how everything is connected, stitched and programmed. Like "I took ESP, two finger-type batteries, DHT22, threw it in a box, shook the hour and the thermometer is ready!". In the end, it turns out strange: those who are already working with ESP do not see anything unusual in the work done, and those who want to learn do not understand where to start. Therefore, I decided to write a detailed article on how ESP is connected and stitched, how to connect it with the Arduino and the outside world and what problems I came across on this way. Links to Aliexpress cite only to represent the order of prices and the appearance of the components.

So, I had two microcontrollers, seven different sensors, five power supplies, a DHT22 temperature sensor and a whole lot of wiring of all sorts and colors, as well as countless resistances, capacitors and diodes. It is not that all this was necessary for the thermometer, but if I started studying microelectronics, it becomes difficult to stop.
')


Nutrition

To operate the ESP8266, you need a voltage of 3.3V and a current not lower than 300mA. Unfortunately, the Arduino Uno is not able to provide such a current as the USB-UART adapters (programmers) of the type FT232RL are not able to provide it either - their limit is about 50mA. So you have to organize a separate meal. And it would be better if Arduino also worked from 3.3V to avoid problems like “I gave a five-volt signal to the output of the RSP module ESP, why does it smell like burning plastic?”.

There are three solutions.

1. Buy a ready - made power supply for 3.3V.

2. Buy a ready-made module with a voltage regulator, reducing 5V to 3.3V. Perhaps this is the most convenient option.

3. Assemble the module itself from the AMS1117 regulator and one 22mkF tantalum capacitor.

I chose the third item, because I often need 3.3V, I am greedy and I like to build in regulators directly in power supplies.

With AMS1117, everything is simple: if you put it text up, then the voltage on the legs grows from left to right: 0 (Gnd), 3.3V (Vout), 5V (Vin).
Between zero and output you need a 22mkF tantalum capacitor ( according to the instructions , what happens if you put the electrolytic one - I did not check). In tantalum SMD-capacitor plus where the strip. A bit of monstrous soldering of SMD components not intended for such barbarism and:

image



Be sure to check the output voltage. If it is significantly less than 3.3V (for example, 1.17V) - let the regulator cool down after soldering and check the contacts. If you set the capacitor to more than 22µF, then the multimeter may show a higher voltage.

Why choose AMS1117? It is widely used. You can find it almost everywhere, even in the Arduino Uno, as a rule, it costs AMS1117-5.0.
If you know something of similar size and price, even easier to use - please write.

An important point. I do not know why, but AMS1117 is extremely capricious about the quality of connections. Contacts must be reliable. Better - soldered. Otherwise, it produces 3.3V on tests, but it does not produce anything under load.

ESP8266 Connection

I chose model 07 because it has an excellent metal screen that acts as a protection against interference, mechanical effects and as a radiator. The latter provides the difference between a burned-out module and just getting hot. In addition, there is a jack for an external antenna.

To start the chip you need to connect VCC and CH_P through a 10kΩ resistor. If this is not the case, then any one from the range of 1-20 kOhm will do. In addition, specifically, model 07 still requires that GPIO15 (closest to GND) be “on the ground” (this is not visible in the picture, because the connection is from the other side).



Now we take the USB-UART adapter, switch it to 3.3V and connect the RX to TX, TX to RX and GND to “ground” (my transmission is unstable without this). If you cannot switch to 3.3V, then you can use the simplest resistor voltage divider: connect the ESP RX to the TX adapter via a 1 kΩ resistor, and ESP RX to the ground via 2 kΩ. There are many more complex and more reliable ways to tie 3.3V and 5V, but in this case it will come down.



And we connect at the speed of 9600 on the desired COM port (you can see it in the device manager).


I use SecureCRT, Putty is also suitable, and Linux lovers already know what to do and where to look.


(AT + RST reloads the chip)

If nothing happens - turn off - turn on the power, if nothing happens anyway - check the TX / RX compliance, try to rearrange them or solder them to the chip.

Sometimes the chip freezes during the bullying experiments and then it must be de-energized, including turning off the adapter (for example, pulling it out of USB), because the chip even has enough incoming crumbs of power to stubbornly and not work.

Sometimes tricks with an adapter hang a USB port. It is possible to use another USB port as a temporary solution, but in general it is better to reboot the computer.

Sometimes this changes the number of the COM port. Under Linux, this can be solved with udev.

If garbage comes instead of text, then check the speed settings. Some older chips work on 115200.

At the start, the chip heats up, but if it is really hot and continues to heat up, disconnect and check all connections. So that the case does not fall + 3.3V, so that 5V does not come to it at all, so that the "earth" of the adapter is connected to the "earth" of the chip. Models with a metal screen are very difficult to burn (but nothing is impossible), and they complain about models without screens, saying that even a small mistake may be the last in the life of the chip. But I did not check it.

Firmware

My choice is NodeMCU . She has problems with memory and iron support, but it pays off many times by the simplicity of the code and the ease of debugging.

NodeMCU flasher and LuaLoader will also be required (the latter is optional, there are other clients to work with this firmware).


Turn off the chip. Connect GPIO0 to the ground and turn on the chip:



If nothing happens and the MAC / STA MAC AP fields are empty - check again that GPIO0 is on the “ground”.
If the firmware started, but hung up - look at the Log tab, for some reason, I specifically refused to flash this chip on the FT232RL, but it didn’t flush to PL2303HX at the speed of 576000 without any problems. You need to open the plastic case and solder the wire from 5V to 3.3V, there are options with five outputs : 3.3, 5, TX, RX, Gnd.


Please note: STA MAC has changed. I suspect that the flasher showed it incorrectly, but check is required.

To save strength and nerves, you can take ready or semi-finished version.

There are disposable adapters with convenient wiring.
There are ready for firmware .
There are options with simple whale kits and more complicated - ESP8266-EVB
There is a ready USB-adapter - NodeMCU Development Board . Under it, even some shildy do.

If you, like me, do not like ready-made solutions too much, I recommend taking it all with a margin, because experience, as they say, is directly proportional to the number of burned components.

Valuable links from comments:
NodeMCU custom builds
Programming ESP8266-EVB with Arduino IDE
Explanation of tantalum capacitor.

Update: replaced in the text “programmer” with “USB-UART adapter” or just “adapter”. In my experience, the term "programmer" is used more often, but perhaps the "USB-UART adapter" will be more accurate.

Source: https://habr.com/ru/post/259925/


All Articles