upload by OTA does not work on Wemos board ATmega2560+ESP8266+32Mb+USB-TTL CH340

Hello everybody,

I bought a chinese board Wemos® Mega +WiFi R3 Module ATmega2560+ESP8266 32Mb Memory USB-TTL CH340G. After installing WiFi Link firmware and WiFi Link Library with serial3 connection between Mega2560 and ESP8266, i can interact with ESP administration webpages at Myipnetwork : 80 and i can interact with webserver running inside Mega2560 at Myipnetwork : 81, all in WiFi. I can also upload a new firmware into ESP by OTA using python and Espota.py. So, all that is ok.
But i can’t upload a new sketch into Atmega2560 by OTA. Strangely, IDE runs arduinoota.exe and not arduino_mcuota.exe as i expected. WindowsXP Pack3 and IDE 1.8.5 in “portable” version are running in my PC. In my hardware configuration, GPIO4 is wired to control Mega reset pin.

  1. Running the upload by IDE. The IDE console displays :
    C:\Program Files\Arduino\portable\packages\arduino\tools\arduinoOTA\1.1.1\bin\arduinoOTA
    -address 192.168.1.15 -port (upload.network.port)
    -sketch c:\docume~1\locals~1\temp\arduino_build_291171/wifiwebserver.ino.hex
    -upload(upload.network.endpoint_upload)
    -sync(upload.network.endpoint_sync)
    -reset(upload.network.endpoint_reset)
    -sync_exp(upload.network.sync_return)
    Resetting the board
    Failed to reset the board, upload failed

  2. Running the upload by Python 2.7.11 and Arduino_mcuota.py with Windows line command :
    C:\mcuota>python.exe arduino_mcuota.py -f c:\mcuota/test_mega_temp.ino.hex -i 192.168.1.15 -p 80
    Sending c:\mcuota/test_mega_temp.ino.hex to host 192.168.1.15
    ('Connection aborted.', BadStatusLine("''",))

  3. Running the upload by Avrdude 6.3 with Windows line command :
    C:\avrdude>avrdude -v -v -DV -patmega2560 -Pnet:192.168.1.15:23 -c arduino -b115200 -Uflash:w:test_mega_temp.ino.hex:i
    Avrdude : net_open() : Connect failed : target expressly refused

Without knowlegde of the interactions between the different components, without documentations, i hope the community can help me to solve my issues. So thanks for your help. I galley for three months, without finding a solution !!

Daniel

how could you? bootloader of the Mega listens on UART0. but it doesn't matter, because the dfu library in WiFi Link is only for 328p with optiboot

I discover this limitation, incredible for me !

So, my questions are now :

  1. dfu library in wifi link is it used whatever the way of uploading ? IDE, Python, Avrdude ?
  2. is there another version compatible with Mega2560 ?
  3. how can we upload a sketch by OTA into Mega2560 ?
  4. is it possible, easy, to modify the Mega bootloader to make it listen on both UART0 (cable case) and UART3 (wifi case) ?

Thanks for your help.

concerning this chapter "Tool for OTA uploading the Atmega sketch is a python script available in arduino.org GitHub repository. To run it, you need Python 2.7, 3.x doesn't work. With python installed you can package the script as exe. Instructions are in the GitHub repository."

I followed these steps and got the executable arduino_mcuota.exe. Running it (way python + arduino_mcuota), i got an error.

kock:

  1. dfu library in wifi link is it used whatever the way of uploading ? IDE, Python, Avrdude ?
  2. is there another version compatible with Mega2560 ?
  3. how can we upload a sketch by OTA into Mega2560 ?
  4. is it possible, easy, to modify the Mega bootloader to make it listen on both UART0 (cable case) and UART3 (wifi case) ?
  1. mcuota was written by arduino.org for WiFiLink dfu. I made an ArduinoOTA addition to dfu. I think it is int the version in the zip on the link in the README of the firmware.

  2. no

  3. with WiFi Link a SPI connection would work for upload too, but the esp8266 on your board has the SPI pins not accessible. Other option is esp-link firmware, but the networking library is not good.

  4. don't know. then the USB upload would not work

kock:
Running it (way python + arduino_mcuota), i got an error.

did you compile the WiFi Link firmware with the MCU_OTA define?

" 3) with WiFi Link a SPI connection would work for upload too, but the esp8266 on your board has the SPI pins not accessible."

HSPI pins (GPIO12, 13, 14) seem to be unused. I have already made hardware modifications on the board to have a reset controled by GPIO4. I can add a wire connection between ESP HSPI pins and Mega2560 SPI pins.

What about this way to interact by wifi with a webserver running in Mega2560 and upload sketch by OPA ?

My project concerns an full automatic mower. During the first step of my project, i use an Arduino Uno Wifi R3 dev rev. Unfortunately, its ram is too small. I think to use a mega2560 board integrating an ESP8266.

" did you compile the WiFi Link firmware with the MCU_OTA define? " yes, i do.

if you make the SPI connection. there is a better firmware and library then WiFi Link.
use WiFiSpiESP. I added OTA support to it.

I am going to spent two weeks of holidays and I will wire a HSPI link and test solution when i will be back.

Thanks a lot for your help. See you soon for results.
Daniel.

About using GPIO15 for SS in WiFiSpiESP :

In Wemos board, GPIO15 is fixed to ground and you note "If the ESP is booting at the moment when the SPI Master (i.e. Arduino) has the Select line HIGH (deselected), the ESP8266 WILL FAIL to boot!

So that is two reasons not to use GPIO 15. Is it possible to choose a different GPIO ? where is that defined ?

Daniel

kock:
So that is two reasons not to use GPIO 15. Is it possible to choose a different GPIO ? where is that defined ?

no because the esp8266 is slave, so we must use the SS pin.

the best workaround is to reset the esp8266 after the Atmega sketch started.

recommended esp reset · Issue #6 · JiriBilek/WiFiSpi · GitHub (read only OP. the rest of the thread was hijacked)

With my mega 2560 board, i use two shields with SPI. I must use pins like in an UNO board (11,12, 13 and SS).

For the SD card, i set SD.begin(9,11,12,13). In the WiFiSpiESP usage, how can i make the same ?

kock:
With my mega 2560 board, i use two shields with SPI. I must use pins like in an UNO board (11,12, 13 and SS).

For the SD card, i set SD.begin(9,11,12,13). In the WiFiSpiESP usage, how can i make the same ?

I am sure you do not use 11, 12, 13 for SPI on Mega. because on this pins there is no SPI on Mega. same for SD card. you try to connect the esp8266 over SPI? connect to ICSP header

  1. Below is the beginning of my SD sketch running in my Mega2560. You can see that Mega SPI pins is not 50, 51.... in my configuration.

  2. i do not use ICSP connector

  3. SD card is shorter than Mega (pin 50, 51 .. are not physical accessible)

So, Mega SPI pins can be chosen by users ! SDcard library by Spark allows that. I think it is much better to use 11, 12, 13 because ICSP connector is not always available.

I would like the WiFiSpiESP library to do it too. But i don't know how.


#define PIN_LED 13
String inString;

#include <Wire.h>
#include <SPI.h>
#include <SD.h>

const int chipSelect = 9;
unsigned long fin;
int i = 0;

void setup()
{
Serial.begin(115200);
Serial3.begin(115200);
Wire.begin();
pinMode(PIN_LED, OUTPUT);
while (i <10)
{
digitalWrite(PIN_LED, LOW);
delay (1000);
digitalWrite(PIN_LED, HIGH);
delay (300);
}
delay(500);
Serial.println("echange pret");

while (!SD.begin(chipSelect,11,12,13)) // only avaliable with Spark version
{
Serial.println(F("problem with SD card"));
delay (1000);
}
}

void loop()
{
digitalWrite(PIN_LED, HIGH);

File dataFile = SD.open("capture.txt", FILE_WRITE);

use hardware SPI, not 'software' SPI. Mega has SPI pins at 50 to 52

Hello,

After a couple of weeks in vacation, i continued testing OTA upload. I left the previous configuration (Mega 2560 with integrated Wifi) for a new one, more “standard”. So, my testing configuration is now a nodemcu from LOLIN interconnected by hardware SPI with an UNO board. My needs are always, first, uploading nodemcu and UNO sketches by OTA and, next, downloading and uploading datas with my IP network.

By serial, i uploaded WIFISPIESP release 0.1.1 into nodemcu and WIFIWebClient into UNO. UNO is connected to my PC (under WindowsXP) by serial for debugging. That seems to work correctly (access to google.com and download datas). I conclude the SPI link works good. A ping command to “arduino.local” is always OK.

Next step, i wanted to upload a new sketch into nondemcu, by OTA

  • a ping to “arduino.local” is ok (network adress is 192.168.1.1.”
  • i made compilation of WIFISPIESP for device "Nodemcu LOLIN 1.0 (ESP-12E module)"
  • i upload the sketch WIFISPIESP to network address.

IDE terminal says :
Python.exe c:\program files\arduino\portable\packages\esp8266\hardware\esp8266\2.4.1/tools/espota.py -i 192.168.1.1 -p 328 --auth= -f C:\docume~1\daniel~1\locals~1\temp\arduino_build_737834/wifispiesp.ino.bin
“[ERROR] : No Answer.
“[ERROR] : No Answer.
A ping command to “arduino.local” is always OK.

What is wrong ?

Last step, i wanted to upload a new sketch into Arduino Uno by OTA

  • i made compilation of WIFIWebClient for device Arduino Uno
  • i upload the sketch to network adress 192.168.1.1.
  • D2 of nodemcu is connected to Uno reset pin.

IDE terminal says : C:\Program Files\Arduino\portable\packages\arduino\tools\arduinoOTA\1.1.1/bin\arduinoOTA
-address 192.168.1.1 -port (upload.network.port)
-sketch c:\docume~1\locals~1\temp\arduino_build_338927/wifiwebclient.ino.hex
-upload(upload.network.endpoint_upload)
-sync(upload.network.endpoint_sync)
-reset(upload.network.endpoint_reset)
-sync_exp(upload.network.sync_return)
Resetting the board
Failed to reset the board, upload failed

My scope shows that any pulse is generated by nodemcu to reset Uno board.

What is wrong ?

Thanks for you help. Daniel.

WiFiSpiESP in master branch doesn't have OTA support. Use version from the "OTA AVR ISP" branch.

and read the "Optional OTA AVR ISP" chapter in the README in the branch

You gave me these information in July. No answer when i try to upload nodemcu with WIFISPESP. Ping to arduino.local is ok.

An idea ?

kock:
You gave me these information in July. No answer when i try to upload nodemcu with WIFISPESP. Ping to arduino.local is ok.

An idea ?

you try upload from IDE? copy here the console content sorry

you try to upload to esp8266. why? there is the firmware. you want to upload a new version of the firmware?

You would need to add ArduinoOTA to the firmware sketch to OTA upload a new version of the firmware. It is simple. See the examples of the ArduinoOTA library.

i discover your answer before writing my below message ! with it, i understand why the problem doesnt exist with FIRMWAREESP inside nodemcu.

Yes, i want to put all the solution in my mower, close it for a couple of years. Open and close the mower take about two hours, are very risk.

I expect to continue tests after tomorrow.


Below is the tests sequence i made two hours ago.

a) by usb, compilation and download of FIRMWAREESP (part of wifilink) into nodemcu =>OK
b) cable disconnected from my PC and reconnected to an independant 5 volts power supply
c) change port from COM9 to @IP
d) compilation again and download by OTA => result good
e) download by OTA again for 5 or 6 times => always good
f) sketch FIRMWAREESP replaced in IDE by WIFISPIESP release 0.1.1
g) compilation of WIFISPIESP and download to @IP =>OK (download made with FIRMWAREESP running in nodemcu)
h) compilation again and download by OTA => No Answer (WIFISPIESP running in nodemcu)
i) download again 3 times => always No Answer
j) nodemcu disconnected from the power supply and reconnected to my PC by USB
k) change port from @IP to COM9
l) compilation again of WIFISPIESP and download by USB => OK
m) cable disconnected from my PC and reconnected to 5 volts power supply
n) change port from COM9 to @IP (ping to arduino.local is ok)
o) compilation again and download by OTA => No Answer systematically

After the compilation phase, same 3 lines are displayed by IDE terminal :

Line 1 :Python.exe c:\program files\arduino\portable\packages\esp8266\hardware\esp8266\2.4.1/tools/espota.py -i 192.168.1.1 -p 328 --auth= -f C:\docume~1\daniel~1\locals~1\temp\arduino_build_737834/wifispiesp.ino.bin

Line 2 : 22:20:45 [ERROR] : No Answer.

Line 3 : 22:20:45 [ERROR] : No Answer.

kock:
Yes, i want to put all the solution in my mower, close it for a couple of years. Open and close the mower take about two hours, are very risk.

I would recommend to lead out the USB of both boards.