Introduction: Arduino MEGA 2560 With WiFi Built-in - ESP8266
In today's text, we discuss an Arduino that I consider extremely special, as it has an ESP8266 embedded in its board. It doesn’t have the ESP12 soldered onto the board. Instead, it has the Espressif chip. So, on the board you have the built-in Tensilica chip with 4MB of memory, along with the ATmega2560, which is the traditional Arduino Mega.
Let’s move onto how this Arduino works, and let's do an assembly that shows when you should select ESP or Mega to perform a home automation. With this, we can turn lamps on and off, which is a mechanism that can be very useful for you to make improvements in your house.
Step 1: Physical Characteristics of the Board
I really like that this Arduino has a Pigtail connector for an antenna. Why is this good? If you connect an antenna on this device, you will have a huge benefit, as it will increase your reach, straight from 90 meters to 240 meters away. I came to this conclusion after a test I did, so I did not have to rely solely on the datasheet manual.
This board also has a selector switch that allows the ESP to interleave the connection between TX0 and TX3, remembering that the ATmega has four serials. A second selector switch is the DIP Switch, and we also have a key recording mode of the ESP8266. All the pinning is completely compatible with the ATmega pinout.
Step 2: Access to ESP8266 Pins
Here, I show the back of the board, where there is a table that displays access to the ESP pins.
Step 3: Comparing the Two Arduinos
Here, we have a comparison between the Mega Arduino with the integrated ESP (Arduino Mega RobotDyn) and the traditional Mega Arduino (Arduino Mega 2560). We can see that they are similar, but in the 2560, we have the USB printer, which is a large connector. However, in the RobotDyn, we have the mini-USB. I particularly like the more compact option, but the power is the same in both.
We can see, then, that the intention of the RobotDyn creaters was to maintain the architecture of the ATmega.
As we see in the table above, the ATmega has 32MB of memory, not counting the ESP memory. This is wonderful, since the traditional Mega Arduino has only 256kb of memory. The power in the RobotDyn is 7 to 12 volts, and the ESP8266 is already powered, and already has a voltage reducer. So, feeding the Arduino is already feeding the ESP, which is already down to 3v3, and internally that microcontroller is already 3v3.
The processors are the same, 16MHz, and one great advantage of these models is the high amount of IOs.
Step 4: Switch Status and Mode Selection
We have here the DIP Switch and a table with several positions. These help in the connections, depending on your objective. One essential detail is that if you are writing Flash in ESP, you have to be aware of addresses that are even slightly different.
In the image below, we zoomed in on the key that changes the serial port of the Arduino Mega. This connects to the ESP, and also in the key Mode, requiring that we must press the ESP8266 to record.
Step 5: AT Firmware Installation
If you want to use ESP8266 in AT mode, download the PDF file. You should now configure the card so that the ESP8266 is connected to the USB and in recording mode. To do this, set switches 5, 6, and 7 to ON (left) and all other switches to OFF (right).
If you want to use ESP8266 in AT mode, you should configure the Flash Download Tool as follows:
SPI Speed = 80MHz
SPI Mode = DIO
Flash Size = 32Mbit 4mb bytes x 8 bits = 32m bits
Crystal Freq = 26M
File\bin\esp_init_data_default.binataddress0x3fc000
File\bin\blank.binataddress0x37e000
File\bin\boot_v1.4(b1).binataddress0x00000
File\bin\at\512+512\user1.1024.new.2.binataddress0x1000
Step 6: Verifying AT Firmware
In this part, I used esptool.exe, which is a command tool that accesses the ESP8266 Flash and checks for some settings, such as the chip type and memory size.
Step 7: Example
In this example we show the hexadecimal addresses we use to write with the Flash Download Tool.
Also, for those who do not have much experience with the ESP8266, I suggest two of my previous videos: Recording in ESP01 and Introduction to ESP8266.
Step 8: Configure Arduino IDE Environment
To record the Arduino, there is no mystery at all. You only need to set up the Mega Arduino 2560 board as if it were a traditional Arduino.
Step 9: Arduino Mega With Relays Using Esp8266 Separate Board
We have here the assembly scheme that I perform in the video. We connected the Arduino Mega to the ESP01 and controlled two relays for one application.
Step 10: Arduino Mega With Built-in Esp8266
Here, we do the same thing mentioned above, but while using the Arduino Mega with integrated ESP. One tip is that you watch the video entitled Residential Automation with Arduino Mega and ESP8266 for more details about this subject.
51 Comments
2 months ago
Hi! Can I upgrade sketch of Mega, using ESP8266 OTA ?
6 months ago
My Board needs not only DIP Switches 3 and 4 but also DIP Switch 6 to be set ON for Uploading Sketch to Mega2560.
Some extra Information:
Mega2560 connects to the ESP8266 Serial1.
The Serial0 TX/RX Pins of the ESP8266 are some of the accessable ESP8266 Pins.
Question 10 months ago
Hi, how can I do to communicate via serial from MEGA to ESP8266, with Serial3?
Question 2 years ago on Step 5
what the heck is "AT mode"? and why should or shouldn't i use it?
im not new to programming or electronics but im fairly new to arduino and esp development.
when i see "AT mode" first thing i think of is Auto Translate. which doesn't make sense.
i kinda hate acronyms especially when someone expects everyone to know what the Fun it means.
Acquired Target?
Aqueous Transition?
Abridged Translation?
Armored Transport?
American Tea?
Artistic Talent?
Ancient Transcripts?
Antichrist Transformation?
Almighty Tallest?
Acronym Translator?
Answer 2 years ago
You thought you were being funny, but the jokes on you ;) It doesn't stand for anything, it is just one of the types of firmware you can install in an ESP8266. Most chips come with this setup. All the commands begin with "AT" as in AT+RST to reset. If you were old enough, you would have used these back in the days when everyone owned a Hayes modem to connect to their favorite bulletin board system. It did stand for "attention" but that has long passed into history. It is a PC vs. Mac thing as to which firmware you want to use. But I am of the mind to learn how to use the commands that come loaded in the chip, which can do just about anything, instead of having to upload new firmware. Many of the libraries out there give you computer method type functions that behind the scenes just call the AT commands.
Reply 2 years ago
Lol you know actually i just realized it could also be AT for Atmel in ATmega.
but i do have an actual question.
how is the communication happening between the mega and esp8266?
is it like having separate boards and communicating through some digital pins or something else? I'm not seeing a sample code i can look at.
thanks for any help.
I've programmed an Esp8622 and arduino before but i haven't used both at the same time or an 2 in 1 board.
I needed an ESP8622 board with 16 analog pins and this board seemed like the best option. esp32 is all digital input if im not mistaken. there is a way to use the digital as analog but my input voltage wont match the 0-3.3v and only be 0-1v so accuracy will likely be pretty poor.
Reply 2 years ago
You have that exactly correct. It is two separate circuits linked with those 8 dip switches. If you switch them all off, they are disconnected completely from each other and you can use the male pins near the switches to connect to the ESP8266.
The UART for your serial port (hardware Serial) can connect to the mega or the ESP. So fiddling with the switches lets you program one or the other or run connected to the USB for using the serial monitor. For my needs, I wanted to have the "special mode" with 1, 2, 3 and 4 on which connects the USB to the Mega as it would normally be and with the toggle switch to Tx3/Rx3, connects the ESP to hardware Serial3 on the Mega.
The picture below with a regular mega and an ESP-01 is an exact equivalent of what the Mega WiFi can do where I connect the mega to my laptop and the Mega talks to the ESP through Serial3. I never have to touch the pins again. In this configuration, I can program the Mega as much as I want and run my sketches.
This board looks like it has a level shifter on it, so it converts the GPIO pin voltages from 5 to 3.3 and back. An ESP-01 has one analog input but you would be using the pins on the mega. You can also wire a chip to expand the ports if you needed to.
Here is sample code to run on the mega once you have the ESP programmed to type things to the ESP and have it spit back responses. If I could find the name of the author whose code I modified for this I would give it:
Reply 2 years ago
Thank you very much.
I should be able to work with it now.
Reply 2 years ago
My board either did not have the AT command set flashed on it or had a version that wouldn't work the way I needed it to, so I had to flash the ESP8266. Took about 15 tries ;) But I finally figured out the settings. Hope you don't have to do that, but if you do, I can give you my settings
Reply 2 years ago
I cant get any sketch to upload to my mega2560 + WIFI R3 board...
im getting " avrdude: stk500v2_ReceiveMessage(): timeout "
been at it for a few hours and im about to break it in half and get a regular mega.
neither Rx or Tx LED is blinking during upload.
Reply 2 years ago
Are you trying to flash the ESP8266 or the Mega? With 1,2,3 and 4 ON, connect your serial cable to the Mega. In the Arduino IDE, make sure you select the Mega and the correct COM port. If you don't see the com port, then your computer doesn't have the CH340 driver you need to communicate with the cheap chip these boards use. Download and install that for your OS. If you are trying to flash the ESP8266, that's a bit more difficult. ;)
Reply 1 year ago
Hi FrightRisk,
Newbie here. I just got the mega wifi. The esp not communicating. I have installed 340 driver.
How do you flash the esp?
Thanks.
Reply 2 years ago
Thanks!! "facepalm...."
Right now i just wanted to program the mega part to try out a LCD first. For some reason i had completely forgot about the DIP setup picture you had. i had 5,6,7 on at first then turned them all off. (work independently ) but also NO usb communicate.
with 3,4 on it works....
There is almost no forum help on this board. the only suggestion i could find was bootloader and that wasn't it. doesn't help that i'm trying this after work when i tend to fall asleep in my chair.
Answer 1 year ago
At mode means when you plug in the usb your talkimg to the storage chip (the atmega, a relative of the attiny and I believe ones called an atmel...) there's a different mode also set with the dip switches to chanhe it to esp mode so your fiddling with the wifi stuff instead of the storage chip... hope that clears a bit up...
Answer 2 years ago
From https://www.sparkfun.com/datasheets/Cellular%20Modules/AT_Commands_Reference_Guide_r0.pdf, page 6:
"The AT is an ATTENTION command and is used as a prefix to other parameters in a string. The AT
command combined with other parameters can be set up in the communications package or typed in
manually as a command line instruction."
Reply 2 years ago
This was answered 4 days before you posted ;)
1 year ago
MUCHAS GRACIAS, Por la AYUDA., Eres muy amable gracias. CIUDAD DE MÉXICO., RAFAEL 🌈🐺
1 year ago
Reply 1 year ago
Don't be offended because this linknis for absolute beginners, but this page has a wealth of knowledge that rivals this place, and it'll link you to more and more advanced stuff, plus theres also links to their github where they have all kinds of sketches and libraries to download for arduino, rasp pi... Literally anything they sell they have tons of instructions, projects, and just troubleshooting. Plus if you can't figure out what ya doimg amd you post they usually actually will reply and either point you to it or go oh damn we don't have that, well get right on adding it. Love em. I order most of my tinkering stuff from them. Good prives, always ships fast and from the us(new york) and they are just neat people. All their info is free just because they feel everyone should habe access to all that information if they want it.(sorry fot ramblinh)
https://learn.adafruit.com/series/learn-arduino
Question 1 year ago on Step 8
Hi!
I m fairly new to Arduino environment,
I wanted to know that what should be the DIP switch and tx selector switch config. for uploading the code to atmega chip directly?
Also, is it possible to use this board without the wifi thingy for the time being?
I.e., use it as a usual mega board?