• OpenMV VSCode 扩展发布了,在插件市场直接搜索OpenMV就可以安装
  • 如果有产品硬件故障问题,比如无法开机,论坛很难解决。可以直接找售后维修
  • 发帖子之前,请确认看过所有的视频教程,https://singtown.com/learn/ 和所有的上手教程http://book.openmv.cc/
  • 每一个新的提问,单独发一个新帖子
  • 帖子需要目的,你要做什么?
  • 如果涉及代码,需要报错提示全部代码文本,请注意不要贴代码图片
  • 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
  • 1:OpenMV端引入串口通信模块,运行速度变的巨慢? 串口传输length信息到stm32端,为什么会这样报错



    • openMV端代码:

      # Measure the distance
      #
      # This example shows off how to measure the distance through the size in imgage
      # This example in particular looks for yellow pingpong ball.
      
      import sensor, image, time
      
      from pyb import UART
      
      uart=UART(3,9600)
      # For color tracking to work really well you should ideally be in a very, very,
      # very, controlled enviroment where the lighting is constant...
      red_threshold  = (13, 49, 18, 61, 6, 47)
      # You may need to tweak the above settings for tracking green things...
      # Select an area in the Framebuffer to copy the color settings.
      
      sensor.reset() # Initialize the camera sensor.
      sensor.set_pixformat(sensor.RGB565) # use RGB565.
      sensor.set_framesize(sensor.QQVGA) # use QQVGA for speed.
      sensor.skip_frames(10) # Let new settings take affect.
      sensor.set_auto_whitebal(False) # turn this off.
      clock = time.clock() # Tracks FPS.
      
      K=730#the value should be measured
      
      while(True):
          clock.tick() # Track elapsed milliseconds between snapshots().
          img = sensor.snapshot() # Take a picture and return the image.
      
          blobs = img.find_blobs([red_threshold])
          if len(blobs) == 1:
              # Draw a rect around the blob.
              b = blobs[0]
              img.draw_rectangle((b[0:4]),color=(255,0,0)) # rect
              img.draw_cross(b[5], b[6]) # cx, cy
              Lm = (b[2]+b[3])/2
              length = K/Lm
              print(length)
              
              uart.write(length)
              time.sleep_ms(1000)
             
              #print(Lm)
          #print(clock.fps()) # Note: Your OpenMV Cam runs about half as fast while
          # connected to your computer. The FPS should increase once disconnected.
      

      STM32端代码:

      #include "stm32f10x.h"                  // Device header
      #include "Delay.h"
      #include "OLED.h"
      #include "Servo.h"
      #include "Key.h"
      #include "stdio.h"
      uint8_t KeyNum;
      float Angle;
      
      uint8_t count = 0;
      void USART1_Init(void);
      float res=0;
      
      int main(void)
      {
      	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
      	OLED_Init();
      	Delay_ms (1000);
      	USART1_Init();
      	
      	OLED_ShowString(1, 1, "COMEOUT:");
      
      	
      	while (1)
      	{
      		
      		OLED_ShowChar(2, 1, res);
      	}
      }
      void USART1_Init(void)
      {
      	GPIO_InitTypeDef GPIO_InitStructure;
      	USART_InitTypeDef USART_InitSture;
      	NVIC_InitTypeDef NVIC_InitSture;
      	
      	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
      	RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
      	
      
      	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
      	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
      	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
      	GPIO_Init(GPIOA, &GPIO_InitStructure);
      	
      	
      	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
      	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
      	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
      	GPIO_Init(GPIOA, &GPIO_InitStructure);
      	
      	USART_InitSture.USART_BaudRate = 9600;
      	USART_InitSture.USART_HardwareFlowControl =USART_HardwareFlowControl_None;
      	USART_InitSture.USART_Mode =USART_Mode_Tx|USART_Mode_Rx;
      	USART_InitSture.USART_Parity =USART_Parity_No;
      	USART_InitSture.USART_StopBits =USART_StopBits_1;
      	USART_InitSture.USART_WordLength =USART_WordLength_8b;
      	
      	USART_Init (USART1 ,&USART_InitSture);
      	USART_ITConfig (USART1 ,USART_IT_RXNE ,ENABLE );
      	USART_Cmd (USART1 ,ENABLE );
      	
      	
      	
      	NVIC_InitSture.NVIC_IRQChannel =USART1_IRQn;
      	NVIC_InitSture.NVIC_IRQChannelCmd=ENABLE ;
      	NVIC_InitSture.NVIC_IRQChannelPreemptionPriority =0;
      	NVIC_InitSture.NVIC_IRQChannelSubPriority =1;
      	NVIC_Init(&NVIC_InitSture );
      
      }
      void USART1_IRQHandler(void)
      {
      		if(USART_GetITStatus (USART1 ,USART_IT_RXNE )!=RESET )
      		{
      				res=USART_ReceiveData(USART1);
      
      		}
      
      }
      
      int fputc(int ch, FILE *f)
      {
      	USART_SendData(USART1, (unsigned char) ch);
      	while( USART_GetFlagStatus(USART1,USART_FLAG_TC)!= SET);	
      	return (ch);
      }
      

      0_1682424675632_EOAEQR6MG57GNRLV6UKTL05.png



    • 官方提供的测距离代码,添加串口通信代码到stm32端为什么会这样报错,而且openmv运行速度变得很慢



    • 你OPENmv的串口通信成功了吗?我要做的东西和你一样哎



    • @sdwo 成功了,openmv端需要强制数值类型转换



    • 问题解决了?可以看看你改的代码吗?