Arduino Mega 2560 + ESP WiFi

Last Updated on 1 April 2022 by Suffocation

Es handelt sich hierbei um ein hybrides Board aus Atmega 2560 und einem Espressiv Chip (ESP8266) für die WLan Kommunikation.

View

Überblick


NameMega + WiFI
Number/CPU
1 / ATMEGA 2560 + ESP8266
Clock speed (MHz)16 /240
Kernel1/1
Digital IOs / Pins54
Analog inputs16
Interrupt Pins4
Pulse Width Modulation15
SPI1
Flash memory32 MB /
RAM (KB)8KB/
EEPROM (KB)4 KB
WiFi802.11 b/g/n
Bluetooth
EncryptionWEB / WPA2 / TKIP / AES
Bluetooth-
UART4
I2C1
Ethernet-
Video-
Sound-
Miscellaneous-
USB1 Micro
Operating voltage [V]5
Input voltage7-16
Current (mA) / Standby (mA)
Size L x W x H101.52 x 53.3
Weight [g]

Board features

Arduino Mega + ESP Beschriftet
Arduino Mega + ESP Labelled

Zusätzlich sind einige Pins des ESP herausgeführt. Die Beschriftung ist auf der Rückseite des Boards zu finden.

DIP Switch Settings

1234567
ATMega ESP AnAnAustralia Australia Australia Australia Australia
USB ATMega Australia Australia An An Australia Australia Australia
USB ESP Firmware Australia Australia Australia Australia An An An
USB ESP Com. Australia Australia Australia Australia An An Australia
No connections Australia Australia Australia Australia Australia Australia Australia

Special Pin Assignments

FunctionPins
Interrupt 2, 3, 18, 19, 20, 21
Serial port 1
Serial port 2
Serial port 3
Serialport 4
0 (Receive), 1 (Transmit)
19(RX), 18(TX)
17 (RX), 16 (TX)
15 (RX), 14 (TX)
LED 13

Closer inspection

Hier ein paar Schnappschüsse mit dem Mikroskop.

Programming environment

Mega Settings

Dips switch 3,4 to ON, rest to OFF

Auswahl Arduino Mega in der Arduino IDE
Selecting the Arduino Mega in the Arduino IDE

ESP Settings

Possibly, before that, Setting up the ESP8266 programming environment. I used version 2.7.1 of the board drivers here.

Dipschalter 5,6,7 auf ON Rest auf OFF. Sollte das programmieren nicht beginne ist ein Reset  des Boards nötig. Das spielen mit der Reset Methode im Menü brachte hier leider keine Besserung.

Überblick Arduino Mega Einstellungen in Arduio IDE
Überblick Arduino Mega Einstellungen in Arduio IDE

Test Programme

Als Testprogramme können die, des hier gelinkten Beitrags verwendet werden.

Miscellaneous

Using AT-Lib

Wenn man noch nicht so genau weiss wo die Reise hin geht und für was der ESP auf dem Board gebraucht wird, kann man erst einmal eine Maximalkonfiguration aufspielen. Dh. man spielt die sogenannte AT-Firmware auf, die durch Steuerkommandos (die auf komischerweise alle mit AT beginnen) konfiguriert wird ohne jedes mal neu programmiert zu müssen. Wer jetzt glaubt vom Regen in die Traufe zu kommen und AT Kommandos lernen zu müssen hat Glück, es gibt eine gegestück für den Arduino. Ein paar Klassen erlauben es den ESP mit einfachen Methodenaufrufen zu steuern ohne die AT Kommandos verwenden zu müssen. Somit ist sind die Ziele:

  • Installing the AT firmware on the ESP
  • Create a program on the Arduino which uses the ESP as a Wi-Fi adapter

HINWEIS: Schaut mal vorba ob nicht schon die AT Firmware auf dem dem ESP vorhanden ist, solltet ihr sie überschrieben haben, kein Problem hier erfahrt ihr wie ihr sie wieder herstellen könnt.

Den Prepare ESP

Set the ESP to programming mode itself:

Für den ESP benötigen wir eine Version der AT Bibliothek. Diese gibts als Binärdatei auf der Espressif Homepage.

https://www.espressif.com/en/support/download/at

Sollte die gewählte Firmware nicht funktionieren, probiert mal ältere Versionen aus. Auch ich habe mehrere ausprobiert und ich bin bei Version 1.6 in dieser Konstellation gelandet.

Zum flashen der Binärdatei auf den ESP kann jedes beliebige Tool verwendet werden, hier das vom Hersteller.

Tool und Binärdatei entpacken. Geladen wird mit der 1.6 Version wie folgt. In den README Dateien der Zip’s ist meist beschrieben wie diese zu flashen sind (hat bei mir alles nicht funktioniert, habe nach unzählig Versuchen eine Kombi gefunden die bei diesem Board funktionierte).

MEGA+WIFI – Start Flash Tool from Hard Drive
MEGA+WIFI – Start Flash Tool Modus auswählen

Dateien Auswählen, Speicherbereiche eingeben, Einstellungen anpassen und noch die richtige Verbindung zum Board wählen. Danach auf Start und warten was passiert.

MEGA+WIFI – Flashoption für AT Firmware

Ob die Firmware richtig installiert ist kann in der Arduino IDE Konsole überprüft werden. (Nicht vergessen Dipschalter 7 wieder aus zu schalten, sonst geht nichts). Boud Rate ist 115200 als Zeilendend NL/CR auswählen und oben in die Sendezeile AT eingeben. Kommt ein OK zurück klappt erstmal alles.

MEGA+WIFI – Console AT Command Fun

Wer noch mehr über die vorhandenen AT Kommandos wissen will kann sich auf der folgenden Seite informieren.

https://docs.espressif.com/projects/esp-at/en/latest/AT_Command_Set/index.html

Da im Arduino auf das Netzwerk zugegriffen werden soll möchte ich das vorab mal mit AT Kommandos prüfen:

AT+CWMODE=1 -> Turn on Station Mode

AT+CWLAP -> Netzwerk scannen gibt ne liste zurück

Connect to Access Point

AT+CIFSR -> Get connection information

AT+CWDHCP? -> DHCP enabled? If not, enable with AT+CWDHCP:1

More coming soon.... 

Connect external antenna

Wie ihr im Bild seht ist mein Mega+Wifi etwas eingestaubt. Nichts desto trotz kam die Frage auf, was zu tun ist um eine extene Antenne anzuschliessen. Hierfür muss die Brücke (0 Ohm Widerstand) aus dem Bild umgelötet werden auf die freie Position (2).

Mega+Wifi – Brücke umlöten von 1 nach 2.

Conclusion

Wer ein Arduino Uno kompatibles Board, eine Menge zusätzlicher Ports und eine WLan Anbindung benötigt, ist mit diesem Board richtig gut bedient. Der Antennenanschluss vergoldet das Board zusätlich, da hierdurch höhere Reichweiten erreicht werden können.

Zudem ist das Board recht günstig, seit dem der ESP32 draussen ist, wird das Board zum Teil unter 10€ gehandelt  (schaue beim schnellen Ali oder beim guten Beng nach 😉 ).

Sources

https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/

https://www.arduino.cc/en/Hacking/PinMapping2560

https://www.instructables.com/id/Arduino-MEGA-2560-With-WiFi-Built-in-ESP8266/

https://robotdyn.com/catalog/boards/mega_wifi_r3_atmega2560_esp8266_flash_8gb_usb_ttl_ch340g_micro_usb/

https://docs.espressif.com/projects/esp-at/en/latest/AT_Command_Set/index.html

https://www.espressif.com/en/support/download/at

DateChangeAuthor
31.10.2017Post createdSuffocation

11 thoughts on “Arduino Mega 2560+ESP WIFI

  1. Hello,
    I wanted to set up this board with ESP using your guide. Unfortunately, the version you used in your guide is no longer available on the Espressif website. The current version does not have the .bin files you used. Do you know of another download option or can you send me this version via email?

    Thank you
    Thomas

      1. Hello Stefan,
        Thank you very much for the quick reply. I also managed it with the current firmware. DIP switches 5 and 6 are now on, the rest off. AT commands work and the connection to the FritzBox also works. Once the connection is established it is also stable. It just sometimes takes a few board resets until it gets an IP address. Although it is set in the FritzBox that the same IP address should always be assigned.

        The problem now is that I can't get a sketch onto the ESP. I downloaded a small sketch for a mini web server to test. Compiling also runs without errors. However, in the Arduino IDE, under the selected board Generic ESP8266, the Programmer is „No Programmer available“. In your instructions above, however, there is one. Naturally, I always receive the message that the sketch cannot be uploaded due to a timeout.

        Any clever ideas where the problem might lie?

        Thank you

        Thomas

        1. Hello Thomas,
          I've just checked it on my end. It really doesn't say Programmer anymore, but programming my board is possible. However, with me, DIP switches 5, 6, and 7 must be activated for programming. After programming, remove 7 again. (If the ESP is not already disconnected from the power, reset it again in both cases).
          Greetings Stefan

  2. Thank you, good article
    I have such a board running to connect RFLink to my MQTT broker via MQTT and WiFi.
    I am finding that the stability of the WiFi connection is extremely dependent on the [STAO] situation. I have a WiFi setup based on a Fritz 7560 and two repeaters in a mesh. I am currently using the PCB antenna.
    Has anyone successfully connected an external antenna? Does anything need to be re-soldered for this?

    1. Hi, I'm currently on holiday and don't have the board in front of me. But I always thought that mine at least only worked with an external antenna. I can't see an etched antenna on the pictures, nor the characteristic 0 Ohm jumper.

      Greetings Stefan

    1. Hello Michi,
      Good tip, you should always include the version number :( I'll improve that straight away. I used version 2.7.1. If no methods have been renamed or new bugs have been added, it should also work with 2.7.4 :).

      Hello
      Stefan

Leave a Reply

Your email address will not be published. Required fields are marked *