串口通信。 用串口助手发送hex和utf8的1 都不行
-
import sensor, image, time,pyb
from pyb import UART
import jsonthresholds = [(-5,50, 20, 80, 0, 60), # generic_red红_thresholds
(10, 80, -50, -20, 0, 40), # generic_green绿_thresholds
(15,75, -40, 35, -60, 0)] # generic_blue蓝_thresholds
uart = UART(3, 9600)ledR= pyb.LED(1)
ledG= pyb.LED(2)
ledB= pyb.LED(3)
led= pyb.LED(1) # Red LED = 1, Green LED = 2, Blue LED = 3, IR LEDs = 4.def R():
ledR.on() #亮灯
time.sleep(1000) #延时150ms
ledR.off() #暗灯
time.sleep(500)
def B():
ledB.on() #亮灯
time.sleep(1000) #延时150ms
ledB.off() #暗灯
time.sleep(500)
def G():
ledG.on() #亮灯
time.sleep(1000) #延时150ms
ledG.off() #暗灯
time.sleep(500)sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False) # must be turned off for color tracking
sensor.set_auto_whitebal(False) # must be turned off for color tracking
clock = time.clock()def twoley():
while(True):
clock.tick()
img = sensor.snapshot()
for code in img.find_qrcodes():
img.draw_rectangle(code.rect(), color =(255,0,0))
message =code.payload()
a_er=int(message)
uart.write(message)
print(message)
if a_er==123:
while(True):
R()
G()
B()
print(a_er)elif a_er==132: while(True): R() B() G() print(a_er) elif a_er==213: while(True): G() R() B() print(a_er) elif a_er==231: while(True): G() B() R() print(a_er) elif a_er==312: while(True): B() R() G() print(a_er) elif a_er==321: while(True): B() G() R() print(a_er)
def yanshe():
while(True):
clock.tick()
img = sensor.snapshot()
for blob in img.find_blobs([thresholds[0]], pixels_threshold=200, area_threshold=200):
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(), blob.cy())
a=blob.cx()
for blob in img.find_blobs([thresholds[1]], pixels_threshold=200, area_threshold=200):
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(), blob.cy())
b=blob.cx()
for blob in img.find_blobs([thresholds[2]], pixels_threshold=200, area_threshold=200):
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(), blob.cy())
c=blob.cx()
time.sleep(500)
if a<b :
if a<c :
if b<c :
a_yanse='123'
else :
a_yanse='132'
else :
a_yanse='312'
else :
if b<c :
if a<c :
a_yanse='213'
else :
a_yanse='231'
else :
a_yanse='321'print(a_yanse) uart.write(a_yanse[0]) time.sleep(1000) uart.write(a_yanse[1]) time.sleep(1000) uart.write(a_yanse[2]) time.sleep(1000)
while(True):
if uart.any(): uart.readchar() flag=uart.read()
if flag=='1':
twoley()elif flag=='0':
yanshe()
-
什么叫做不行,请说具体的现象
-
运行之后 一段时间之后画面就定格了, 用串口助手发送0 和1 都不工作。 openmv也一直在工作
-
所以你的问题是如何使用串口接收数据?
-
是的。 还有接受的数据类型 是什么
-
串口的问题,一两句话说不清。
等过两天串口接受的视频上传上去。
-
好吧。 谢谢