Go Down

Topic: Connecting and working with Mega +WiFi R3 ATmega2560+ESP8266 (32Mb memory) (Read 8945 times) previous topic - next topic

cyberpks

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 :'( , 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.   :-\

Juraj

You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

cyberpks

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?

Lennyz1988

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.

Juraj

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.
You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

Lennyz1988

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

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: http://imgur.com/a/gvA0d):

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  :smiley-confuse:


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?

Lennyz1988

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: http://imgur.com/a/gvA0d):

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  :smiley-confuse:
Yes that should be possible. It depends on what sketch/firmware you got flashed on your ESP.

Quote
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.

Juraj

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.
You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

cyberpks

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 :)

Juraj

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.
You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

cyberpks

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.

Code: [Select]

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........... :smiley-evil:

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

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

exon

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
- git clone https://github.com/espressif/esp8266_at.git
- https://github.com/espressif/ESP8266_NONOS_SDK/releases/tag/v2.1.0

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

wishwa

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
<a href="https://www.amazon.com/HiLetgo-Internet-Development-Wireless-Micropython/dp/B010N1SPRK/ref=sr_1_3?ie=UTF8&qid=1523159450&sr=8-3&keywords=eps8266&dpID=51XTrgJ-HLL&preST=_SX300_QL70_&dpSrc=srch">this board</a>

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 <a href="https://www.aliexpress.com/item/WEMOS-Mega-WiFi-R3-ATmega2560-ESP8266-32Mb-memory-USB-TTL-CH340G-Compatible-for-Arduino-Mega-NodeMCU/32814497771.html?spm=2114.search0104.3.124.3c2f39d8vg67sT&ws_ab_test=searchweb0_0,searchweb201602_2_10152_10065_10151_10344_10068_10130_5722815_10324_10342_10547_10325_10343_10546_10340_10341_10548_5722915_10545_5722615_10696_10084_10083_10618_10307_5711220_5722715_10313_10059_10534_100031_10103_441_10624_10623_10622_5722515_10621_10620_10810_10811,searchweb201603_25,ppcSwitch_5&algo_expid=62c714c8-ada4-4c8b-8e87-63abe0beb647-17&algo_pvid=62c714c8-ada4-4c8b-8e87-63abe0beb647&transAbTest=ae803_4&priceBeautifyAB=0">this boar</a>

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.

Juraj

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.
You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

Go Up