├── LICENSE
├── README.md
└── uart_example.py
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 JetsonHacksNano
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # UART Demo Code
2 |
3 | This is currently a simple Python 3 script to interface with the UART on the J41 header of the NVIDIA Jetson Nano Developer Kit.
4 |
5 | Original article on JetsonHacks: https://wp.me/p7ZgI9-31I
6 |
7 |
Before You Start
8 | The stock Jetson Nano starts a console on the ttyTHS1 serial port at startup through a service. The script that starts the service is nvgetty.sh which launches getty. The script is located in /etc/systemd. While this does not conflict with the script presented here, consider disabling the console if you are using the serial port to avoid conflicts. Note that normal udev rules will be overridden by the console while the service is running. To disable the console:
9 |
10 | ```
11 | $ systemctl stop nvgetty
12 | $ systemctl disable nvgetty
13 | $ udevadm trigger
14 | # You may want to reboot instead
15 | ```
16 |
17 | The Demo Script
18 |
19 | The script opens up the serial port ( /dev/ttyTHS1 ), writes a simple header on the serial port, and then will echo any characters it receives from the serial port back. When the script is terminated with ^C, the script will close the port.
20 |
21 | One easy way to use the script is to connect the Jetson Nano to a PC/Mac/Linux box via a TTL to USB cable. The Jetson Nano signal is 3.3V. Run a serial tty program on the PC to interface with the serial port, and then interact with the Jetson Nano.
22 |
23 | The script requires py-serial. To install py-serial:
24 |
25 | ```
26 | $ sudo apt-get install python3-serial
27 |
28 | ```
29 | Then to run the script:
30 |
31 | ```
32 | $ sudo python3 uart_example.py
33 |
34 | ```
35 |
36 | Notes
37 |
38 | Initial Release October 2019
39 |
40 | - L4T 32.2.1/JetPack 4.2.2
41 | - Python 3
42 |
43 |
44 |
--------------------------------------------------------------------------------
/uart_example.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python3
2 | import time
3 | import serial
4 |
5 | print("UART Demonstration Program")
6 | print("NVIDIA Jetson Nano Developer Kit")
7 |
8 |
9 | serial_port = serial.Serial(
10 | port="/dev/ttyTHS1",
11 | baudrate=115200,
12 | bytesize=serial.EIGHTBITS,
13 | parity=serial.PARITY_NONE,
14 | stopbits=serial.STOPBITS_ONE,
15 | )
16 | # Wait a second to let the port initialize
17 | time.sleep(1)
18 |
19 | try:
20 | # Send a simple header
21 | serial_port.write("UART Demonstration Program\r\n".encode())
22 | serial_port.write("NVIDIA Jetson Nano Developer Kit\r\n".encode())
23 | while True:
24 | if serial_port.inWaiting() > 0:
25 | data = serial_port.read()
26 | print(data)
27 | serial_port.write(data)
28 | # if we get a carriage return, add a line feed too
29 | # \r is a carriage return; \n is a line feed
30 | # This is to help the tty program on the other end
31 | # Windows is \r\n for carriage return, line feed
32 | # Macintosh and Linux use \n
33 | if data == "\r".encode():
34 | # For Windows boxen on the other end
35 | serial_port.write("\n".encode())
36 |
37 |
38 | except KeyboardInterrupt:
39 | print("Exiting Program")
40 |
41 | except Exception as exception_error:
42 | print("Error occurred. Exiting Program")
43 | print("Error: " + str(exception_error))
44 |
45 | finally:
46 | serial_port.close()
47 | pass
48 |
--------------------------------------------------------------------------------