-->
Page 1 of 1

Using Arduino Leonardo as a programmer not working.

PostPosted: Tue Jan 19, 2016 12:32 pm
by primateio
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() {
  Serial.begin(baud);
  Serial1.begin(baud);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
}

void loop() {
  if (Serial.baud() != baud) {
    baud = Serial.baud();
    Serial1.begin(baud);
  }
  if (Serial1.available()) {
    Serial.write(Serial1.read());
  }
  if (Serial.available()) {
    Serial1.write(Serial.read());
  }
}


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

Re: Using Arduino Leonardo as a programmer not working.

PostPosted: Wed Jan 10, 2018 12:24 pm
by Frederico C Wilhelms
Was any update here from the time of the post? Did you find the problem?

Re: Using Arduino Leonardo as a programmer not working.

PostPosted: Thu Jan 11, 2018 9:01 pm
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.

Re: Using Arduino Leonardo as a programmer not working.

PostPosted: Sun Jan 21, 2018 5:23 pm
by Ribeiro Santos
Same problem! :( It seems to be a buffer problem but until now I haven't found the solution...