Connection UNO with ESP01

I am trying to connect Arduino UNO with ESP01. There are many tutorials available but with many inconsistencies too.
What is the correct wiring between Uno and ESP01? Description vary. My understanding is
UNO ESP01
TX (pin 1) RX (pin 4)
RX (pin 0) TX (pin 5)

But there are diferent descriptions available.
When connected as described nothing hapens. No AT commands work. When connected TX to TX there is a response in serial monitor after resetting ESP, just the time, arrow and a number of strange characters.
When uploading a Blink example, the following message appears:

a fatal esptool.py error occurred: failed to connect to esp8266: timed out waiting for packet header

Regardless how the RST and other pins are treated.
Serial monitor is turned off during the upload.


See also the picture, where the pin0 RX looks like an output.

Don't. Just don't.

Pins 0 and 1 are not available to use on Uno. They are needed for uploading your sketch and using Serial Monitor.

If you must use Uno, choose 2 other pins and use Software Serial.

A much better and much easier solution is to use an Arduino compatible board based on ESP8266. I recommend Wemos D1 mini.

You didn't address the issue - pins, wiring and programming the 8266 module via UNO. There were many discussions on this but without any useful outcome.

because there are so many faster, easier and better solutions than to connect an UNO with an ESP.

If you have a sketch which needs WLAN, just get an ESP8266 Board like a NodeMCU or a Wemos D1, program the ESP and omit the UNO.
Program ONE microcontroller ... the ESP.
If you run out of ports on the NodeMCU/Wemos D1 consider an ESP32 Board or use I2C port expanders.

OK, I just want to upload some code to the module as displayed on the picture right now. Nothing else. Let start with blink example, consisting of ca 3 lines. Forget anything else.

Did you draw that? What is the purpose of the 1K and 2K2 resistors on the Uno Rx pin? Is that the correct Uno pin to connect them to?

In order to upload code to an ESP-01, you must put it into upload mode. Connect 10K pull-ups between the RESET and GPIO0 and 3.3V. Connect pushbuttons between those pins and ground. When you click the button connected to RESET, you should see 2 very brief flashes of the tiny blue led. This indicates that the ESP is in normal mode. Now, hold down the button connected to GPIO0 and click the RESET button, then release the other button. You should see only 1 flash. This indicates the ESP is in upload mode. Now you can hit Upload on the IDE. When the upload has completed, click the RESET button and the uploaded code should start to run.

I didn't draw the picture and I am wondering about the correctness. as mentioned before.

for programming/running ESP-01 I find the ESP-01 Helper V3 useful - no switching wires etc and a clone connector to attach sensors etc

or better drop the UNO and like @noiasca suggested get ESP8266 NodeMCU or ESP32

That's exactly I was doing before and the following message arrived:

A fatal esptool.py error occurred: Failed to connect to ESP8266: Timed out waiting for packet header

BTW I do not use such resistors but bidirectional logic level 5V/3.3V converter.

Ok. It couldn't be more wrong. The purpose of the 1K+2.2K voltage divider is to reduce the 5V from the Uno's Tx pin down to 3.3V so that it does not damage the ESP's Rx pin. Unfortunately, the resistors are connected between the ESP's Tx pin and the Uno's Rx pin, reducing the 3.3V from the ESP's Tx pin down to 2.3V, which isn't enough for the data to be read by the Uno's Rx pin. And, of course, does nothing to protect the ESP from the damaging 5V signal from the Uno's Tx pin.

EDIT: sorry, it can be more wrong, and it is! The two Rx pins are connected together, which is harmless but useless, and the two Tx pins are connected together, which will cause a damaging short-circuit.

But it does not matter anyway. We found out in post #10, "By The Way", that you are not even using that circuit. You are using bi-directional logic level shifters on signals that are not even bi-directional.

If you are serious about wanting help, 'fess up to any other By-The-Ways in your next post. And post a schematic accurately showing us your circuit.

Actually, I suggested that first. But it's irrelevant anyway. @draggon is connecting the Uno's reset pin to ground, keeping the atmega328 suspended. The Uno is only being used as a USB-serial converter.

EDIT: ...only that diagram is now discredited, we don't know if the atmega328 is suspended.

Attached ny actual wiring
Capt-2

It depends on what you attempt to do.

The reason there are so many bad tutorials on the matter is unknown, but i agree there are. An the good ones get removed somehow. I should really create one here on the forum, that would save a lot of work.

To get a handle on what you want to do i suggest you first try to communicate directly to the ESP thru the UNO's USB to TTL converter.

For that you need to make sure the Serial port of the UNO is not in use itself.

You can simply upload a blank sketch onto it or blink or basically any sketch as long as it does not use Serial or GPIO 0 & 1, or alternately you can put the UNO in constant reset (not what i do)
i upload this little sketch

const byte ledpin=13;
uint16_t ms=100;
bool increase=true;


void setup() {
  // initialize digital pin 13 as an output.
  pinMode(ledpin, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(ledpin, HIGH);   
  delay(ms);            
  digitalWrite(ledpin, LOW);    
  delay(ms); 
  if (ms>250) increase=false;
  if (ms<20) increase=true;
  if (increase) ms=(ms*10)/9;
  else ms=(ms*9)/10;           
}

After this you need to make the connections such that the ESP's MCU replaces the MCU on the UNO.
For that you connect the TX to TX & RX to RX, but due to the logic level differences the ESP's RX pin needs to be protected. Using a converter works, though again i never use one. I use 3x 1k resistors to create a voltage divider which belongs to the ESP's RX-line. the schematic with the 2.2K & 1K works, but leaves you with a higher logic level (5 /3.2) * 2.2 = 3.4375 and 3x 1K end up at 3.33v Ideally it should be even less. Resistors with higher values like 3x 10K will get you the proper voltage as well but will add more capacitance to the circuit, and will probably not work at higher baud rates.

The reason you connect TX to TX & RX to RX is because the USB to TTL converter on the UNO (an Atmega 16u2 if it's an original) connects it's TX to the RX of the UNO's MCU (the Atmega 328P) and it's RX to the 328P's TX. The markings on the UNO refer to the pins on the 328P.

Make sure that at the time of boot, GPIOs 0, 1 & 2 are not pulled LOW or the ESP will go into the incorrect boot mode.

Set the Serial monitor Baud rate to 115200 and line-ending to both NL & CR
Now type 'AT' and you should get some response.

GPIO 0 is used to set the boot mode to 'flash-mode'. If pulled LOW at boot, the ESP will go into the mode that allows it to be programmed,
The connections for 'direct AT-commands' & 'programming the ESP-01' are the same with that exception.

Now if you would like to just upload a sketch onto the UNO that then makes use of the original AT-command firmware that is on the ESP, you need to change the RX & TX lines over (make sure you keep protecting the ESP's RX line !) and connect them crossed TX to RX & RX to TX.
But of course you would normally want to still use the Serial port of the UNO to tell that what to do (and for debugging) so a software Serial solution usually is better.

Unfortunately swSerial is not reliable at 115200 (for reception) which is the default baud-rate of the ESP, so you should tell the ESP to switch to 9600bps first up and then continue from there.

Now i don't really support this whole UNO + ESP-01 AT-commands thing, so i will not dive into it. The ESP-01 has a way more powerful processor, and to use it in that way is just to inefficient.

I suggest you program the ESP-01 directly, this will erase the AT-command firmware, which gets overwritten by your own, it can be re-uploaded afterwards, but seriously why bother ?! You can make much more efficient use of the ESP-01 if you program it directly.

Now to do this you connect GPIO 0 to GND and reset the ESP-01 to put it in 'flash' mode and afterwards you can remove that connection (i have a small shield with 2 buttons, 1 grounds out GPIO 0 and 1 grounds out RST, the shield also has the resistors of the voltage divider and connects to the UNO's 3.3 GND and RX & TX pins)
The UNO 3.3v regulator should be able to provide the current required for the ESP if it's an original UNO (like mine) but clones tend to not have enough heatsink, which will show up when trying to connect WiFi which is the moment of peak current requirement.

Now download the ESP8266 core, select 'generic ESP8266' and with the default settings, upload this sketch

const byte ledpin=1;
uint16_t ms=100;
bool increase=true;


void setup() {
  pinMode(ledpin, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(ledpin, HIGH);   
  delay(ms);            
  digitalWrite(ledpin, LOW);    
  delay(ms); 
  if (ms>250) increase=false;
  if (ms<20) increase=true;
  if (increase) ms=(ms*10)/9;
  else ms=(ms*9)/10;           
}

The ESP-01 has a builtin LED on GPIO 1 (TX) which is active LOW
After upload the sketch will start running regardless of GPIO 0 being connected to GND or not, but if you reset it you will have to decide what boot mode you want.

@draggon Thanks for the diagram.

Ah, stupid me! Completely forgot about that.

@draggon apologies for my earlier errors and criticism about connecting Rx to Rx and Tx to Tx.

I would suggest to try removing the level converter. Tx from ESP to Tx of Uno can be directly connected. Rx from Uno should be connected to Rx of ESP via 10K & 22K voltage divider (10K from Uno Rx to ESP Rx and 22K from Uno Rx to ground).

You have disregarded my comment about higher value resistors

I am serious though, at the default upload speed this can already cause issues, and with these first experiments we don't want 'any possible issues'

Actually it seems you disregarded that whole paragraph

No need to take offence.

The default upload speed in the IDE for generic ESP8266 devices is 115,200 baud. As long as the wires are not long, I think either 10K&22K or 1K&2K2 or 3x1K will be fine. And I think 0.1V higher than the ideal input voltage will be within safe tolerances, certainly better than 5V, anyway!

I do agree, it is just that i have had issues with 3x 10K myself as well as others who have come for assistance.
If you use metal film resistors 3X 10K (or 10K & 22K) will nearly always work, but with carbon film issues may arise.
As i said before, there isn't anything wrong with 3x 1K although it requires more current than 3x 10k.
I will stick with recommending 3x 1K simply because it is better than the other options.

Very helpful, especially the baud rate 115200, now I receive response after resetting the ESP:

17:06:26.579 -> ;ld��|�$�| � d�c|ǃ�e�{�c� b��og�l'o��� #x��l;l{lp�n� � d  cg�|ll��c��'o�$��l�eng$'{���g ��l x�o� {�����  #g�|�Ǐc��gn�l�eogl an;���g �lx�o� ;������l # '�|d�s�c��'o� d�e'o$'{���o�dl s��' �ld;l��o���'o�ğ�;og'� $�b;{l ��l�eۓ�  � �lldrd�e�d$d'��  � ؄���l��g��'�n?e��dd��# l$xc�cs���l gd�p��dcll��o�n���gd�|c $  d;l����o�r��g|� ��|sd��r�$�d� l��s�l�le�  l��;�d ��� d$sdǃr$���#$�#;| �cp`�l�#$r�lc��'�ng� �$�pl � d�DŽ � ��l�d�g����bl�x ���cl�cpsd;l

17:06:26.840 -> Ai-Thinker Technology Co. Ltd.

17:06:26.840 ->

17:06:26.840 -> ready

Nevertheless the direct upload results into:

Did you put it into flash mode by connecting GPIO 0 to GND and hard reset the unit ?

17:06:26.579 -> ;ld��|�$�| � d�c|ǃ�e�{�c� b��og�l'o��� #x��l;l{lp�n� � d  cg�|ll��c��'o�$��l�eng$'{���g ��l x�o� {�����  #g�|

That is the boot message it comes out at 78840bps