脱机运行为何串口无法发送?
-
本问题不涉及代码,我使用了WIFI扩展板,OPENMV直接插在电脑上供电可以在串口上打印值,但是接在充电宝上虽然仍可连接WIFI,仍可看到图像,但是串口无法打印数值。同样的代码同样的操作重复多次仍是如此,是因为电压问题吗?该如何解决呢?
-
应该是代码的问题。请提供你的代码。
-
import sensor, image, time, math, network, usocket, sys from pyb import UART uart = UART(3, 9600, timeout_char=1000) SSID ='OPENMV_AP' KEY ='1234567890' HOST = '' PORT = 8080 threshold_index = 0 thresholds = [(20, 93, -59, -22, -5, 32)] sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time = 2000) sensor.set_auto_gain(False) sensor.set_auto_whitebal(False) sensor.set_contrast(1) sensor.set_brightness(1) sensor.set_saturation(1) sensor.set_gainceiling(16) wlan = network.WINC(mode=network.WINC.MODE_AP) wlan.start_ap(SSID, key=KEY, security=wlan.WEP, channel=2) def start_streaming(s): print ('Waiting for connections..') client, addr = s.accept() client.settimeout(2.0) print ('Connected to ' + addr[0] + ':' + str(addr[1])) data = client.recv(1024) client.send("HTTP/1.1 200 OK\r\n" \ "Server: OpenMV\r\n" \ "Content-Type: multipart/x-mixed-replace;boundary=openmv\r\n" \ "Cache-Control: no-cache\r\n" \ "Pragma: no-cache\r\n\r\n") clock = time.clock() while (True): clock.tick() frame = sensor.snapshot() cframe = frame.compressed(quality=35) header = "\r\n--openmv\r\n" \ "Content-Type: image/jpeg\r\n"\ "Content-Length:"+str(cframe.size())+"\r\n\r\n" client.send(header) client.send(cframe) img = sensor.snapshot() clock.tick() for blob in img.find_blobs([thresholds[threshold_index]], pixels_threshold=200, area_threshold=200, merge=True): img.draw_rectangle(blob.rect()) middle = blob.cx() print(middle) if middle>=0 and middle<=70: feedback = '0x02' id = int('0x02',16) uart.writechar(id) elif middle>=90 and middle<=160: id = int('0x00',16) uart.writechar(id) else : id = int('0x06',16) uart.writechar(id) while (True): s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM) try: s.bind([HOST, PORT]) s.listen(5) s.settimeout(3) start_streaming(s) except OSError as e: s.close() print("socket error: ", e)
-
这个是代码,经反复测试在电脑端供电可正常使用,用充电宝供电虽WIFI模块正常工作,但串口无数据发送,急求解决办法,谢谢