logo

openmv如何发送一串16进制的数

2019-04-09 16:51
4
ntiv

我的想法是根据x坐标的大小输出一串16进制数,代码没有报错,但在串口助手里面显示的全是0.代码如下

import sensor, image, time
from pyb import UART

def control(cmd):
    if cmd == '3+L':
        uart.write(bytes(0xFF))
        uart.write(bytes(0x55))
        uart.write(bytes(0x44))
        uart.write(bytes(0xBB))
        uart.write(bytes(0x00))
        uart.write(bytes(0xFF))
    elif cmd == '3+R':
        uart.write(bytes(0xFF))
        uart.write(bytes(0x55))
        uart.write(bytes(0x44))
        uart.write(bytes(0xBB))
        uart.write(bytes(0x00))
        uart.write(bytes(0xFF))
    elif cmd == '3+U':
        uart.write(bytes(0xFF))
        uart.write(bytes(0x55))
        uart.write(bytes(0x44))
        uart.write(bytes(0xBB))
        uart.write(bytes(0x00))
        uart.write(bytes(0xFF))


    return 0

sensor.reset()
sensor.set_pixformat(sensor.RGB565) # grayscale is faster
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()

uart = UART(3, 57600)
uart.init(57600, bits=8, parity=None, stop=1) # init with given parameters

while(True):
    clock.tick()
    img = sensor.snapshot().lens_corr(1.8)
    for c in img.find_circles((0,0,160,120),threshold =2500, x_margin = 10, y_margin = 10, r_margin = 10,r_min = 9, r_max = 100, r_step = 2):
        img.draw_circle((c.x(), c.y(), c.r()), color = (255, 0, 0))
        uart.write(bytes(c.x()))
        print(c.x())
        #uart.write('\xFF')
        uart.write(bytes(0x56))
        uart.write(chr(0xFE))
        #print(bytes(65))

        if c.x() < 22:
            control('3+L')
        if 22 <= c.x() <= 122:
            control('3+U')
        if c.x() >= 122:
            control('3+R')
2019-04-09 21:11
I
网红小智智 星瞳科技

串口助手里面显示的全是0,显然是不对的。

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

你应该先运行教程。

2019-04-10 15:38
4
ntiv

@kidswong999 教程也运行过了,想问一下这个程序有问题吗

2019-04-10 19:05
I
网红小智智 星瞳科技

出现0的地方在于

>>> bytes(10)
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
>>> bytes([10])
b'\n'