Arduino MEGA 2560 With WiFi Built-in - ESP8266

Introduction: Arduino MEGA 2560 With WiFi Built-in - ESP8266

About: Do you like technology? Follow my channel on Youtube and my Blog. In them I put videos every week of microcontrollers, arduinos, networks, among other subjects.

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.

Be the First to Share

    Recommendations

    • Battery Powered Contest

      Battery Powered Contest
    • Plywood Challenge

      Plywood Challenge
    • Plastic Contest

      Plastic Contest

    36 Discussions

    1
    isakitela
    isakitela

    Question 2 months ago

    Where can I get the codes for this project? and once I have them .... Which code is for esp and which is for Mega?
    0
    Bulldog1989
    Bulldog1989

    2 months ago

    How do I use the 'Flash Download Tool'; finally managed to download & open the program, enter the data you have given us, but nothing happens.

    Also you have given a link to a youtube video, unfortunately it's not in English, so is no help to me.

    Where do I find 'esptool.exe' ?

    I have been working on getting this board to work for a week now, & starting to believe it is impossible to connect it to the internet.

    Thanks

    Alan

    0
    obiora
    obiora

    6 months ago

    Good day all, please I need help here I have mega 2560+ Esp8266 I have tried to upload sketch and its not working but always giving me error massage

    2
    ToniD0
    ToniD0

    Reply 6 months ago

    I had similar problem yesterday. :-D:
    i put switches like this:
    1=OFF 2=OFF 3=ON 4=ON 5=OFF 6=OFF 7=OFF 8=OFF

    and sketch works:-). no error anymore.

    0
    krisferrari
    krisferrari

    Reply 4 months ago

    I tried looking at OPs table [ 3rd combination], but I think it is not the proper combination, though general blink etc upload works . It may void the esp8266. Combination 1 i.e 4offs, 3 ons is used in Step5 should be enabling both atmega and esp

    0
    john henry
    john henry

    Question 5 months 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?

    0
    FrightRisk
    FrightRisk

    Answer 5 months 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.

    0
    john henry
    john henry

    Reply 5 months 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.

    0
    FrightRisk
    FrightRisk

    Reply 5 months 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:

    void setup()
    {
    Serial.begin(115200); // communication with the host computer
    //while (!Serial) { ; }
    // Start the software serial for communication with the ESP8266
    // Switch the comments on the 2 lines below for an Uno
    //ESPserial.begin(115200);
    Serial3.begin(115200);
    Serial.println("");
    Serial.println("Remember to to set Both NL & CR in the serial monitor.");
    Serial.println("Ready");
    Serial.println("");
    }
    void loop()
    {
    // listen for communication from the ESP8266 and then write it to the serial monitor
    // more Uno swapping, change Serial3 for ESPserial
    if ( Serial3.available() ) { Serial.write( Serial3.read() ); }
    // listen for user input and send it to the ESP8266
    if ( Serial.available() ) { Serial3.write( Serial.read() ); }
    }

    mega_esp-01.jpg
    0
    john henry
    john henry

    Reply 5 months ago

    Thank you very much.
    I should be able to work with it now.

    0
    FrightRisk
    FrightRisk

    Reply 5 months 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

    0
    john henry
    john henry

    Reply 4 months 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.

    0
    FrightRisk
    FrightRisk

    Reply 4 months 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. ;)

    0
    john henry
    john henry

    Reply 4 months 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.

    0
    FrightRisk
    FrightRisk

    Reply 4 months ago

    This was answered 4 days before you posted ;)

    0
    mrsharkit
    mrsharkit

    Question 1 year ago on Step 1

    hi
    to enable external antenna, isn't it required to remove or move one of the 2 resistors near the socket? I read it somewhere, but can't find info on it...

    0
    accarien1
    accarien1

    Answer 5 months ago

    hello, did you find the answer ?