Ejemplo n.º 1
0
def pye(*args, tab_size=4, undo=50):
    from pyb import USB_VCP
    USB_VCP().setinterrupt(-1)
    io_device = IO_DEVICE()
    ret = pye_edit(*args, tab_size=tab_size, undo=undo, io_device=io_device)
    io_device.deinit_tty()
    USB_VCP().setinterrupt(3)
    return ret
Ejemplo n.º 2
0
def main():
    # usb object
    usb = USB_VCP()
    i = 0
    j = 0
    emailNum = 0
    while (True):
        clock.tick()
        img = sensor.snapshot(pixformat=sensor.GRAYSCALE)
        blobs = img.find_blobs(threshold_list,
                               pixels_threshold=0,
                               area_threshold=0,
                               merge=True)
        cmd = usb.recv(4, timeout=1)

        if (cmd == b'snap'):
            i = 0
            emailNum = 0

        if (i == 0):
            usb.send(244)

        if (blobs):
            i = 1
            if (i == 1):
                fire_blob = max(blobs, key=lambda x: x.density())
                img.draw_rectangle(fire_blob.rect())
                img.draw_cross(fire_blob.cx(), fire_blob.cy())

                # For pan control
                xPos = fire_blob.cx()
                xErr = 20 - xPos

                # For tilt control
                yPos = fire_blob.cy()
                yErr = 15 - yPos

                #img.draw_string(fire_blob.x(), fire_blob.y() - 10, "Pan Error: %.2f pixels" % xPosErr, mono_space=False)
                usb.send(xPos)
                usb.send(yPos)

                if ((xErr <= 1 and xErr >= -1) and (yErr <= 1 and yErr >= -1)
                        and emailNum == 0):
                    bigPic()  # Convert to better resolution for email photo
                    img2 = sensor.snapshot(pixformat=sensor.GRAYSCALE)
                    blobs = img2.find_blobs(threshold_list,
                                            pixels_threshold=0,
                                            area_threshold=0,
                                            merge=True)
                    fire_blob = max(blobs, key=lambda x: x.density())
                    img2.draw_rectangle(fire_blob.rect())
                    img2.draw_cross(fire_blob.cx(), fire_blob.cy())
                    img2.to_rainbow(
                        color_palette=sensor.PALETTE_IRONBOW)  # color it

                    imgUSB = img2.compress()
                    usb.send(ustruct.pack("<L", imgUSB.size()))
                    usb.send(imgUSB)
                    emailNum = 1
                    smallPic()  # Convert back to low-res imaging for control
Ejemplo n.º 3
0
 def __init__(self):
     self.usb_serial = USB_VCP()
     self.baud = 0
     self.recv_buf = bytearray(1)
     # Disable Control-C on the USB serail port in case one comes in the
     # data.
     self.usb_serial.setinterrupt(-1)
Ejemplo n.º 4
0
 def __init__(self, role):
     self.role = role
     self.console = USB_VCP()
     self.command_dispatch = { }
     self.cmd_hist = [b'']
     self.prompt = bytes(self.role + '> ', 'ASCII')
     self.tx_want_ack = True
     self.destination = bytes(8)
    def __init__(self, port=0, data_rate=None, host_id=2, module_id=1, debug=False):
        del data_rate
        tmcl_module_interface.__init__(self, host_id, module_id, debug)
        tmcl_host_interface.__init__(self, host_id, module_id, debug)

        self.__vcp = USB_VCP(port)
        self.__vcp.init()
        self.__vcp.setinterrupt(-1)
Ejemplo n.º 6
0
def run_usb_vcp_test():
    serial_port = USB_VCP()
    nmea_line = None
    #serial_port.setinterrupt(-1)

    while True:
        # retrieving data
        if serial_port.any():
            nmea_line = str(serial_port.readline(), 'utf-8')

        if nmea_line:
            delay(1)
            nmea_line = None

        delay(50)
Ejemplo n.º 7
0
import sensor, image, time
from pyb import USB_VCP

# Pink
thresholds = [(20, 85, 25, 100, -45, 40)]

# Sensor Initialization
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

# USB Initialization
usb = USB_VCP()

# Send X,Y
while (True):
    img = sensor.snapshot()
    for blob in img.find_blobs(thresholds,
                               pixels_threshold=25,
                               area_threshold=25,
                               merge=True):

        # Filter non-circle blobs
        if blob.roundness() > 0.6:
            buf = str(blob.cx()) + ' ' + str(blob.cy())
            usb.send(buf)

            # Draw red circle around ball
Ejemplo n.º 8
0
try:
    from pyb import DAC
    from pyb import LED
    from pyb import Pin
    from pyb import USB_VCP

    sensitivity, maxn, minn = .5, 255, 0

    com = USB_VCP()
    light = DAC(2)
    y1, y2, y3 = Pin('Y1', Pin.IN), Pin('Y2', Pin.IN), Pin('Y3', Pin.IN)
    intensity, oldStr = maxn, str(y1.value()) + str(y2.value())

    directTab = {
        '1000': 1,
        '0001': 1,
        '0111': 1,
        '1110': 1,
        '1011': -1,
        '1101': -1,
        '0100': -1,
        '0010': -1
    }

    def setByte(i):
        return i.to_bytes(1)

    def limitNums(num, maxn, minn):
        return max(minn, min(maxn, num))

    def handleLEDs(intensity, value):
Ejemplo n.º 9
0
# Turn on the light so you know something is happening
led = LED(4)
led.on()

# Write out a sinusoidal curve to channel X5, which is wired via a
# female-female jumper to X2
# --
# create a buffer containing a sine-wave, using half-word samples
buf = array(
    'H', 2048 + int(2047 * math.sin(2 * math.pi * i / 128))
    for i in range(128))
dac = DAC(1, bits=12)  # Wired to X5
dac.write_timed(buf, 400 * len(buf), mode=DAC.CIRCULAR)

# Instatiate the USB serial object
u = USB_VCP()

u.write('Hello world!!')

# Enter into an infinite loop
while True:

    # Get a line from the serial connection
    line = u.readline()

    # If there is nothing, line will be None
    if not line is None and line:

        # What you got is a byte object, convert from bytes (binary data) to python string
        line = line.decode('ascii')
Ejemplo n.º 10
0
 def __init__(self):
     self.vs = USB_VCP()
     self.direction = 0
     self.speed = 0
     self.select_dir = 0
     self.select_speed = 0
Ejemplo n.º 11
0
def pye(*files):
    from pyb import USB_VCP
    USB_VCP().setinterrupt(-1)
    pye_mp.pye(*files)
    USB_VCP().setinterrupt(3)
Ejemplo n.º 12
0
from pyb import LED, Timer, Pin, Switch, UART, USB_VCP
from Basic.Car_Driver import Car_Driver as Car
from Basic.Wifi_Driver import Wifi_Driver as Wifi
from Basic.ComHelper import ComHelper

sw = Switch()

led1 = LED(1)
led2 = LED(2)
led3 = LED(3)
led4 = LED(4)

usb_uart = USB_VCP()

car = Car(['Y1', 'Y2', 'Y3', 'Y4'])
wifi = Wifi()
getter = ComHelper()


def car_control(ret):
    if ret == 'w':
        car.Right_move(1)
        car.Left_move(1)
    elif ret == 's':
        car.Right_move(2)
        car.Left_move(2)
    elif ret == 'a':
        car.Right_move(1)
        car.Left_move(2)
    elif ret == 'd':
        car.Right_move(2)
Ejemplo n.º 13
0
from pyb import USB_VCP  # importing the library for USb VCP(Virtual Comm Port).
usb = USB_VCP()  # makes USB object

while (True):  # making a loop to continously send data
    usb.send("hi123")  # send function to send script.
'''  NOTE
 usb.send() fucntion send the data character by character.
 for ex: usb.send("hi123") send the "hi123" string as "h", "i", "1", "2", "3".
'''
Ejemplo n.º 14
0
def run_uav_test(i2c_bus=2):
    global SIGNALS
    global SIGNAL_USR

    SIGNALS[0] = 0
    serial_port = USB_VCP()
    nmea_line = None
    # serial_port.setinterrupt(-1)
    disp = display.create_spi_display(SSD1322, 256, 64)
    i2c = I2C(i2c_bus, freq=400000)
    devices = i2c.scan()
    lsm303 = LSM303D(i2c)
    switch = Switch()
    speed_pid = PID(target=500, kp=.4, ki=.2, kd=.1)
    uav['pid'] = speed_pid
    timestamp = None
    w = 0

    screen_renderers = [
        render_gps_screen, render_hud_screen, render_imu_screen
    ]
    renderer_idx = 0
    render_screen = screen_renderers[renderer_idx]

    switch.callback(switch_cb)

    while True:
        # retrieving data
        accel, mag = lsm303.read()

        if serial_port.any():
            nmea_line = str(serial_port.readline(), 'utf-8')

        # processing data
        x, y, z = accel
        x, z, y = mag
        uav['imu']['north'] = atan2(y, x) * 180.0 / pi

        if nmea_line:
            update_gps_data(nmea_line)
            nmea_line = None

        # sending orders
        if renderer_idx % 2:
            if timestamp:
                pid_value = speed_pid.update(
                    uav['speed'],
                    elapsed_millis(timestamp) / 1000.0)
                adjust_throttle(serial_port, pid_value)

            timestamp = millis()

        if SIGNALS[0] & SIGNAL_USR:
            renderer_idx = renderer_idx + 1
            render_screen = screen_renderers[renderer_idx %
                                             len(screen_renderers)]
            SIGNALS[0] = SIGNALS[0] & ~SIGNAL_USR

        render_screen(disp.framebuf, uav)

        disp.send_buffer()
        delay(50)