# 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 time
from pyb import UART
# 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, 19200, timeout_char=1000)
while(True):
if uart.any():
a = uart.readline()
if a == "OK\r\n"
sensor.snapshot().save("example1.jpg")
我是要用32串口发送个字符串“OK\r\n”,在python中判断接收到的字符串,然后拍照储存到SD卡。
你的if那一行,没有冒号吧
缩进也不对吧……
@5ewo 在 [python中应该如何判断接收到的字符串是发送的字符串?](/post/6976) 中说:
>
>
>
额,我缩进了4个空格,可能粘贴上去就没了,冒号是没加。但是还是不行,我记得例程中说还要复位一下,是不是必须这样。
代码格式问题
来自星瞳实验室APP: 必看[视频]:玩转星瞳论坛 https://forum.singtown.com/topic/57
请贴完整的代码,以及报错提示。
# 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 time
from pyb import UART
# 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, 19200, timeout_char=1000)
while(True):
if uart.any():
a = uart.readline().decode()
print(a)
if a == "OK\r\n":
sensor.snapshot().save("example1.jpg")Traceback (most recent call last):
File "<stdin>", line 17, in <module>
UnicodeError:
MicroPython v1.9.4-4510-g23e8457de on 2018-06-29; OPENMV3 with STM32F765
Type "help()" for more information.
你最后一句的缩进是错的。
# 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
from pyb import UART
# 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)
while(True):
if uart.any():
a = uart.readline().decode()
print(a)
if a == "OK\r\n":
print("You're on camera!")
img = sensor.snapshot()
img.morph(1, [+2, +1, +0,\
+1, +1, -1,\
+0, -1, -2])
img.save("example.jpg")
print("Done! Reset the camera to see the saved image.")我不知道怎么缩进,我是对照例程改的。
Traceback (most recent call last):
File "<stdin>", line 21, in <module>
RuntimeError: Sensor Timeout!!
MicroPython v1.9.4-4510-g23e8457de on 2018-06-29; OPENMV3 with STM32F765
Type "help()" for more information.
现在又不行了。
新的问题,单独新发帖子。
行,我先看看,不懂再发,感谢你!