Programming Arduino UNO clone with built-in WiFi module UNO R3 + WiFi ATmega328P+ESP8266

Andrey Semenyuk
Dev Genius
Published in
8 min readSep 19, 2022

--

or UNO R3+WiFi ATmega328P+ESP8266

There are some unofficial Arduino UNO clones boards with WiFi available on the market. There boards are often look interesting and promising for many projects, as Arduino UNO with WiFi capabilities is not very common.

Sadly, often these boards lack any documentation, so after trying them, many people think they got something that doesn’t work, just because these boards are tricky and you have to know how to work with them.

In this story I summarized my experience working with these boards, as I found that there is a lack of a good document summarizing all information together, so if you got one of these boards and not sure how does it work, then this article is for you.

Understanding chips on this board

First, let’s have a closer look at the board. In fact, these boards may sometimes look differently and have some variations, so picture above shows just most popular variant, but even if there are differences, in general it will be something similar anyway.

Chip marked with number one is CH340 USB-to-serial adapter, so you have to have corresponding driver installed, if your computer can’t recognize this board, when you plug it in via USB. If not sure what is CH340 and how it’s driver needs to be installed, then I got you covered in this article.

Marked with number two is ATmega328P — the core and brain of Arduino, which runs all your sketches. This chip could look differently on different boards — sometimes it’s big, as on original Arduino UNO, sometimes smaller, but it is still the same chip, just packaged in different cases.

Marked with number three are dip switches, and these switches are very important for understanding how to work with this board, so we will have detailed look on on them later, right now just bear in mind their importance.

Number four is ESP8266 — chip which bears WiFi module.

ESP8266

ESP8266 is not just a WiFi chip, but actually is powerful microcontroller, with it’s own IO pins, CPU core and memory. In fact, ESP8266 is more powerful, than Arduino’s ATmega328P and the only reason board like this are advertised like “Arduino with built-in WiFI” instead of “ESP8266 with built-in Arduino” is just because Arduino is better known to general audience, especially people who just starting with microcontrollers. Arduino is well-know name and after all, Arduino is not just about a microcontroller, it is a more about form-factor, about being able to plug shield into a board. And as this board follows Arduino board specification, we call it Arduino equipped with WiFi, although from another perspective there is no such thing as “main” chip on this board and ATmega328P works completely independently from ESP8266, as we will see later.

ESP8266 pins

So nothing can stop you from completely ignoring Arduino’s ATmega328P and work with ESP8266 only. You can’t use standard Arduino pins in this case, but on the other hand — there are several pins for ESP8266 on this board, you can see on this picture. You’ll find ESP pin markings on the back of the board.

This is very important and I will stress it here:

There is no main chip on this board by design. Both chips can work independently. You can work with ATmega328P only, or with ESP8266 only, and ignore another chip completely. Or you can use both chips and control one of them by the program running on another one. It is up to you how you will design your solution and which way you prefer. Below we will look on few patterns.

Switches

But if there two chips on the board, then which chip is connected to USB port and how can you select which chip to flash? This is why there are DIP switches on the board — by switching them ON or OFF you can select which chip is currently connected to CH340, which means — which chip you can flash or connect to. Please refer to a table below for correct switches setup. Please note, that switch 8 is not used, so I just skipped it in the table below.

Please be patient and don’t flash any sketches on ESP8266 yet, just finish this article first. The reason is — there might be AT firmware already flashed there and you might want to keep it. Or maybe not. You’ll decide yourself by the end of this article.

DIP switches configuration

In other words:

  • to connect your computer to ESP8266 via USB, turn switches 5, 6 ON and all others OFF, except switch 7 which has special meaning here because it is connected to IO port 0 of ESP8266: when turned OFF, it will switch ESP8266 to a serial connection mode, and when turned ON, it will boot ESP8266 in a flash mode.
  • to establish serial connection from your computer to ATmega328 via USB set switches 3 and 4 ON and all others OFF
  • to connect ESP8266 and ATmega328 together with no connection to CH340 (meaning that you will not be able to connect to chips via USB) turn switches 1 and 2 ON and all others OFF
  • and finally, if for some reason you don’t want chips to be connected at all and prefer them all working independently — just switch everything OFF

Programming ATmega328P

There is really not much to say here, just set your switches accordingly, as shown on the table above, and work with this board as with any other Arduino, because when you’ll set switches, it will become nothing more, then just another Arduino clone.

As main topic of this article is to show you how to work with this type of board, rather than teach you basics of Arduino programming, I will skip it here, as there are tons of good articles about Arduino programming, just google around.

If you need help working with this Arduino clone bearing CH340 chip, please see my article here.

Programming ESP8266

Please be patient and don’t flash any sketches on ESP8266 yet, just finish this article first. The reason is — there might be some firmware already flashed there and you might want to keep it. Or maybe not. You’ll decide yourself, by the end of this article.

First of all, don’t forget to change switches to the correct position for uploading sketch to ESP8266, as described in the table above. And don’t forget to reboot the board, as pin 7 for ESP8266 which selects flash or com mode will be making any effect only during ESP8266 boot.

Patterns of solution design for this board

Architecture of this board bearing independent chips that can be connected together in different configurations, allows us apply different patterns for our solutions.

Pattern 1: Arduino only

One of the simplest things will be — just use it as any other Arduino and simply ignore ESP8266. These boards are cheap, after all, so if for some reason you can’t get any other Arduino clone, why not use this one? While it can feel just like a waste of a board potential, this approach is used in many applications all around us.

Pattern 2: ESP8266 only

And vice versa — if you have a sketch for ESP8266, then why not run it on this board and just ignore ATmega chip? Or instead, if your goal is to develop a new sketch for ESP8266, then this board can be used as a development board, where you can also use CH340 for debugging or communication purposes. After all, ESP8266 is more powerful, than Arduino’s ATmega, so probably opting to ESP8266 instead of ATmega328p makes sense.

Pattern 3: Arduino with built-in WiFi with AT firmware

Many of these boards are advertised as an “Arduino with WiFi”, assuming that you wish easily add WiFi capabilities to your Arduino project. In order to do this, many of these boards come with an AT firmware preinstalled on the ESP8266, making it compatible with AT command set. So you can easily control ESP8266 by sending AT commands from an Arduino chip.

It is very simple and easy way of adding WiFi to your Arduino solution, and there is only one disadvantage: you are dedicating much more powerful ESP8266 to be nothing more than just WiFi modem, which can make heart of a perfectionist bleed.

Pattern 4: Combined Arduino plus ESP8266 solution

And the last pattern that you can apply — just use both chips on this board to run two separate sketches. This way it will be heterogeneous multiprocessing board, which allows you to run different sketches on different CPU cores at the same time. Some tasks may run on one chip and other tasks on another one, depending on how you will program it.

This might be a bit tricky to develop, but on the other hand it will be very interesting journey. The challenge is, that these chips have different architectures, so you have to keep this in mind, while working with them.

And keep in mind that it is not possible to upload sketches on both chips at once — you will have to change switches for programming one chip first, then upload first sketch, then change switches for the second chip, upload second sketch, and then probably change switches to connect chips together, as probably your solution requires some communication between sketches. A lot of annoying switches, isn’t it?

To minimize switch configuration, it might be better to develop your solution in stages: one sketch first and then another one, but if both sketches are really tightly coupled and require a lot of intercommunication, you may want to start with a sort of a dummy mock sketch for one of the chips, which will mock it’s functionality allowing you to proceed with development of a sketch for another chip, and then get back to the first chip and replace your mock with something real.

Debugging

Of corse sooner or later you’ll probably want some debug output from your project. In a typical Arduino sketch this is often achieved by printing to serial port, but on this board this will work only if you are using it as typical Arduino clone, pretending there is no ESP8266 chip on the board. In this case you just set pins as described in a table above to connect ATmega328 to CH340, and that’s it.

But if you are using this board instead of a typical Arduino clone, then this is probably for a reason that you want to use ESP8266 chip for whatever reason, is it just it’s WiFi capabilities or if you are running some sketch on it. But in that case your ESP8266 must be connected to ATmega328 instead of CH340, which means you will not be able to get a serial connection to ATmega328, so here’s a couple of ways to go:

1. Use LCD

One of the simplest ways to go, but unfortunately not always possible is to just plug one of the LCD modules available on the market into Arduino pins and just use it for debug output. However, this is only possible if you are not using any other Ardiuno shields and only if you need debug output from your ATmega328 (Arduino). If you need any output from ESP8266, then this method will not work (unless you program some weird way of channelling your ESP8266 debug messages to ATmega328, which will print them on LCD)

2. Use pins

If method above doesn’t work for you, then the only way to go is to use Arduino and/or ESP pins for debug signals

Wrap up

So, that’s it about these boards. Although to someone they may look like a weird Frankenstein monsters, actually they are powerful boards which can bring new capabilities to your projects!

--

--

Solution Architect. Love explore everything new, both in tech and new places on the planet.