|
相信会有小伙伴在STM32和OPENMV的串口通信上存在一些问题
STM32发送数据时,像发东西上串口调试助手那样就OK,OPENMV接收数据时,直接按官方例程写就行。
但STM32接收时,OPENMV发送时,如果像例程那样写就会出现一些问题,
这两份代码能够实现OPENMV和STM32的稳定通信。
- # QRCode Example
- #
- # This example shows the power of the OpenMV Cam to detect QR Codes
- # without needing lens correction.
- import sensor, image, time, pyb
- led3=pyb.LED(3)
- led2=pyb.LED(2)
- uart=pyb.UART(3,115200,timeout_char = 1000)
- sensor.reset()
- sensor.set_pixformat(sensor.RGB565)
- sensor.set_framesize(sensor.QVGA)
- sensor.skip_frames(time = 2000)
- sensor.set_auto_gain(False) # must turn this off to prevent image washout...
- clock = time.clock()
- while(True):
- clock.tick()
- img = sensor.snapshot()
- img.lens_corr(1.8) # strength of 1.8 is good for the 2.8mm lens.
- for code in img.find_qrcodes():
- img.draw_rectangle(code.rect(), color = (255, 0, 0))
- led3.on()
- if code[4] == '11':
- uart.write("l")
- if code[4] == '21':
- uart.write("R")
- time.sleep(150)
- led3.off()
- if uart.any():
- a = uart.readline().decode().strip()
- if a == 'OK':
- led2.on()
复制代码
|
|