为什么一传输数据就会出错呀?
-
from machine import I2C from vl53l1x import VL53L1X from pyb import UART import time,pyb,sensor,json sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QQVGA) sensor.skip_frames(time = 2000) uart = UART(3, 9600) clock = time.clock() i2c = I2C(2) distance = VL53L1X(i2c) led1 = pyb.LED(1) led2 = pyb.LED(2) led3 = pyb.LED(3) clock = time.clock() while True: time.sleep_ms(50) dis=distance.read() if 610<dis<640: data="0" data_out = json.dumps(set(data)) uart.write(data_out +'\n') print('you send:',data_out) clock.tick() img = sensor.snapshot() for r in img.find_rects(threshold = 25000): img.draw_rectangle(r.rect(), color = (255, 0, 0)) for p in r.corners(): img.draw_circle(p[0], p[1], 5, color = (0, 255, 0)) if r.w()>r.h(): if 470<dis<490: data="1" data_out = json.dumps(set(data)) uart.write(data_out +'\n') print('you send:',data_out) elif 320<dis<355: data="2" data_out = json.dumps(set(data)) uart.write(data_out +'\n') print('you send:',data_out) elif r.w()<r.h(): if 470<dis<490: data="3" data_out = json.dumps(set(data)) uart.write(data_out +'\n') print('you send:',data_out) elif 320<dis<355: data="4" data_out = json.dumps(set(data)) uart.write(data_out +'\n') print('you send:',data_out) #include <SoftwareSerial.h> SoftwareSerial softSerial(10, 11); // RX, TX void setup() { softSerial.begin(9600); Serial.begin(9600); } void loop() { if(softSerial.available()) { String s = detectString(); Openmv(s); } } String detectString() { while(softSerial.read() != '{'); return(softSerial.readStringUntil('}')); } void Openmv(String s) { if(s[1]=='0') { Serial.print('0'); Serial.print('\n'); } if(s[1]=='1') { Serial.print('1'); Serial.print('\n'); } if(s[1]=='2') { Serial.print('2'); Serial.print('\n'); } if(s[1]=='3') { Serial.print('3'); Serial.print('\n'); } if(s[1]=='4') { Serial.print('4'); Serial.print('\n'); } }
-
-
此回复已被删除!
-
https://singtown.com/learn/50539/
先按照视频步骤测试测距扩展板