Add wifi capabilities to Arduino Mega 2560 for OTA software updates?

Hello, my question is basically as the title describes. I have a project fully built that uses a Mega 2560 board, and since the hardware and case for the project are finished I want to avoid switching to a completely different microcontroller if I can, but I am wondering if it’s possible to add wifi capabilities to the board and set it up so that I can upload sketches wirelessly to the Arduino Mega? Or maybe Bluetooth would be easier? Any tips on wirelessly uploading code to my Arduino Mega would be much appreciated!

I should mention that I am not totally against using a different microcontroller, but it’s gotta be compatible with my project and I don’t think most would be. I’ve looked into boards like the Arduino YÚN REV 2 and the Arduino UNO REV 2 WIFI, except the reason why I went with the MEGA over the UNO in the first place is because I needed extra digital headers as I am using a TFT LCD shield that uses up all headers on an UNO plus I also need to connect relays and things, hence the extra output pins of the MEGA. If they simply made a WIFI-enabled MEGA that would be perfect for me! But it doesn’t seem that they do. How should I approach this?

A possible solution is to use a separate WiFi Arduino like the Arduino Nano 33 IoT.

https://store.arduino.cc/arduino-nano-33-iot

You keep your current Arduino just like it is and the new Arduinos handles the communication and reprogramming. This keeps everything simple.

1 Like

Thanks for the idea, I will look into that! How easy would it be to get the nano to reprogram the MEGA with a new sketch sent to it over Wifi? Do you know of any tutorials or documentation that could help me with this?

You may want to consider using a board with WiFi already on board like the Wemos D1 Mini plus a port expander like the MCP23017.

1 Like

I found this page and it describes how you would program an Arduino from a program on a PC. It could be slightly out of date, but I think it will tell you the basics and shows you the source code with good description.

Whether the program runs on a PC or another hardware is not important because at the end the bootloader expects bytes over serial and sends bytes back. Some parts of the code can likely be ignored because you know what device you have connected.

Understanding this could help you find information about how to do this from another Arduino.

https://www.diericx.net/post/upload-hex-file-from-csharp/

1 Like

you can do OTA or OTE to Mega with my ArduinoOTA library

2 Likes

I could, and I have looked into simply getting an Arduino UNO Rev 2 Wifi, but the problem with that is I need the same amount of I/O as an Arduino MEGA. I am using this Elegoo TFT LCD shield that utilizes EVERY pin on an Arduino UNO, so I need the extra pins of the mega to connect other devices such as a relay.

Alternatively, I have found this Wifi-enabled Arduino MEGA when doing some research. I know it is obviously not an official board, but has anyone had experience with it/do you think this would work well? Could I do OTA software updates with this board?

Awesome, thanks for pointing me to that! What hardware would I need to add to my MEGA for this to work though? Is there some sort of wifi chip I need to wire up to it? Because I understand that the MEGA is not WIFI-enabled out of the box. I’ve seen that there are MANY options for wireless chips, shields, etc. out there, is there 1-2 you highly recommend that would work well with your library?

This seems useful, I will read through it when I get the chance.

@Klaus_K , Nano 33 IoT is SAMD21 + ESP32. two MCUs. do you thing it is optimal to add it as WiFi to Mega?

OTA is still not supported on Uno WiFi Rev 2. it is an ATmega4809 + Esp32. ATmega4809 is very very different from ATmega2560.

Mega+WiFi is perfect. But the same way you can add esp8266 module to your Mega. Either way be prepared for first learning the esp8266.

Best Arduino WiFi is the WiFi101 shield with WiFi101 library. Arduino doesn’t sell it anymore, but Adafruit has a clone named WINC1500 WiFi Shield

1 Like

Thank you for your reply, I looked at the WINC1500 WiFi Shield you mentioned and it seems like this could maybe be my solution! It seems very easy to get WiFi working with this shield.

I just have 2 questions to determine whether this is what I need or not:

1.) Can I get OTA updates to work with this WiFi shield?
2.) Is it possible to stack another shield on top of the WiFi shield? Because I am using a TFT LCD shield but maybe I could stack it on top of the WiFi one?

Thanks for all your help!

EDIT: I think these answer my question #2: Shield stacking headers for Arduino (R3 Compatible) : ID 85 : $1.95 : Adafruit Industries, Unique & fun DIY electronics and kits I just wonder if the touchscreen will still work like normal when it is stacked on top of the WiFi shield

Yes, the user does not need to worry about the fact how many MCU there are. The ESP32 is hidden in the WiFi module. Some sketches check the firmware version and tell users they need to update, but that is mostly not necessary.

From the application point of view, you program the SAMD21. The WiFININA library is easy to use and when you compile the example sketches for WiFi they use less than 10% of the SAMD21 Flash and RAM because most of the code is inside the module. This leaves plenty of room to write a sketch that will program the Mega.

When you just add a WiFi module to the MEGA, it will need to handle the extra software. Additionally, you would need to do self-updating OTA. The MEGA would need to store a complete binary image somewhere, erase its flash memory and reprogram it. When something goes wrong the device is dead. With my solution the SAMD21 could program the MEGA on the fly. It could store parts of the new MEGA binary in RAM program it and then get the next part. Even if the system crashes because somebody unplugs power the SAMD21 boots and continuous the process.

the ArduinoOTA library supports WiFi101 as you could read in the link in my first comment.

the WiFi shield uses the ICSP header for SPI and three more pins

there could be two problems with the combination of shields:

  1. both use the SPI bus. it should work OK but a conflict is possible if the TFT library doesn’t use SPI transactions and requires a different SPI settings than the WiFi shield
  2. the TFT shield will shadow the WiFi antenna so it will have a lower range. they have a version of the shield for external antenna if you need a good WiFi range.

(esp8266 module would use only two pins RXn/TXn)

1 Like

@Klaus_K, what you describe is possible with esp8266 only. no need for two MCU. see ESPLink firmware.

(but the self update works without problems too)

Hm, okay. So I guess my choices are either A) Get the WiFi101 shield and hope it works in combination with the TFT LCD shield or B) Add an ESP8266 module to the mega (or buy the mega with ESP8266 already built-in that is linked here) and figure out how to get that to work. I like the idea of how simple the WiFi shield is so I’ll probably do some more research on that to see if it would work in combination with the TFT shield I’m using.

1 Like

And here am i, looking for what i described, and why i thought it needed 2 MCU’s
But you replied to Klaus. But yeah it is possible to update a Mega OTA using an ESP-01 (or something bigger) isn’t it ? I’ve never done it, but have seen it come through somewhere before.

No problem, happens to me as well.

what is the physical distance between the sender and receiver? There are some wireless serial tranceiver devices that do transparent serial.
best regards Stefan

1 Like