备战电赛K210篇(第三天)

okok,也是实现了K210和STM32的通信

学习自b站小黑,和博主“”变优秀吧“”————写的是非常全面容易理解,爆赞!!!

要注意对于你发送的数据进行,分析——帧头,帧尾。(32)

void USART1_IRQHandler(void)                	
{
 static int i=0;//静态变量
	if(USART_GetITStatus(USART1,USART_IT_RXNE) != RESET)//判断是否有数据
	{
			MyData[i++] = USART_ReceiveData(USART1);//接收
		if(MyData[0] != 0xa3) i=0;//
		if((i == 2) && (MyData[1] !=0xb3)) i=0;//判断
		if(i == 6)
		{
			if( data_teat(MyData))//判断合理性
			{
				num=MyData[2];
				x=MyData[3];
				y=MyData[4];//存储
			}
			i=0;
		}
	}
} 

K210:

##########发送
def sending_data(num,x,y):
    FH= bytearray([ 0xa3 , 0xb3 , num , x , y ,0xc3 ])
    uart_A.write(FH);

先来记记K210上的代码:
 

import time                 
import sensor                #摄像头
import lcd, image            #lcd和图像
from machine import UART     #串口
from fpioa_manager import fm #定义Pin10用于发送

lcd.init()
lcd.init(freq = 15000000)#频率
sensor.reset()           #摄像头初始化
lcd.init(type=2)  
lcd.rotation(2)
sensor.set_pixformat(sensor.RGB565)       #图像颜色  
sensor.set_framesize(sensor.QVGA)         #分辨率240×320
sensor.set_auto_gain(False)               #自动增益
sensor.set_auto_whitebal(False)           #白平衡

sensor.run(1)
Range = (0,0,160,120)                     #识别区域(不要以后就)
##########################################################配置 9600 八位 不校验 一位停止位 串口接收超时时间 串口接收缓存

fm.register( 10,fm.fpioa.UART1_TX, force=True )
uart_A = UART(UART.UART1,115200,8,0,1, timeout = 1000, read_buf_len=4096)  #舒适化串口

##########发送
def sending_data(num,x,y):
    FH= bytearray([ 0xa3 , 0xb3 , num , x , y ,0xc3 ])
    uart_A.write(FH);

##########################################################
#for i in range(200):
   #img=sensor.snapshot()
   #img.draw_rectangle((150,100,30,30),color=(255,255,255))#圈出搜寻区域
   #Statistics = img.get_statistics(roi=(200,100,30,30)) #得到统计信息
   #Threshold = [Statistics.l_min(),Statistics.l_max(),
                #Statistics.a_min(),Statistics.a_max(),
                #Statistics.b_min(),Statistics.b_max(),]
   #print(Threshold)
   #lcd.display(img)
###########################################################
x=0
y=0
num=0
print("发送OK================")
while True:
    #img=sensor.snapshot()
       ##找色块
    #for blob in img.find_blobs([Threshold],roi=Range,pixels_threshold=100,area_threshold=100,merge=True,margin=10):
       #img.draw_rectangle(Range)#画框
       #img.draw_rectangle(blob.rect())#画框
       #img.draw_cross(blob.cx(),blob.cy())#十字
       #print(blob.cx(),blob.cy())
       #lcd.display(img)
    num+=1;
    x+=2;
    y+=3; 
    sending_data(num,x,y)
    print("num:",num,"x:",x,"y:",y)
    time.sleep_ms(1000)

下面是代码:

import time
import sensor
import lcd, image
from machine import UART
from fpioa_manager import fm

lcd.init()
lcd.init(freq = 15000000)
lcd.init(type=2)
lcd.rotation(2)

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)#灰度
sensor.set_framesize(sensor.QVGA)#分辨率240×320
sensor.set_auto_gain(False)#自动增益
sensor.set_auto_whitebal(False)#白平衡
sensor.skip_frames(time=3000)#跳过3000张图片
sensor.run(1)
#########################################
Range1 = (0,100,320,16)
Range2 = (0,180,320,8)
black_my=(42, 22, -9, 10, 10, -18)
Flag=0        #判断开始
##########################################################配置 9600 八位 不校验 一位停止位 串口接收超时时间 串口接收缓存

fm.register( 10,fm.fpioa.UART1_TX, force=True )
uart_A = UART(UART.UART1,115200,8,0,1, timeout = 1000, read_buf_len=4096)

##########发送
def sending_data(num,x,y):
    FH= bytearray([ 0xa3 , 0xb3 , num , x , y ,0xc3 ])
    uart_A.write(FH);

##########################################################

###########################################################

print("发送OK================")
while True:
    img=sensor.snapshot()
    
    are1 = img.find_blobs([black_my],roi=Range1,area_threshold=200,merge=True)
    #are2 = img.find_blobs([black_my],roi=Range2,area_threshold=120,merge=True,margin=120)
     #are1寻迹  are2判断路口
    if are1:
        for blob in are1:
           #blob[0]_颜色外框X 
           #blob[1]_颜色外框Y
           #blob[2]_颜色外框W宽度7#判断起始
           #blob[3]_颜色外框H高度
           #blob[4]_像素数量
           #blob[5]_中心坐标X
           #blob[6]_中心坐标Y
           tmp=img.draw_rectangle(blob[0:4])#画框
           tmp=img.draw_cross(blob[5],blob[6])#十字
           c=img.get_pixel(blob[5],blob[6])
           print(blob.cx(),blob.cy())
           
    lcd.display(img)
    
    #sending_data(num,x,y)
    #print("num:",num,"x:",x,"y:",y)
    #time.sleep_ms(1000)

现在学习都是抄别人的,再加以改进等等,加油加油!!!

王者我来了

 

  • 50
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值