赞
踩
用urb线。esp8266队友负责 我只进行上位机发信号
上实验图
发送1成功之后亮灯。(下位机已经写好)
usb口直接供电。板子里面有ch340芯片所以无需再usb转ttl
上代码:
import serial as ser
se=ser.Serial("/dev/ttyUSB0",115200,timeout=1)
se.write(“1”.encode())
1se.write(“0”.encode())
1se.write(“1”.encode())
1
import serial as ser
se=ser.Serial("/dev/ttyTHS1",115200,timeout=1)
se.write("1".encode())
命令:
ls -l /dev/ttyUSB0
crw-rw---- 1 root dialout 188, 0 4月 20 02:37 /dev/ttyUSB0
ls -l /dev/ttyS*
crw–w---- 1 root tty 4, 64 4月 19 13:56 /dev/ttyS0
crw-rw---- 1 root dialout 4, 65 4月 19 13:57 /dev/ttyS1
crw-rw---- 1 root dialout 4, 66 4月 19 13:57 /dev/ttyS2
crw-rw---- 1 root dialout 4, 67 4月 19 13:57 /dev/ttyS3
ls -l /dev/ttyTH*
crwxrwxrwx 1 root tty 238, 1 4月 20 02:30 /dev/ttyTHS1
crw-rw---- 1 root dialout 238, 2 4月 19 13:56 /dev/ttyTHS2
dmesg | grep ttyS*
[ 1.044023] console [ttyS0] disabled
[ 1.044120] 70006000.serial: ttyS0 at MMIO 0x70006000 (irq = 63, base_baud = 25500000) is a Tegra
[ 1.044230] console [ttyS0] enabled
[ 1.045183] 70006040.serial: ttyTHS1 at MMIO 0x70006040 (irq = 64, base_baud = 0) is a TEGRA_UART
[ 1.045561] 70006200.serial: ttyTHS2 at MMIO 0x70006200 (irq = 65, base_baud = 0) is a TEGRA_UART
[ 6.106957] usb 1-2.4: ch341-uart converter now attached to ttyUSB0
[ 36.176037] ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0
[ 85.318975] usb 1-2.4: ch341-uart converter now attached to ttyUSB0
[ 398.416093] ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0
[ 398.667390] usb 1-2.4: ch341-uart converter now attached to ttyUSB0
[ 495.440008] ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0
[ 3356.740326] usb 1-2.4: ch341-uart converter now attached to ttyUSB0
[12633.424098] ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0
:
sudo apt-get install cutecom
sudo cutecom
sudo apt-get install minicom
sudo minicom
import time import serial print("UART Demonstration Program") print("NVIDIA Jetson Nano Developer Kit") serial_port = serial.Serial( port="/dev/ttyTHS1", baudrate=115200, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, ) # Wait a second to let the port initialize time.sleep(1) try: # Send a simple header serial_port.write("UART Demonstration Program\r\n".encode()) serial_port.write("NVIDIA Jetson Nano Developer Kit\r\n".encode()) while True: if serial_port.inWaiting() > 0: data = serial_port.read() print(data) serial_port.write(data) # if we get a carriage return, add a line feed too # \r is a carriage return; \n is a line feed # This is to help the tty program on the other end # Windows is \r\n for carriage return, line feed # Macintosh and Linux use \n if data == "\r".encode(): # For Windows boxen on the other end serial_port.write("\n".encode()) except KeyboardInterrupt: print("Exiting Program") except Exception as exception_error: print("Error occurred. Exiting Program") print("Error: " + str(exception_error)) finally: serial_port.close() pass
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。