|
相信會有小伙伴在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()
復制代碼
|
|