ATmega328p + ESP8266 WIFI tutorial

Hi,

So I had quite some trouble getting my board to work as most things are not straightforward. Therefore, I am writing this short tutorial with everything I learned so people do not have to rediscover everything on their own. This guide is specifically for the UNO R3 + ATmeg328p + ESP8266 WIFI (4Mb) USB - TTL. This thing still feels like a black box to me, so if you have any more insight please let me know in the comments.

Board Layout
The board has two chips, an ATmega328p chip, and an ESP8266 WIFI module. Both chips can communicate with each other and you as a user can communicate/read/write to one over USB depending on how you set the dip switches.

My board has a CH340G thing to communicate over USB. It can be that your device is not recognized when plugging it into the USB port of your computer. Maybe you have to install the appropriate driver. At first, I thought this was the problem for me, turned it out was NOT.


Dip Switches
Communication mode is set using the dip switches as follows:
ATmega <-> ESP8266 1100000
USB <-> ATmega 0011000
USB <-> ESP8266 0000111 (Update firmware or sketch)
USB <-> ESP8266 0000110
All independent 0000000

As you can see, the first two switches enable communications between both chips. And for USB communication you have to choose either ESP8266 or ATmega.

I read somewhere that when changing dipswitches you have to press ESP reboot. However, I cannot verify this, I believe it worked for me without doing this but honestly, the thing is still a black box to me.

Programming ATmega
When programming the ATmega you have to set dip-switches (3,4) ON and (5,6,7) OFF. Now in the Arduine IDE I select the Arduino UNO as the board. Make sure you select the right COM port, you can check by unplugging the USB from your computer and putting it back in again to see what COM port shows up (you have to exit the menu in between).

When uploading a sketch it gets a bit tricky. Here it helps if you go to Arduino->Preferences and set Show verbose output during: upload. Now, when you hit the upload button you wait for the first few (red) lines (overriding baudrate for me) of the upload to show up in the console. If these show up you press the red reset button. Now it should start uploading. If it shows an error just try again and play a bit with the timing of pressing the reset button.

Programming ESP8266
When programming the ESP8266 you have to set dip-switches (5,6,7) ON and (4,5) OFF. I downloaded the ESP8266 community here board manager and selected Generic ESP8266 module.

Now, before uploading anything you have to reset the board with the red reset button before pressing upload in the IDE. After you upload your code I believe you have to put dip-switch 7 to OFF so that your sketch remains after rebooting the board.

If it looks like it is not working, just wait for it to throw an error and try again. Again pressing the reset before uploading. Maybe throw in an upload without pressing reset before. Setting reset method to no dtr, no_sync also did something for me.

When dip switch 7 is ON I believe the ESP8266 does some kind of factory reset when you reset the board. This will then enable a new sketch to be uploaded.

I am still having problems sometimes uploading to the ESP8266, sometimes it feels like just trying over and over until it works... I think by default the LED is turned on (this LED is on PIN 14 in case you want to play with it).

ERROR MESSAGES
I solved this with above protocol:
esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header

Notes
Using mac

I hope this turns out useful for someone. If I got anything wrong or anyone has other useful insights please let me know in the comments.

6 Likes

Why? The combination of Arduino Nano or Uno AND ESP8266 or ESP32 has always seemed pointless to me. Even the weaker ESP8266 is much more powerful than ATmega328 and with much more memory and only its pins are less but then you can use ESP32 and the difference in price is small. They can also be programmed directly from the Arduino IDE.

Thanks @pangeaterra. Maybe adding an image of your board can make things a little easier for beginners; at least they can see what you're referring to if their board does not exactly match.

The boards exist and are in use so a tutorial is always useful. The fact that you will not use a board like that is another story :wink:

1 Like

Thanks for mentioning it. For me, I'm just getting into it and thought this was a good starting point. Since I am only programming my ESP8266 as of now I would definitely recommend looking into ESP8266/ESP32 only for other people.

Multi-processor communication is a good skill to learn, and quite important in the real world. I have yet to see a complex system running from within a single gazillion gigahertz processor

1 Like

In my opinion the primary benifit is flexibility. It's a more or less self contained communication module, which can be easily replaced with some other communication module.

Edit: And active power consumption and peripherals.

1 Like

Good tutorial :slight_smile:

The benefit of this configuration is ease of use and compatibility. You have 1 core (ESP) running Wifi tasks. The other core (ATmega) is running a non-blocking sketch, which communicates with the ESP when needed.

The Blynk IOT platform currently struggles to use the dual cores of the ESP32, but having 2 separate microcontrollers eliminates this problem.

1 Like

Here's one possible reason for using a co-processor of some kind with an ESP8266: https://forum.arduino.cc/t/tcp-non-blocking-code-for-client-connection-to-server/968403

@pangeaterra Nice little tutorial :smiley:

3 Likes

A post was split to a new topic: Unable to program ATMega

I spent a whole day trying to get this piece of garbage working and your tutorial is the first time my code has been uploaded successfully (i used the USB <-> ATmega and had been trying the ES8266 before). I don't think this board will actually run what I want it to considering I wanted to try wifi, but oh well...

To connect to ATmega328p I selected Arduino Uno Wifi board and worked for me without pressing the reset buton (pin 3 and 4 on)

1 Like

how to make the communication in series of these two modules, on the uno+wifi, that is to receive the data from the arduino with esp8266?

need help please

Sometimes you need all pins of ATMega, Wifi of ESP and smooth asynchronous communication between them. It works like a charm for me. Do not blame the equipment if your needs do not require it.

1 Like

To solve your problem with programing ESP8266 try:
Programming ESP8266

  1. Power off
  2. Switch 5,6,7 ON
  3. Power ON
  4. Upload
  5. If successful, the Arduino IDE will produce the following message – “Hard resetting via the RTS pin”
  6. Power OFF
  7. Switch 7 OFF

It work for me perfectly.

And thanks dor AT328 hint, you save planty of my time as I can't do it before your instruction.

1 Like

How does the 2 boards communicate?
Are they using Serial?

Does this board support OTA (Over-The-Air) programming like the original Arduino Uno Wifi boards?

Hi,

Why when I try to install Arduino-Master.zip I obtain the following message ?
Error: 13 INTERNAL: Library install failed: moving extracted archive to destination dir: library not valid
Off course I use the link present inside this topic :frowning:

You can get few more related guides here-- ESP8266-wemos-d1-mini-Projects-Using-Arduino

Nice, here is also a nice instructable i found for serial comms with this board. I have had this board since they came out and never had time to actually do anything with it - think its time to dev something :slight_smile: