How to communicate between OpenMV and STM32 single Chip Microcomputer
This article mainly introduces how OpenMV communicates with STM32 MCU, which has certain reference value. Interested friends can refer to it. I hope you can learn a lot after reading this article. Let's take a look at it with you.
Hardware connection
The materials I used are as follows: four-pin IIC OLED,OpenMV (OV7725), STM32F103C8T6 minimum system board, N data lines (OpenMV data cables can only be used officially, other basic can not be used), several DuPont lines.
1.OpenMV side: know UART_RX-P5-UART_TX-P4 from the diagram
2.STM32 side: USART_TX-PA9-USART_RX-PA10
3. Four-pin OLED IIC connection: because SDA-PA2-SCL-PA1 uses analog IIC instead of hardware IIC, you can modify the IO port to control SDA and SCL lines according to individual needs. You only need to simply modify the code.
The TX (RX) of 4.STM32 is connected to the RX (TX) of OpenMV, and the OLED is connected to STM32.
Software code-import sensor, image, time,math,pybfrom pyb import UART,LEDimport jsonimport ustructsensor.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 trackingsensor.set_auto_whitebal (False) # must be turned off for color trackingred_threshold_01= (10,100,127,32,-43 67) clock = time.clock () uart = UART (3Magne 115200) # define serial port 3 variables uart.init (115200, bits=8, parity=None, stop=1) # init with given parametersdef find_max (blobs): # define the function max_size=0 for blob in blobs: if blob.pixels () > max_size: max_blob=blob max_size= blob.pixels () return max_blobdef sending_data (cx,cy,cw) to find the largest color block area Ch): global uart # frame= [0x2C 18pint (cx/0xff), cy%0xff,int (cy/0xff), 0x5B]; # data = bytearray (frame) data = ustruct.pack ("