Wireless Serial (UART) for Arduino/STM32/etc.
by MartinD_CZ in Circuits > Wireless
14177 Views, 66 Favorites, 0 Comments
Wireless Serial (UART) for Arduino/STM32/etc.
Hopefully everybody will agree with me that the Arduino Serial is a great tool for debugging your projects. Well, it's basically the only option for debugging an Arduino. But sometimes, it is not possible or practical to run a USB cable from the Arduino or any other microcontroller into your computer.
So I made this UART-WiFi board, based on the ESP8266-01, which is dirt cheap these days. The boards is small, you can plug it into a breadboard, connect power, RX, TX and ground and it will transmit everything it receives from the UART to you computer via WiFi and vice versa.
Features:
- baudrates up to 115200 (theoretically even up to 921600, but this is not tested)
- receives/sends data from UART and sends/receives data via WiFi directly to your computer using port 23 (Telnet)
- 18 components, parts cost about USD 3.50
- 20 x 45 mm dual sided PCB, breadboard compatible
- 5 V tolerant RX pin
- voltage input from 12 V to 3.3 V, current draw about 80 mA on average
I have been using these boards for about half a year now and I found them extremely useful. I even prefer them to USB-UART bridges, because with my board, I just plug one of them into a breadboard and I do not need to worry about running cables all across my desk. You also do not any any other hardware, no free USB ports and these boards provide full galvanic isolation from your computer, which is a good safety precaution and you do not need to worry about different ground potentials.
How It Works
Once power is applied to the module, it starts trying to connect to the predefined WiFi. During that phase, the yellow LED is blinking. Once it connects, the yellow LED stays lit. After that, the module is awaiting a connection from a Telnet client (see next step) and green LED is blinking. After the connection is successfully established, the Telnet terminal shows you a prompt, asking about the desired baudrate. You input the baudrate into the terminal and you are finished! Now anything you type into the terminal gets send over WiFi and then it is outputted from the TX pin of the ESP8266. Similarly, anything appearing on the RX pin is send to the terminal. Basically, you can't tell the difference between a serial and telnet console.
LEDs:
- yellow (leftmost) - Wifi status, blinking - trying to connect, lit - connected
- green (second from left) - Telnet status. blinking - awaiting connection, green - connected
- blue (two rightmost ones) - RX and TX
How to Set It Up
Connection
The only slight complication is that you need some sort of an identifier for every Telnet device (similar to every serial port having a number). In my project I used Static IP. Normally, once a device connects to WiFi, it automatically receives an IP address from the DHCP server. This is called dynamic IP addressing, but the problem here is that the IP address might change. So I programmed the board in such a way that it always receives a predefined IP address, in my case 192.168.2.20x, where x is the board number. This is called Static IP addressing. Then you just connect a Telnet console to 192.168.2.20x:23 and you are ready to go.
As a console you can use a variety of apps, the two best known are probably PuTTY or YAT (Yet Another Terminal). I use the latter and in the picture section you can see how to set it up - you just need to know the previously mentioned Static IP address.
Firmware
The firmware is written in Arduino IDE and you can find it on my GitHub. If you wish to program your ESP8266, you need to look into the header and modify some variables there, namely:
- ssid - the name of the WiFi you wish the board to connect
- pass - password for that WiFi
- ip - the static IP you wish the board to have; choose something outside of the DHCP pool (or just choose something between 200 - 250, that is usually free)
- gateway - the IP of your router
- subnet
You can get the last two information from command line, by pressing Win + R, typing in "cmd" and then typing in "ipconfig". See pictures.
Of course you need the Arduino IDE, esp8266 toolchain etc., but there are many other tutorials about that.
Board
You also need to manufacture the PCB. While it is not complicated and you could theoretically make it at home, I recommend that you use some Chinese PCB manufacturer. It is cheap and works nice. I used ALLPCB and was satisfied.
Power
You need to provide power to the board. You can either power it directly with 3.3 V (jumper JP1 in the 3.3 V position) or feed the voltage thru a 3.3 V regulator (jumper in the other position). The regulator can accept voltages up to 12 V. All capacitors are already integrated onboard.
Conclusion
As I said before, I found these boards very useful for prototyping, not only with an Arduino, but with any MCU in general. And I have been using them for about half a year now and I did not have a problem with them.
Source code, Eagle files and some pictures can be found either on my GitHub or in the zip file below. But I recommend GitHub, since there might be a newer version.
If you have any questions, comments or suggestions, feel free to leave them below.