logo

串口接收一字符再拍照,并输入一次拍一张?

2018-12-30 19:10
3
王羽

我想用arduino板子想OPENMV发送一字符让它拍照,且输入一次拍一张,如何实现?代码如下:

# UART Control
#
# This example shows how to use the serial port on your OpenMV Cam. Attach pin
# P4 to the serial input of a serial LCD screen to see "Hello World!" printed
# on the serial LCD display.

import sensor, image, pyb,time
from pyb import UART

BLUE_LED_PIN = 3

# Always pass UART 3 for the UART number for your OpenMV Cam.
# The second argument is the UART baud rate. For a more advanced UART control
# example see the BLE-Shield driver.
uart = UART(3, 9600, timeout_char=1000)

sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
sensor.set_framesize(sensor.VGA) # or sensor.QQVGA (or others)
sensor.skip_frames(time = 500) # Let new settings take affect.

pyb.LED(BLUE_LED_PIN).on()
sensor.skip_frames(time = 500) # Give the user time to get ready.

pyb.LED(BLUE_LED_PIN).off()

count = 0;

while(True):

    if uart.any():
        a = uart.readline().decode()
        if a == "OK\r\n":
            count = count + 1
            sensor.snapshot().save("%d.jpg"%(count)) # or "example.bmp" (or others)
            uart.write("Finish")
            pyb.LED(BLUE_LED_PIN).on()
            time.sleep(100)
            pyb.LED(BLUE_LED_PIN).off()
            a = "\n";

    else:
        sensor.snapshot()
        time.sleep(100)

运行时,显示错误

6f5e15da-a72d-4e67-b75f-b17f7877783b.PNG
2018-12-30 19:17
3
王羽

有大神帮忙解决一下么?万分感谢!

2018-12-30 19:56
I
网红小智智 星瞳科技

你用Arduino发送的数据的可能不是字符串。

建议先用OpenMV 串口调试扩展板和星瞳串口助手测试。