Hardware debugging and programming via UART/Serial connection has always been something so vital to hardware developers and even other team players like QA engineers. In certain circumstances, the device that needs to be debugged or programmed is not reachable by wires. I remember how QA engineers in my previous job had to come up with a Bluetooth adapter to bridge the serial debugging information of the tested products because it was fixed inside the car dashboard and can’t be reached out. In this article, it’s time to make some serial data fly over the air!

Serial Bridge Using ESP8266

One of the most well-known (appeared on Hackaday’s blog) and well-designed projects to make ESP8266 as a WiFi-UART bridge is jeelabs’s esp-link. Actually, this project is far beyond being a simple serial bridge as it also manages MQTT client pub/sub and REST HTTP requests in order to connect the MCU to the internet. Moreover, it can be used to flash the attached MCU. Esp-link has a very handy web interface stored inside the ESP.

To make the test, we will use ESP8266 development board, specifically NodeMCU.

Prepare The Software

First, we need to download one of the release images of the project from releases page. The compressed file (A .tgz file is beside the download word in bold) should have 5 bin files :blank.bin, boot_v1.x.bin, esp_init_data_default.bin, user1.bin and user2.bin. The ESP8266 board should be connect after downloading one of the available download tools like: Flash download tool from Espressif or Nodemcu flasher.

Now, follow the flashing guidelines available in Readme file according to your ESP8266 edition and set the bin files addresses according to your module memory size.

You can simply make the Flash download tool from Espressif find it for you by connecting it and pressing “start” to get the required specification from the boot message.

Alternatively, you can read the boot message using a serial console with 76600 baud.

After flashing the image files successfully, you should see a new WiFi network.

Connect to it and type this IP address into the browser http://192.168.4.1 . Now, you should see the home page.

Prepare The Hardware

To test the serial bridge code, we will achieve the following connection: TX0 from ESP with RX of the device and RX0 with TX of the device that sends serial information and needed to be bridged via WiFi. For the sake of the test, the device here would be a USB-TTL cable (USB-UART converter) and the data will be sent and received from a console (PUTTY for instance).

Finally, I think a considered amount of time is needed to explore the other options of this amazing project!

Serial Bridge Using ESP8266 (Simpler)

The previous project could be too complicated to do the simple job of converting Serial connection to a WiFi connection. So I decided to port a project described in the rest of this article written in Arduino. The ported code works on ESP8266 and can be download from here:

The explanation in the next section should be followed to know who to use it but with ESP8266, where simply by using a specific IP/Port via a Tellnet connection, the Serial data can be reached out.

Serial Bridge Using ESP32

A project via Github presents a WiFi to Serial bridge for the 3 UART ports available in ESP32. This project is written using Arduino IDE and supports ESP32 as an access point (AP) that broadcasts a specific WiFi network with predefined SSID and password in the code or a station. However, every UART port on ESP32 is accessible after making a WiFi connection with ESP32 via a specific IP and port.

Let’s prepare the needed software and hardware to test this project.

Prepare The Software

As the project uses Arduino SDK with ESP32 core, then we need to add Arduino core for the ESP32 to the Arduino environment. The official documentation of ESP32 core from Espressif has an installation guide, but the easiest way to add this core is to download the repo as a zip file then decompress it in the following directory:

(Windows) \Documents\Arduino\hardware\espressif\esp32

(Linux) folder is named “Sketchbook” and it is typically located in /home/

The next step is to get the compilation tool-chain xtensa-esp32-elf by executing one of the get.exe or get.py files available in the tools folder according to your machine type.

To test this all together, open the Arduino IDE and check the Tools>boards menu

Now, testing the compilation of a simple program is needed also. The following test code can be used.

C++

1

2

3

4

5

6

7

8

9

10

11

12

#define PIN_LED 1 // built_in

voidsetup()

{

pinMode(PIN_LED,OUTPUT);

}

voidloop()

{

digitalWrite(PIN_LED,HIGH);

delay(1000);

digitalWrite(PIN_LED,LOW);

delay(1000);

}

Prepare The Hardware

To test the serial bridge code, we will do the following connection: TX0 from ESP with RX of the device and RX0 with TX of the device that sends the serial information and needed to be bridged via WiFi. For the sake of the test, the device here would be a USB-TTL cable (USB-UART converter) and data will be sent and received from a console (PUTTY for instance).

Now download the Arduino code from Github and upload it to ESP32. Choose from Tools>boards>ESP Dev Module. Many things can be configured before uploading the code to ESP32 like choosing the working mode as a station or an access point and many other things.

C

1

2

3

#define MODE_AP // phone connects directly to ESP

//#define MODE_STA // ESP connects to WiFi router

If no changes are done, the bridge will broadcast a WiFi network with SSID “LK8000” and password “Flightcomputer”. Connect to the WiFi network and open the Putty program then use the following setups: one for the Serial connection for the USB-UART converter.

And another to connect to the WiFi server using one of the following IP/Port according to the used UART port.

192.168.4.1:8880 for UART0

192.168.4.1:8881 for UART1

192.168.4.1:8882 for UART2

Now, open the two consoles and try the magic!

Note: Telnet connection can be done from a smartphone by using Telnet client application like Termius or any other working application.

Embedded Hardware Engineer interested in open hardware and was born in the same year as Linux. Yahya is the editor-in-chief of Atadiat and believes in the importance of sharing free, practical, spam-free and high quality written content with others. His experience with Embedded Systems includes developing firmware with bare-metal C and Arduino, designing PCB&schematic and content creation.

Hi!
Thank you very much for this. How do I use this to display my programatically generated debug serial messages from my sketch?
Typing in the wifi and COM terminal windows work as expected, but the messages that my sketch sends to the COM terminal is not mirrored in the wifi putty connection.

Hi,
I tried something like that but I blocked on some limitation.. I need to connect UART @1,2Mbps and send A LOT OF DATA in continue!
So my data are OK @ 250kbps but @ 1,2Mbps there is a lot of errors :/
Anybody did try that ?
What can I do to make it better ?
Maybe on IDF ?
Thanks for your help,

Hi. I tried your project on ESP32. In config.h changed the speed to 115200. There was a problem when transmitting large amounts of data . The first 12 kB file is transmitted normally. Then, after a pause, the same file is transmitted with errors. The further you go , the more mistakes you make . Then it stops transmitting even single bytes at all. It looks like the memory is filling up somewhere and not being cleared. I couldn ‘t figure out the code myself. Can you help? A very necessary device

Advertisement

Follow Us

About

With passionate staff, Atadiat believe that Electronics is a practical domain and related content must be fine and practical. We aim to provide a new content experience with marketing related to electronics to our audience.