README.md
1# UART REPL Example
2
3(See the README.md file in the upper level 'examples' directory for more information about examples.)
4
5This example demonstrates how to use REPL console on a different UART than the default one.
6It also shows how to connect these two UART together, either for testing or for sending commands
7without any human interaction.
8
9## How to use example
10
11### Hardware Required
12
13The example can be run on any ESP board that have at least 2 UARTs. The development board shall be connected to a
14PC with a single USB cable for flashing and monitoring. If you are willing to monitor the console UART, you may use
15a 3.3V compatible USB-to-Serial dongle on its GPIO pin.
16
17### Setup the Hardware
18
19No external connection is needed in order to run the example. However, as stated before, if you are willing to see what
20is going on on the second UART (console UART), you can connect pins CONSOLE_UART_TX_PIN (5 by default) and
21CONSOLE_UART_RX_PIN (4 by default) to a Serial-to-USB adapter.
22
23### Configure the project
24
25The default values, located at the top of `main/uart_repl_example_main.c` can be changed such as:
26DEFAULT_UART_CHANNEL, CONSOLE_UART_CHANNEL, DEFAULT_UART_RX_PIN, DEFAULT_UART_TX_PIN, CONSOLE_UART_RX_PIN,
27CONSOLE_UART_TX_PIN, UARTS_BAUD_RATE, TASK_STACK_SIZE, and READ_BUF_SIZE.
28
29### Build and Flash
30
31Build the project and flash it to the board, then run monitor tool to view default UART's serial output:
32
33```
34idf.py -p PORT flash monitor
35```
36
37(To exit the serial monitor, type ``Ctrl-]``.)
38
39See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
40
41## Example Output
42
43The example will set up the default UART to use DEFAULT_UART_RX_PIN and DEFAULT_UART_TX_PIN. Then, it will set up
44the REPL console on the second UART. Finally, it will connect both UARTs together in order to let default UART
45be able to send commands and receive replies to and from the console UART.
46
47Here is a diagram of what UARTs will look like:
48
49```
50 UART default UART console
51
52USB monitoring <------ TX -----------> RX----+
53 v
54 Parse command
55 and output result
56 | Optional 3.3V
57 RX <----------- TX<---+ (----------->) Serial-to-USB
58 Adapter
59```
60
61If everything goes fine, the output on default UART should be "Result: Success". Else, it should be "Result: Failure".