logo

运行下面的代码,会有问题

2020-09-23 21:35
2
h4rl

没发现和视频里的原代码有差别,但如果发送“123456”,得到数据不是一整行打印出来的,如果发送“123456\r\n”的话会报错

# Select an area in the Framebuffer to copy the color settings.

import time
from machine import I2C
#from vl53l1x import VL53L1X
from pid import PID
from pyb import UART
import math
clock = time.clock() # Tracks FPS.

# For color tracking to work really well you should ideally be in a very, very,
# very, controlled enviroment where the lighting is constant...

'''
i2c = I2C(2)
distance = VL53L1X(i2c)
'''
x_pid = PID(p=0.5, i=1, imax=100)
d_pid = PID(p=0.05, i=0.1, imax=50)

uart1=UART(3,115200,timeout_char=1000)
#uart2=UART(3, 115200)
#uart2.init(115200, bits=8, parity=None, stop=1)

while(True):
#    clock.tick() # Track elapsed milliseconds between snapshots().

    
    if uart1.any():
        x_error=uart1.readline().decode().strip()
        
        print(x_error)
e0b0e0cf-bd46-4271-b82a-b08b932cfb09.PNG
2020-09-24 18:38
I
网红小智智 星瞳科技

用一下这个代码

import time
from pyb import UART

# Always pass UART 3 for the UART number for your OpenMV Cam.
# The second argument is the UART baud rate. For a more advanced UART control
# example see the BLE-Shield driver.
uart = UART(3, 19200,timeout=1000)

while(True):
    if uart.any():
        print(uart.readline())