当前位置:   article > 正文

【jetsonnano】jetsonnano串口通信与esp8266 cutecom和minicom使用_import serial as ser

import serial as ser

用urb线。esp8266队友负责 我只进行上位机发信号

上实验图
在这里插入图片描述

在这里插入图片描述
发送1成功之后亮灯。(下位机已经写好)
usb口直接供电。板子里面有ch340芯片所以无需再usb转ttl

上代码:

import serial as ser
se=ser.Serial("/dev/ttyUSB0",115200,timeout=1)
se.write(“1”.encode())
1

se.write(“0”.encode())
1

se.write(“1”.encode())
1

import serial as ser
se=ser.Serial("/dev/ttyTHS1",115200,timeout=1)
se.write("1".encode())
  • 1
  • 2
  • 3

命令:

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

cutecom和minicom


sudo apt-get install cutecom

sudo cutecom

在这里插入图片描述

sudo apt-get install minicom
sudo minicom

在这里插入图片描述

附:UART Demo

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/211200
推荐阅读
相关标签
  

闽ICP备14008679号