Chat here is you are connecting ESP-xx type modules to existing AVR based Arduino

Moderator: igrr

User avatar
By primateio
#39246 I have been trying to use an arduino leonardo to program an ESP8266 module (ESP-12 to be precise). I cannot get it to work and I am not sure why. Here is the basic code I am using on the Leonardo. I have a more advanced code for the reset function, but I cannot get the serial to work so this is the simplified version.

Code: Select allunsigned long int baud = 115200;
void setup() {
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only

void loop() {
  if (Serial.baud() != baud) {
    baud = Serial.baud();
  if (Serial1.available()) {
  if (Serial.available()) {

I am resetting and putting the ESP module into program mode externally. I have tested with a normal USB to UART converter and it all works fine, but when I try with the Leonardo, it fails. Am I missing something? Below is the error code I get when I try.

Code: Select alltrying to connect
   flush start
   setting serial port timeouts to 1 ms
   setting serial port timeouts to 1000 ms
   flush complete
   espcomm_send_command: sending command header
   espcomm_send_command: sending command payload
   read 0, requested 1
warning: espcomm_sync failed
error: espcomm_open failed
User avatar
By primateio
Frederico C Wilhelms wrote:Was any update here from the time of the post? Did you find the problem?

This was 2 years ago so my memory is a little fuzzy on the details, but I was not able to get it to work. If I remember correctly, it had something to do with the USB virtual serial sending the packets full speed and storing in a buffer until full and then sending the packets out at the proper baud rate. But once the buffer was empty, there was a pause until it was filled again. This pause messed up the programming of the esp8266. But thinking about it now, it might be something else.

It should be possible though as I tried to tie in the USB to serial converter from an Arduino board, which uses a programmed chip similar to that on the Leonardo, and it worked as expected. The code for this is open sourced so it could theoretically be ported over, but I was not able to make it work despite my efforts at the time.