这是我写的openmv的代码,不涉及openmv向stm32发送信息,已经成功烧到了openmv4里面,是可以亮蓝灯的,我感觉我写的应该没大有问题,但是无法和stm32进行通讯,感觉接收不到stm32的信息,stm32usart1这个串口有跳线帽的时候,串口调试助手上是可以看到返回了字节符的,想请问一下是什么原因呀?
import sensor, image, time, lcd, json,math,ujson
from pyb import LED
from pyb import UART
red_led = LED(1)
green_led = LED(2)
blue_led = LED(3)
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA) # Special 128x160 framesize for LCD Shield.
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False) # must turn this off to prevent image washout...
uart = UART(3, 115200)
uart.init(115200, bits=8, parity=None, stop=1)
while(True):
da=3
img = sensor.snapshot()
img.lens_corr(1.8) # strength of 1.8 is good for the 2.8mm lens.
if(uart.any()):
time.sleep(200)
d=uart.readline().decode().strip()
da=int(d)
if(da==1):
green_led.off()
blue_led.off()
red_led.on()
time.sleep_ms(1000)
print('red')
else:
if(da==2):
red_led.off()
blue_led.off()
green_led.on()
time.sleep_ms(1000)
print('green')
else:
if(da==3):
red_led.off()
green_led.off()
blue_led.on()
time.sleep_ms(1000)
print('blue')
连线是这个样子的,麻烦大家了,拜托了
在OpenMV端,只写读取的代码,然后print看一看有没有数据。
@kidswong999
您好,我没有改变源代码,采用了这样的接线方式,在IDE上进行观察,发现在未在串口调试助手(xcom)发送1时,可以在串行终端看到blue的输出,但是一旦我发送了1,blue就不再输出




import sensor, image, time, lcd, json,math,ujson
from pyb import LED
from pyb import UART
red_led = LED(1)
green_led = LED(2)
blue_led = LED(3)
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA) # Special 128x160 framesize for LCD Shield.
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False) # must turn this off to prevent image washout...
uart = UART(3, 115200)
uart.init(115200, bits=8, parity=None, stop=1)
while(True):
img = sensor.snapshot()
img.lens_corr(1.8) # strength of 1.8 is good for the 2.8mm lens.
if(uart.any()):
print('red')但要是这么写的话,串行终端是有red输出的,连接方式和上图一样
@u261 在 [openmv和stm32串口通讯未成功,想请教一下原因?](/post/19209) 中说:
> @kidswong999
> 您好,我没有改变源代码,采用了这样的接线方式,在IDE上进行观察,发现在未在串口调试助手(xcom)发送1时,可以在串行终端看到blue的输出,但是一旦我发送了1,blue就不再输出,并且帧缓冲区画面停止



您好,我现在已经可以成功运行了
import sensor, image, time, lcd, json,math,ujson
from pyb import LED
from pyb import UART
red_led = LED(1)
green_led = LED(2)
blue_led = LED(3)
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA) # Special 128x160 framesize for LCD Shield.
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False) # must turn this off to prevent image washout...
uart = UART(3, 115200)
uart.init(115200, bits=8, parity=None, stop=1)
while(True):
da=3
img = sensor.snapshot()
img.lens_corr(1.8) # strength of 1.8 is good for the 2.8mm lens.
if(uart.any()):
d=uart.readline().decode().strip()
da=int(d)
if(da==1):
green_led.off()
blue_led.off()
red_led.on()
time.sleep_ms(1000)
print('red')
else:
if(da==2):
red_led.off()
blue_led.off()
green_led.on()
time.sleep_ms(1000)
print('green')
else:
if(da==3):
red_led.off()
green_led.off()
blue_led.on()
time.sleep_ms(1000)
print('blue')要删掉一行代码, if(uart.any()):后面删去 time.sleep(200),是我延时太长了 ,反应的有些慢:smiling_face_with_open_mouth_cold_sweat: ,谢谢小助手!!!