# main.py -- put your code here! from pyb import UART from micropyGPS import MicropyGPS from pyb import LED # Setting up UART # This example uses UART 2 with RX on pin X4 # Baudrate is 9600bps, with the standard 8 bits, 1 stop bit, no parity uart = UART(2, 9600) # Initiate my_gps = MicropyGPS() # Reads 100 sentences and reports how many were parsed and if any failed the CRC check sentence_count = 0 while True: if uart.any(): led = LED(3) led.on() stat = my_gps.update(chr(uart.readchar())) if stat: print(stat) print('Latitude:', my_gps.latitude_string()) print('Longitude:', my_gps.longitude_string()) print('Speed:', my_gps.speed_string('kph'), 'or', my_gps.speed_string('mph'), 'or', my_gps.speed_string('knot'))
import time from pyb import UART from modbus import ModbusRTU uart = UART(3) modbus = ModbusRTU(uart) while(True): if modbus.any(): modbus.handle() else: time.sleep(100) # image processing in there
from pyb import Pin, Timer, ExtInt, UART, Servo import time u = UART(3, 9600) ss = Pin(Pin.cpu.A13, Pin.OUT) from car import * import re, time cmds = { 'back': back2, 'forward': forward2, 'stop': stop, 'add': add, 'dec': dec, } ss.value(0) def jdytest(): print("jdytest") for s in ('BAUD', 'RFID', 'DVID', 'RFC'): u.write('AT+' + s + '\r\n') while not u.any(): pass print(u.read()) jdytest() u.write('AT+CLSSA0\r\n') time.sleep(2) print(u.read()) ss.value(1) print(ss.value()) while (1):
SPI = pyb.SPI(1) #DIN=>X8-MOSI/CLK=>X6-SCK #DIN =>SPI(1).MOSI 'X8' data flow (Master out, Slave in) #CLK =>SPI(1).SCK 'X6' SPI clock RST = pyb.Pin('X20') CE = pyb.Pin('X19') DC = pyb.Pin('X18') LIGHT = pyb.Pin('X17') lcd_5110 = upcd8544.PCD8544(SPI, RST, CE, DC, LIGHT) #以上内容为声明并初始化显示屏 count_ = 0 N2 = Pin('Y3', Pin.OUT_PP) #定义“Y3”为输出模式,这个引脚是控制蜂鸣器的,来电话了需要响铃的 N1 = Pin('Y6', Pin.OUT_PP) #定义“Y6”位输出模式,“Y6”引脚是板载通信系统的开关控制引脚 N1.low() pyb.delay(2000) N1.high() pyb.delay(10000) #通过拉低拉高开光控制引脚,启动通信系统 u2 = UART(4, 115200) #设置串口4,并设置串口波特率为115200 i = '0' w = 0 d = 0 q = 0 G = 0 j = 0 while 0 < 1: N2.low() #设置蜂鸣器控制引脚为低电平,不让蜂鸣器响 if (u2.any() > 0): #检测串口4是否有数据,如果有数据执行以下 _dataRead = u2.readall() if _dataRead != None: #判断串口4的数据是否为空,不为空执行以下代码 print('原始数据=', _dataRead) print('原始数据长度:', len(_dataRead)) print('123', _dataRead[2:6]) RING = _dataRead[2:6] #截取包头,这个包头是为了判断数据是否正确的重要依据
#blue=[(34, 40, 10, 18, -60, -40)] #green=[(36, 58, -39, -24, -3, 19)]#green #red=[(41, 54, 67, 80, 30, 63)] # generic_blue_thresholds,green(36, 58, -39, -24, -3, 19), #blue (41, 54, 57, 80, 16, 63) #sensor.reset() #sensor.set_pixformat(sensor.RGB565) #sensor.set_framesize(sensor.QQVGA) #sensor.skip_frames(time = 2000) #sensor.set_auto_gain(False) # must be turned off for color tracking #sensor.set_auto_whitebal(False) # must be turned off for color tracking #sensor.set_vflip(False) #sensor.set_hmirror(False) #clock = time.clock() uart=UART(3,19200) #track_color() color_track() while True: key=uart.readchar() if key==1: cal() elif key==2: color_track() elif key==3: print(3) elif key==4: print(4)
def __init__(self): self.scan = UART(3, 9600, read_buf_len=100)
from pyb import I2C import char_lcd import binascii from pyb import UART from pyb import Pin, ADC ser = UART(6, 115200) ser.init(115200, bits=8, parity=None, stop=1) i2c = I2C(2, I2C.MASTER, baudrate=20000) d = char_lcd.HD44780(i2c) i2 = I2C(1, I2C.MASTER, baudrate=50000) adc = ADC(Pin('X1')) temp1 = 0 #d.set_line(1) #d.set_string("Bar") while True: i2.send(0x43, 0x39) asd = i2.recv(1, 0x39) test = asd[0] step = test & 0x0F chordnr = (test >> 4) & 0x07 i2.send(0x83, 0x39) kanava2 = i2.recv(1, 0x39) test2 = kanava2[0] step2 = test2 & 0x0F chordnr2 = (test2 >> 4) & 0x07 countvalue2 = int(16.5 * (2**chordnr2 - 1) + (step2 * (2**chordnr2))) countvalue = int(16.5 * (2**chordnr - 1) + (step * (2**chordnr)))
import pyb xlights = (pyb.LED(2), pyb.LED(3)) ylights = (pyb.LED(1), pyb.LED(4)) from pyb import UART from pyb import Pin #from ubinascii import hexlify from ubinascii import * accel = pyb.Accel() u2 = UART(2,9600,timeout=100) i=0 K=1 #*******************************主程序********************************** print('while') while (K>0): _dataRead=u2.readall() if(1>0): x = accel.x() print("x=") print(x) if x > 10: xlights[0].on() xlights[1].off() u2.write('\x00\x05\x18YOU') print('\x00\x01\x18YOU') elif x < -10: xlights[1].on() xlights[0].off() u2.write('\x00\x05\x18ZUO') print('\x00\x01\x18ZUO')
#XBee Test code send packets to another xbee #PyBoard #Created by: Joseph Fuentes [08/09/2017] import pyb from pyb import UART from pyb import ExtInt from pyb import Pin import time import math #Connect RX of XBee to 'X3', TX to 'X4' xbee = UART(2, 115200) xbee.write('\nChecking GPS and altitude to see if landed...')
import sensor, image, time, struct from pyb import UART import math import utime from robot_arm import RobotArm3DoF red_threshold_01 = (21, 29, -72, 6, -11, 17) blue_threshold_01 = (26, 12, -15, 25, -46, -6) orang_threshold_01 = (68, 34, -14, 52, 100, 27) sensor.reset() uart = UART(1, 57600) sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time=2000) sensor.set_auto_gain(False) clock = time.clock() qr_finish_flag = 1 buff = [] arm = RobotArm3DoF() img = sensor.snapshot() blobs = img.find_blobs([orang_threshold_01], area_threshold=150) last_blobs = blobs k = 1900 x_scale = 26.8 y_scale = 28.7 scale = (x_scale + y_scale) / 4 init_frame = (0.1, 15, 2.5) target_x_err = 0 length = 0 arm.move(init_frame[0], init_frame[1], init_frame[2])
# with the raspberry pi. ################################## import sensor, image, time from pyb import UART #Sensor Setup ################################# sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time=2000) ################################# #Communication Setup ################################# uart = UART(1, 9600, timeout_char=1000) # init with given baudrate uart.init(9600, bits=8, parity=None, stop=1, timeout_char=1000) # init with given parameters ################################# #Main Loop ################################# clock = time.clock() while (True): clock.tick() while (uart.any() == 0): continue print(20) while (uart.any() != 0): print(uart.readchar()) time.sleep(1000)
import pyb from pyb import UART # 串口6初始化 uart = UART(6, 115200, timeout=100) # 响应报文 header = """ HTTP/1.1 200 OK Content-Type:text/html Content-Length:{0} {1} """ # HTML页面 html = """<!DOCTYPE html> <html> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <head> <title>TPYBoard</title> </head> <body> <h1>TPYBoard v201</h1><br /> <h2>Simple HTTP server</h2> </body> </html> """ while True: if uart.any() > 0: request = uart.read().decode() print('request:', request) # 当接收到GET请求头时,进行响应 if request.find('GET') > -1:
# Single Color RGB565 Blob Tracking Example # # This example shows off single color RGB565 tracking using the OpenMV Cam. import sensor, image, time, math from pyb import UART, Timer obj_x = 0 obj_y = 0 uart = UART(3, 115200) #初始化串口 波特率 115200 def transmit_data(): bol = (obj_x + obj_y) % 254 pack_data = bytearray([ 0xff, obj_x >> 8, obj_x & 0x0ff, obj_y >> 8, obj_y & 0x0ff, bol, 0xfe ]) return pack_data threshold_index = 0 # 0 for red, 1 for green, 2 for blue # Color Tracking Thresholds (L Min, L Max, A Min, A Max, B Min, B Max) # The below thresholds track in general red/green/blue things. You may wish to tune them... thresholds = [ ((59, 0, 24, 118, 5, 50)), # generic_red_thresholds (30, 100, -64, -8, -32, 32), # generic_green_thresholds (0, 30, 0, 64, -128, 0) ] # generic_blue_thresholds
from math import sqrt import pyb import sensor, image, time from pyb import UART sensor.reset() sensor.set_pixformat(sensor.RGB565) #sensor.set_pixformat(sensor.GRAYSCALE) sensor.set_framesize(sensor.QQVGA) sensor.skip_frames(time=2000) clock = time.clock() enable_lens_corr = True #UART Initialization uart = UART(1, 115200) #Threshold Theta min_degree_V = 135 max_degree_V = 180 min_degree_V_rev = 0 max_degree_V_rev = 45 line_counter_V = 0 min_degree_H = 85 max_degree_H = 95 line_counter_H = 0 #Coordinates of detected lines start_x, start_y = 0, 0 end_x, end_y = 0, 0 mid_x, mid_y = 0, 0
#DIN =>SPI(1).MOSI 'X8' data flow (Master out, Slave in) #CLK =>SPI(1).SCK 'X6' SPI clock RST = pyb.Pin('X20') CE = pyb.Pin('X19') DC = pyb.Pin('X18') LIGHT = pyb.Pin('X17') lcd_5110 = upcd8544.PCD8544(SPI, RST, CE, DC, LIGHT) lcd_5110.clear() lcd_5110.lcd_write_string('Getting Ready', 0, 1) #GU620模块初始化 N1 = Pin('Y6', Pin.OUT_PP) #定义通信系统启动引脚 N1.low() pyb.delay(2000) N1.high() pyb.delay(10000) #拉高拉低引脚,启动通信系统 u2 = UART(4, 115200, timeout=100) #定义串口4,设置 波特率为115200 #报文详细格式说明参照萝卜电子服务平台示例报文格式。 #www.turnipsmart.com:8080 message = 'TPGPS,1234567890abcde,36.67191670,119.17200000,201701120825,25,50,END' if __name__ == '__main__': #连接TCP服务器 u2.write('AT+CIPSTART="TCP","139.196.110.155",30000\r\n') while True: if u2.any() > 0: _dataRead = u2.read() print('_dataRead:', _dataRead) if _dataRead.find(b'CONNECT OK') > -1: #说明已经和服务器成功建立连接 lcd_5110.lcd_write_string('CONNECT OK', 0, 2) print('CONNECT OK') pyb.LED(2).on()
# Select an area in the Framebuffer to copy the color settings. #代表红色的代码 red_color_code = 1 green_color_code = 2 yellow_color_code = 4 blue_color_code = 8 from pyb import UART sensor.reset() # Initialize the camera sensor. sensor.set_pixformat(sensor.RGB565) # use RGB565. sensor.set_framesize( sensor.QQVGA) # use QVGA for quailtiy ,use QQVGA for speed. sensor.skip_frames(10) # Let new settings take affect. sensor.set_auto_whitebal(False) uart = UART(3, 115200) #利用串口3 #关闭白平衡。白平衡是默认开启的,在颜色识别中,需要关闭白平衡。 clock = time.clock() # Tracks FPS. right_angle_threshold = (45, 61) forget_ratio = 0.8 move_threshold = 5 center_x = 000 center_y = 000 def calculate_angle(line1, line2): # 利用四边形的角公式, 计算出直线夹角 angle = (180 - abs(line1.theta() - line2.theta())) if angle > 90: angle = 180 - angle return angle
socket_node = 1 pyb.LED(3).toggle() tim = pyb.Timer(4, freq=10) tim.callback(fun) sensor.reset() # Initialize the camera sensor. sensor.set_hmirror(True) sensor.set_vflip(True) sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QQVGA) sensor.skip_frames(10) sensor.set_auto_whitebal(False) clock = time.clock() uart = UART(3, 9600) # Init wlan module and connect to network print("Trying to connect... (may take a while)...") wlan = network.WINC() wlan.connect(SSID, key=KEY, security=wlan.WPA_PSK) # We should have a valid IP now via DHCP print(wlan.ifconfig()) # Create server socket s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM) # Bind and listen s.bind([HOST, PORT]) s.listen(5)
(30, 100, -64, -8, -32, 32), # generic_green_thresholds -> index is 1 so code == (1 << 1) (0, 15, 0, 40, -80, -20)] # generic_blue_thresholds -> index is 2 so code == (1 << 2) """ #*************************************For LASER Measurement Module********************************** laser_off_on = [(0xAA,0x00,0x01,0xBE,0x00,0x01,0x00,0x00,0xC0), #sequence to turn laser OFF (0xAA,0x00,0x01,0xBE,0x00,0x01,0x00,0x01,0xC1)] #sequence to turn laser ON laser_meas_cmd_seq = [(0xAA,0x00,0x00,0x20,0x00,0x01,0x00,0x02,0x23), #OneShotFast mode (0xAA,0x00,0x00,0x20,0x00,0x01,0x00,0x01,0x22), #OneShotSlow mode (0xAA,0x00,0x00,0x20,0x00,0x01,0x00,0x00,0x21)] #OneShotAuto mode fast_meas_cmd_seq = [0xAA,0x00,0x00,0x20,0x00,0x01,0x00,0x02,0x23] #OneShotFast mode #fast_meas_cmd_seq = [0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38] #OneShotFast mode threshold_index = 0; ldmm = UART(1,19200) #Laser Distance Measurement Module UART interface #ldmm.init(19200, bits=8, parity=None, stop=1) ldmm_cmd_sz = 9 ldmm_result_sz = 13 dm_mode_fast = 0 dm_mode_slow = 1 dm_mode_auto = 2 dist_mm = 0 off = 0 on = 1 #***************************For controlling stepper motor functionality***************************** pm_home_pin = pyb.Pin("P2", pyb.Pin.IN)#("P2", pyb.Pin.IN) #pan motor home position detect pin zfm_endis_pin = pyb.Pin("P3", pyb.Pin.OUT_PP) #Zoom, Focus Motor enable/disable pin
''' 实验名称:串口通信 版本:v1.0 日期:2019.10 作者:01Studio 说明:通过编程实现串口通信,跟电脑串口助手实现数据收发。 ''' #导入串口模块 from pyb import UART uart = UART(3, 115200) #设置串口号3和波特率,TX--Y9,RX--Y10 uart.write('Hello 01Studio!') #发送一条数据 while True: #判断有无收到信息 if uart.any(): text = uart.read(64) #默认单次最多接收64字节 print(text) #通过REPL打印串口3接收的数据
# # For this script to work properly you should point the camera at a line at a # 45 or so degree angle. Please make sure that only the line is within the # camera's field of view. import sensor, image, pyb, math, time from pyb import Servo from pyb import LED from pyb import UART from pyb import Pin switch_pin = Pin('P7', Pin.IN, Pin.PULL_DOWN) uart = UART(3, 19200) # Use UART 3 (pins 4 and 5) blue_threshold = (0, 100, -128, 127, -128, -35) # L A B binary_threshold = (57, 255) rois = [0,40,320,190] TARGET_POINTS = [(70, 50), # (x, y), clockwise from top left (285, 50), (319, 239), (1,239)] cruise_speed = 1575 # how fast should the car drive, range from 1000 (full backwards) to 2000 (full forwards). 1500 is stopped. 1575 is slowest it can go steering_direction = -1 # use this to revers the steering if your car goes in the wrong direction
# * Content: * # *---------------------------------------------------------------------------* # * Language: Python * # * Compiler: * # * Target: STM32F407 micropython 1.9.3 * # *===========================================================================* import pyb import accelerometer import filterToolkit import time import math from pyb import UART from pyb import Pin, Timer uart = UART(2, 9600, timeout=10) # UART2 -> Rx PA3, Tx PA2 acc = accelerometer.LIS302DL() acc.init() rawX, rawY, rawZ = 0, 0, 0 filteredX, filteredY, filteredZ = 0, 0, 0 PI = 3.14156 ledLeft = Pin('PD12') ledRight = Pin('PD14') ledUp = Pin('PD13') ledDown = Pin('PD15') tim = Timer(4, freq=1000) chLeft = tim.channel(1, Timer.PWM, pin=ledLeft)
import json import ustruct # #white_threshold_01 = ((95, 100, -18, 3, -8, 4)); #白色阈值 red_threshold_01 = [(5, 37, 122, 34, -47, 31), (34, 54, 46, 15, 18, 57), (20, 48, -124, -10, -45, 127), (0, 30, 0, 64, -128, 0)] sensor.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 tracking sensor.set_auto_whitebal(False) # must be turned off for color tracking clock = time.clock() uart = UART(3, 115200) #定义串口3变量 uart.init(115200, bits=8, parity=None, stop=1) # init with given parameters def find_max(blobs): #定义寻找色块面积最大的函数 max_size = 0 for blob in blobs: if blob.pixels() > max_size: max_blob = blob max_size = blob.pixels() return max_blob def sending_data(cx, cy): global uart #frame=[0x2C,18,cx%0xff,int(cx/0xff),cy%0xff,int(cy/0xff),0x5B];
# # For additional info please consult provided documentation ############################################################ #some imports libraries etc. import sensor, image, time # for using camera and basic image processing functions from pyb import Pin #use hardware inputs / outputs from pyb import UART #enables use of hardware serial (UART) import math #use trigonometry functions #importing lookup tables, placed inside lut_table.py script from lut_table import lut_distance #HARDWARE INPUTS AND OUTPUTS uart = UART(3, 9600) #UART pin 4, 9600 baudrate pin1 = Pin('P1', Pin.OUT_PP, Pin.PULL_NONE) #output, to laser (MOSFET) # gain setting GAIN_SCALE = 1 polozaj_linije_ypos = 100 #tu se zapisuje polozaj vertikalne linije, prepraviti kalibracijom #USER changable: low_threshold = (30, 255) #defining threshold limit for image binarisation #enter bottle diameter in mm, default is 67 mm bottle_diameter = 67 #bottle diameter in mm #define min spot size (reflected laser line), optimised for 15-30 cm distance num_pixels_threshold = 15 #minimal number of pixles detected, default is 25 num_area_threshold = 20 #minimal area covered by blob , default is 30
import sensor, image, time, pyb from pyb import UART from struct import pack sensor.reset() # 初始化摄像头 sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) #320x240 sensor.set_auto_whitebal(False) #关闭白平衡 clock = time.clock() # 追踪帧率 buf_x = [0, 0, 0] # 坐标x的缓冲区 buf_y = [0, 0, 0] # 坐标y的缓冲区 frame_time = 0.01 # FPS初始化(后面会更新成真实值) uart = UART(3, 115200) # 设定好串口号,波特率 blob_thresholds = ((85, 100, -12, 12, -12, 12)) # 白色 thresholds = [(160, 255)] # 二值化设置阈值 find_once = 0 # 搜索边框计数变量 search_rect = [5, 5, 310, 230] # 边框的x1,y1,x2,y2 def find_rect(): if (find_once < 50): sensor.set_pixformat(sensor.GRAYSCALE) # 设置成灰度图像读取 thresh = sensor.snapshot().lens_corr(1.8) # 读取图像 thresh.binary(thresholds) # 二值化处理 u_flag = 1 d_flag = 1 l_flag = 1 r_flag = 1 # 设置4个边界的查找状态变量,若查找成功为0,否则为1
# ---------------------------------------------------- # Task 8: Get keypad commands via Bluetooth import pyb from pyb import Pin, Timer, UART print('Task 8: Test keypad communication with Pyboard') key = ('1', '2', '3', '4', 'U', 'D', 'L', 'R') uart = UART(6) uart.init(9600, bits=8, parity=None, stop=2) while True: while (uart.any() != 10): #wait we get 10 chars n = uart.any() command = uart.read(10) key_index = command[2] - ord('1') if (0 <= key_index <= 7): key_press = key[key_index] if command[3] == ord('1'): action = 'pressed' elif command[3] == ord('0'): action = 'released' else: action = 'nothing pressed' print('Key', key_press, ' ', action)
micropython.alloc_emergency_exception_buf(100) ## Bring up the LED matrix pwmclk = Timer(1, freq=125000) dcfurs.init(pwmclk) dcfurs.clear() ##----------------------------------------------- ## Bluetooth Module ##----------------------------------------------- ble_enable = Pin("BLE_EN", Pin.OUT_OD) ble_enable.value(0) pyb.delay(5) ble_enable.value(1) ble = UART(1, 115200) ## Write variables with a little delay to make up ## for the lack of flow control. def ble_set(name, value=None): line = "set: " + name if value: line += "=" + value line += "\r\n" for ch in line: ble.write(ch) pyb.delay(1) ##----------------------------------------------- ## Pushbutton Class
def __init__(self): # Always pass UART 3 for the UART number for your OpenMV Cam. self.uart = UART(3); # This initializes the UART paramters: 115200 bits/second, 8 bits/byte, no parity, 1 stop. # Wait for 80ms for data to start when reading and up to 20ms between characters before # we timeout on reading. self.uart.init(115200, bits=8, parity=None, stop=1, timeout_char=20, timeout=80); # First we have to stop it from talking so we can send commands # and understand what it says back. # Disable output command: self.command = bytes(b'\x5A\x05\x07\x00\x66'); self.uart.write(self.command); self.uart.read(); #print("Disable Command: %s"%command); #uart.write(command); #response = uart.read(); #print("Disable Response[%d]: %s"%(len(response),response)); # Manal synchronizing with device # # Wait 1/4 second for it to shut up, so we can get synchronized with what it is # sending to us. pyb.delay(250); # Delay is in milliseconds. # Read everything we've got in the UART buffer so far and ignore it...because # it is just a jumble of stuff we don't know where the frames begin or end. self.response = self.uart.read(); # Now Read Version Info: Now we know that the next response will be to this command. self.command = bytes(b'\x5A\x04\x01\x5F'); self.uart.write(self.command); self.uart.read(); #print("Version Command: %s"%command); #uart.write(command); # Read back response: #response = uart.read(); #print("Version Response[%d]: %s"%(len(response), response)); # Set the format of data to be text (easily parsed): # We could send another command to set the binary format and then # we would receive packets of 9 bytes for each reading. self.command = bytes(b'\x5A\x05\x05\x02\x66'); self.uart.write(self.command); self.uart.read(); #print("Format Command: %s"%command); #uart.write(command); # Read back response: #response = uart.read(); #print("Format Response[%d]: %s"%(len(response),response)); # Set the rate to zero so we trigger it to capture and can sync with # other things we do in the OpenMV. It will respond when we ask so # we can't get out of sync with it. self.command = bytes(b'\x5A\x06\x03\x00\x00\x63'); self.uart.write(self.command); self.uart.read(); # print("Rate Command: %s"%command); # uart.write(command); # response = uart.read(); # print("Rate Response[%d]: %s"%(len(response),response)); # Enable output again now that we're ready: self.command = bytes(b'\x5A\x05\x07\x01\x67'); self.uart.write(self.command); self.uart.read();
# Untitled - By: wmy - 周日 12月 2 2018 import sensor, image, time from pyb import UART warning_threshold = (75, 100, -25, 25, -25, 25) kernel_size = 2 kernel = [ -1, -1, -1, -1, -1, -1, 1, 1, 1, -1, -1, 1, 8, 1, -1, -1, 1, 1, 1, -1, -1, -1, -1, -1, -1 ] uart = UART(3, 9600, timeout_char=1000) sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time=1000) clock = time.clock() while (True): warning = False clock.tick() img = sensor.snapshot() img.morph(kernel_size, kernel) blobs = img.find_blobs([warning_threshold]) if blobs: for b in blobs: img.draw_rectangle(b[0:4])
import time, sensor, image, pyb from pyb import UART from pyb import LED import json uart = UART(3, 115200) uart.init(115200, bits=8, parity=None, stop=1) # init with given parameters threshold = (60, 24, 36, 76, -19, 71) blue_led = LED(1) la_led = LED(2) 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) # must be turned off for color tracking clock = time.clock() x = 0 y = 0 while (True): clock.tick() img = sensor.snapshot() blobs = img.find_blobs([threshold], pixels_threshold=10, area_threshold=10, merge=True) la_led.on()
def init(self, bus=3, baud=9600, tout_c=10, initSend=None): self.uart = UART(bus, baud, timeout_char=tout_c) if (initSend): self.sendData(initSend)