share my UART receive code

Discussion related to "under the hood" OpenMV topics.
laiyingjie
Posts: 10
Joined: Thu Nov 16, 2017 4:57 pm

share my UART receive code

Postby laiyingjie » Tue Nov 21, 2017 6:01 pm

global_list.py:

Code: Select all

buf = bytearray(30)
main.py:

Code: Select all

import global_list
import sensor
import time, sensor, pyb
from pyb import UART
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.VGA)
sensor.skip_frames()
uart = UART(3, 9600)
led = pyb.LED(3)
clock = time.clock()
while(True):
    clock.tick()
    img = sensor.snapshot()
    print(clock.fps())
    if (uart.any()):
        uart.readinto(global_list.buf)
        print(global_list.buf)
        if global_list.buf[0] == 0xAA:
            led.on()
        if global_list.buf[1] == 0xAB:
            led.off()

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 5 guests