Connecting and working with Mega +WiFi R3 ATmega2560+ESP8266 (32Mb memory)

Hi Guys,

Recently bought a Mega +WiFi R3 ATmega2560+ESP8266 (32Mb memory) from Aliexpress and I wanted to work on a Home Automation Project with all the sensors and modules connected to same Board (in this case, it was going to be Mega). Later on I had plans to log all the values to a database in the cloud.

I thought, this was going to be as easy as hooking up the board into USB with my PC and push the code to do a Serial Communication between Mega and the ESP8266 Chip that was on board but this turned out to be something I never wanted. Each of the modules i.e. Mega and ESP8266 Chips work when connected independently with correct DIP switch configuration, but I don't know how am I going to make them work together simultaneously. I did try to put it in Special Mode as suggested in the above product page as well as this question earlier.

I think, in past 1 month or so, I have tried doing each and every configuration that I could understand, just to fail at the end.

But now, I have started to regret buying this board :cry: , having said that there is almost no documentation on the entire WWW. The only thing, one could find would be something in Russian and other only translated out of it. That too does not work here.

In fact, I even tried hooking up an ESP8266 separately to the Mega and do Serial Communication but I've never had a chance to see the output of a simple AT command on the Serial Monitor. Though the same chip works with a Nano in same pin configuration.

Any members on the forum, having knowledge or experience in handling this board who could share some thoughts on how exactly does this work? Would really be a great help. :-\

Similar troubles are with Arduino Uno Wifi Developer Edition.

Uno Wifi Dev Ed info

Not sure why, but all the WiFi connectivity options seem to be unreliable. I also have a NodeMCU but the issue is that most of the sensors give output as Analog, and NodeMCU only has 1 ADC input. If possible, can anyone share ADC conversion using ADC0809 chip, as I have 1 lying around?

Also, is there any Board with reliable WiFi connectivity, which works perfectly out of box, and has ample ADC pins to replace a Mega or atleast an Uno?

It's not that hard. It's excactly the same when you would hookup a ESP8266 to a standard Mega.

There is an Table DIP- switch on the page you posted.

There are 6 modus:

ATmega2560<->ESP8266 (Both chips can work together)
USB <->ATmega2560 (only usb and atmega)
USB<->ESP8266 (Update firmware or sketch)
USB<->ESP8266 (serial communication)
All independent (both working but not connected)

USB <-> ATmega2560<-> ESP8266 (Unsure, properly for getting Serial output when both chips working together.)

You upload a sketch to the Atmega using this option:

USB <->ATmega2560 (only usb and atmega)

You upload a sketch to the ESP using this option:

USB<->ESP8266 (Update firmware or sketch)

You then select this option:

ATmega2560<->ESP8266

Voila it's working.

  1. You hook up a sensor to the Mega.
  2. You get data from the sensor.
  3. You send the data to the ESP8266. Probably using something like 'Serial.print(data)'
  4. You receive the data at the ESP8266 and you do with it whatever you want.

If you use this connection:

USB <-> ATmega2560<-> ESP8266

Then using 'Serial3.print(data)' will send data to the ESP8266.

1 Like

You didn't write in your post what problem you have with modes when AVR and ESP are connect. There are two option for this.

The first option is when AVR and ESP are connect over serial 1. In this mode you can't use USB (upload and monitor are unavailable). You must accept this fact and monitor using serial 2, telnet, LCD, TV out .. . To change the sketch you must select other mode with dip switches. Or use ESP firmware with AVR sketch OTA upload over WiFi.

The 'special' option gives you USB access to AVR and connects AVR and ESP over serial 2 (edit) serial 3. But the firmware in ESP a the library for AVR are writen for serial 1.

Juraj:
The 'special' option gives you USB access to AVR and connects AVR and ESP over serial 2. But the firmware in ESP a the library for AVR are writen for serial 1.

To avoid confusion. It does not use those serial ports in the special mode.It will use Serial(0) for the Mega<> USB and Serial3 for Mega <> ESP.

· USB converter CH340G connect to RX0/TX0 of ATmega2560
· ESP8266 connect to RX3/TX3 of ATmega2560

Thanks Lennyz1988 & Juraj for trying to help out. Really appreciate you guys for taking time and helping out.

Let me explain the issue a little bit and try to understand the suggestions at my end.

Problem (Please refer to pic of my board here: Imgur: The magic of the Internet):

In Special Mode, as the documentation suggests (where Switch 1 1=ON, 2=ON, 3=ON,4=ON, 5=OFF, 6=OFF, 7=OFF, 8=ON) that the AVR/MCU is connected to ESP on TX3/RX3 using the Switch 2 which is set to RXD3/TXD3.

If I'm doing that correctly, I should be able to run AT commands using my Serial Monitor through AVR to ESP8266 on board, but I do not see anything on the serial monitor at all. Please correct if I'm wrong :confused:

My understanding from your suggestions.
As per @Lennyz1988, I'll have to write code twice i.e. each for AVR as well as ESP wherein the AVR and ESP would do the data transmission over Serial Port. For this, I need to first use the USB<->AVR mode and then USB<->ESP mode. And finally once the codes are uploaded, check the data over Serial Monitor using Special Mode i.e. USB<->AVR<->ESP.

Is that so?

@Juraj, are you sure the Serial is done over Serial 0 for this version of mega, as in the documentation, the communication in special mode is done over Serial 3?

cyberpks:
Thanks Lennyz1988 & Juraj for trying to help out. Really appreciate you guys for taking time and helping out.

Let me explain the issue a little bit and try to understand the suggestions at my end.

Problem (Please refer to pic of my board here: Imgur: The magic of the Internet):

In Special Mode, as the documentation suggests (where Switch 1 1=ON, 2=ON, 3=ON,4=ON, 5=OFF, 6=OFF, 7=OFF, 8=ON) that the AVR/MCU is connected to ESP on TX3/RX3 using the Switch 2 which is set to RXD3/TXD3.

If I'm doing that correctly, I should be able to run AT commands using my Serial Monitor through AVR to ESP8266 on board, but I do not see anything on the serial monitor at all. Please correct if I'm wrong :confused:

Yes that should be possible. It depends on what sketch/firmware you got flashed on your ESP.

My understanding from your suggestions.
As per @Lennyz1988, I'll have to write code twice i.e. each for AVR as well as ESP wherein the AVR and ESP would do the data transmission over Serial Port. For this, I need to first use the USB<->AVR mode and then USB<->ESP mode. And finally once the codes are uploaded, check the data over Serial Monitor using Special Mode i.e. USB<->AVR<->ESP.

Is that so?

You can do either one of these options:

  1. Flash the ESP with AT-command firmware so you can control the ESP from your Mega sketch.
  2. Write code for both of the devices.

Usually people pick option 2 because that's the most easy.

cyberpks:
you sure the Serial is done over Serial 0 for this version of mega, as in the documentation, the communication in special mode is done over Serial 3?

Just a guess. It's the reason why usb can't be connected in that mode. 'Serial' is to computer or to ESP.

Option 3 for ESP firmware is JeeLabs esp-link or Arduino.org WiFi link firmware. More in the link in #2.

1 Like

Thanks Guys, I'll try-out all the suggestions on my configuration and get back to you with updates. Hope that I can get this to work.

Cheers for the prompt response from both of you :slight_smile:

ESP firmwares like JeeLabs esp-link or Arduino.org WiFi link firmware have over-the-are (OTA) upload of AVR sketch from IDE and OTA of the ESP firmware update too. The WiFi Link firmware is an arduino sketch so it is easy to modify it and upload from IDE. I don't use the USB - upload is OTA and Monitor is Telnet.

Hello everyone ;D ,

Finally, after a lot of troubles and trials, I have finally been able to make the MCU and ESP communicate over Serial at the same time.

I think the issue was more due to incorrect firmware flashed over ESP (Dip switch configuration: 5=ON, 6=ON, 7=ON and rest OFF). I found the correct version (I think) here, and once this was flashed on the ESP, I configured the board's DIP switch on Special Mode (i.e. 1=ON, 2=ON, 3=ON, 4=ON and rest OFF), and finally the other switch set to TXD3/RXD3. Finally after setting the board as "Arduino/Genuino Mega 2560, ATmega2560(Mega 2560)", in Arduino IDE, I pushed the below sketch on the board.

void setup()

{
  Serial.begin(115200);
  Serial3.begin(115200);
  pinMode(13,OUTPUT);
  delay(500);
  Serial.println("AT+CIPMUX=1");
  Serial3.println("AT+CIPMUX=1");
  delay(2000);
  Serial.println("AT+CIPSERVER=1,5000");
  Serial3.println("AT+CIPSERVER=1,5000");
  delay(2000);
  Serial.println("AT+CIPSERVER=1,5000");
  Serial3.println("AT+CIPSTO=3600");
  delay(2000);
}

 

void loop()
{
    // listen for communication from the ESP8266 and then write it to the serial monitor
    if ( Serial3.available() )   {  Serial.write( Serial3.read() );  }
 
    // listen for user input and send it to the ESP8266
    if ( Serial.available() )       {  Serial3.write( Serial.read() );  }
}

And Finally........... :smiling_imp:

It worked 8) ...... !!!!!!

Hope this helps someone else, in trouble like me :slight_smile:

1 Like

Dear All,

I have the same board (Wemos Atmega+esp8266). I can program both contollers with my sketches. I haven't problem with the swithes.
My problem is that I can't make it to work the original AT firmware. I tried many cases but I haven't luck. The upload hasn't errors everithing is fine, but after the upload in the terminal I have only noise. I tried form 9600 to 115200 baud without success.

The firmwares what I tried

Both have bin directories with precompiled firmwares. I used them with esptool under Linux.

I wrote a sample script (more cases):

Flash size 32Mbit: 512KB+512KB

boot_v1.2+.bin 0x00000

user1.1024.new.2.bin 0x01000

esp_init_data_default.bin 0x3fc000 (optional)

blank.bin 0x7e000 & 0x3fe000

#esptool -v -cd wifio -cc esp8266 -cb $SPEED -bz 32M -bf 80 -bm qio -cp $PORT
#-ca 0x00000 -cf $FLASH_BIN/boot_v1.7.bin
#-ca 0x01000 -cf $FLASH_BIN/at/512+512/user1.1024.new.2.bin
#-ca 0x3fc000 -cf $FLASH_BIN/esp_init_data_default.bin
#-ca 0x3fe000 -cf $FLASH_BIN/blank.bin
#-ca 0x7e000 -cf $FLASH_BIN/blank.bin

Flash size 32Mbit-C1: 1024KB+1024KB

boot_v1.2+.bin 0x00000

user1.2048.new.5.bin 0x01000

esp_init_data_default.bin 0x3fc000 (optional)

blank.bin 0xfe000 & 0x3fe000

esptool -v -cd wifio -cc esp8266 -cb $SPEED -bz 32M -bf 80 -bm qio -cp $PORT
-ca 0x00000 -cf $FLASH_BIN/boot_v1.7.bin
-ca 0x01000 -cf $FLASH_BIN/at/1024+1024/user1.2048.new.5.bin
-ca 0x3fc000 -cf $FLASH_BIN/esp_init_data_default.bin
-ca 0x3fe000 -cf $FLASH_BIN/blank.bin
-ca 0xfe000 -cf $FLASH_BIN/blank.bin

Could you help me what can be the problem? Why doesn't work the successfully uploaded AT firmware?
And one more question. What is a mode button on the board?
Thank you

Juraj, can you please share some code that you use to upload new sketches with OTA? I have been struggling a lot with this option, but no proper solution found yet. I have bought
this board

But that has only 3.3V on the pins. I want to drive an LED strip that needs 5V data input. So to conver 3.3V to 5V I want level shifters and buck converters.

However, I am thinking of buying this boar

For either board, I would really appreciate if you could share a sketch/program that can facilitate uploading new sketches OTA. If you could please provide instructions on the ESP sketch as well, using DIP switch positions.

the build in avr serial programmer of esp-link and WiFi Link firmwares supports only Atmega 328p. it will not work with Atmega 2560 on the Mega. The esp-link supposedly has the option to bridge avrdude commands from computer over telnet so it should work with Mega but I never tested this way.

are you sure that the digital input of the led strip wouldn't work with 3.3 V? most 5 V digital inputs evaluate 3.3 V as HIGH. and you can power the strip from 5 V pin. but I know nothing about led strips.

Hi cyberpks.

Can you please provide more detail about how you uploaded the new esp firmware.

Cheers
Garry

Hi everyone, looks like a LOT of confusion with this board, and VERY LITTLE good info online as far as I have found.

I managed to get it working, I can upload sketches to the Mega with switches 3 and 4 on, and upload sketches to the ESP with 5, 6, and 7 on...

With 1, 2, 3, and 4 on, I can upload sketches to the Mega, and the Mega and ESP can talk over serial (Mega-Serial3, ESP-Serial)

So I've got a WebServer running on the ESP, as well as loaded a MySQL connector library so it can read/write data to a remote MySQL Server.

The Mega will connect using SoftwareSerial with 3 other Pro-Mini's, each with 8 sensors (limit of analog pins) and send results via Serial3 to the ESP which will parse the data, and do inserts into the database.
The WebServer can then read this data and display it...

I'm concerned that all this DIP Switch switching is going to kill the tiny little switch!

There is also the MODE button, which existing instructions say you must push to program the ESP. Well, I can program the ESP with the proper DIP Switch settings, and don't need the MODE button. In fact, if I have the DIP Switches in another configuration, the MODE button doesn't do anything.... I'm hoping it's a shortcut so you don't need to keep changing the DIP switches all the time during development...

Some actual instruction here would help, do you just press it and release at any time? press and hold during upload? Press and hold at bootup? Tried em all, nothing....

I've only had this for a couple days,. and I like it, and will be ordering more, but I sure hate the thought of it becoming useless over a mangled dip switch....

1 Like

odam2k:
I'm concerned that all this DIP Switch switching is going to kill the tiny little switch!

You can use OTA upload to esp8266
or
Topic: Arduino + ESP8266 with EspProxy (develop without rewiring) (read all posts in the topic)

I couldn't get IDE OTA to work, the network port isn't showing up, so rather than mess with that, I'm using web browser update for now, and that solves my problem with the dip switches, thanks!

I still don't know what the mode button is supposed to be used for, but everything seems to be working.

Hi,
I have one of these modules and I can load the sketchs without problems in both the ESP and the Mega changing the DIP's. The problem comes because my ESP only uses it as an AP so that the Mega receives data. The AP is reflected in the WiFi search but when you connect to the AP it disappears and you have to turn off the power so that it goes back out because no reset succeeds.

Thinking that it was the module that was defective I bought a second module and it does exactly the same. The fact is that the same sketch I put in my Nodemcu and works perfectly.