logo

串口输出坐标,为什么会失败

2022-04-24 00:11
K
_2nc3
import sensor, image, time
from machine import UART

uart = UART(2, baudrate=115200) 
uart_num = 0   
uart_array = [48,49,50,51,52,53,54,55,56,57]
uart.write(uart_num.to_bytes(1, 'little')) 
uart.write(bytearray(uart_array))
uart.write(bytearray([0x41]))       # 发送一个十六进制数据
sensor.reset()
sensor.set_pixformat(sensor.RGB565) # grayscale is faster
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()

while(True):
    uart_num = uart.any()
    clock.tick()
    img = sensor.snapshot().lens_corr(1.8)

    # Circle objects have four values: x, y, r (radius), and magnitude. The
    # magnitude is the strength of the detection of the circle. Higher is
    # better...

    # `threshold` controls how many circles are found. Increase its value
    # to decrease the number of circles detected...

    # `x_margin`, `y_margin`, and `r_margin` control the merging of similar
    # circles in the x, y, and r (radius) directions.

    # r_min, r_max, and r_step control what radiuses of circles are tested.
    # Shrinking the number of tested circle radiuses yields a big performance boost.

    for c in img.find_circles(threshold = 2000, x_margin = 10, y_margin = 10, r_margin = 10,
            r_min = 2, r_max = 100, r_step = 2):
        img.draw_circle(c.x(), c.y())
    if(uart_num):
        uart_str = uart.read(uart_num)
        uart.write(uart_str)
2022-04-25 20:07
I
网红小智智 星瞳科技

我运行代码,报错是ValueError: UART(2) doesn't exist,请提供具体的硬件型号。

2022-04-28 20:40
K
_2nc3

改成串口2了,那再怎么版

2022-04-28 21:07
I
网红小智智 星瞳科技

@2nc3 你为什么用串口2,硬件上就没有串口2啊。

先按照视频测试。

https://singtown.com/learn/50235/

2022-04-29 19:06
K
_2nc3

说错了,用的是三

K
_2nc3

就是有没有办法将遍历出来的圆的中心坐标一个个地表示出来,

2022-04-30 19:59
I
网红小智智 星瞳科技

@2nc3 看视频了吗,视频里有怎么拼装字符串。