def main(): print("uart connection test") # Open /dev/ttyAMA1 with baudrate 115200 ser = Serial("/dev/ttyAMA1", 115200) print("Write to UART") ser.write(b"Hello from Atlas 200 DK\n") # Read up to 32 bytes, with timeout of 2 seconds readdata = ser.read(32, 2).decode('utf-8') print(f'Received reply: {readdata}')
def main(): parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('-m', '--model', required=True, help='File path of .tflite file.') parser.add_argument('-i', '--input', help='Image to be classified.') parser.add_argument('-l', '--labels', help='File path of labels file.') parser.add_argument('-k', '--top_k', type=int, default=1, help='Max number of classification results') parser.add_argument('-t', '--threshold', type=float, default=0.0, help='Classification score threshold') parser.add_argument('-c', '--count', type=int, default=5, help='Number of times to run inference') args = parser.parse_args() labels = read_label_file(args.labels) if args.labels else {} interpreter = make_interpreter(*args.model.split('@')) interpreter.allocate_tensors() _, height, width = interpreter.get_input_details()[0]['shape'] size = [height, width] trigger = GPIO("/dev/gpiochip2", 13, "out") # pin 37 # UART3, 9600 baud uart3 = Serial("/dev/ttymxc2", 115200) print('----INFERENCE TIME----') print('Note: The first inference on Edge TPU is slow because it includes', 'loading the model into Edge TPU memory.') #for i in range(1,351): while 1: #input_image_name = "./testSample/img_"+ str(i) + ".jpg" #input_image_name = "./testSample/img_1.jpg" #image = Image.open(input_image_name).resize(size, Image.ANTIALIAS) #arr = numpy.random.randint(0,255,(28,28), dtype='uint8') arr = uart3.read(784) #print(list(arr)) arr = numpy.array(list(arr), dtype='uint8') arr = numpy.reshape(arr, (28, 28)) image = Image.fromarray(arr, 'L').resize(size, Image.ANTIALIAS) common.set_input(interpreter, image) #inspector_start = int.from_bytes(uart3.read(1, 1), 'big') #print("read {:d} bytes: _{:s}_".format(len(inspector_start), inspector_start)) #print("Start Signal:", inspector_start) start = time.perf_counter() trigger.write(True) interpreter.invoke() trigger.write(False) inference_time = time.perf_counter() - start output_tensor = interpreter.get_tensor(1)[0] uart3.write(output_tensor.tobytes()) print('%.6fms' % (inference_time * 1000)) classes = classify.get_classes(interpreter, args.top_k, args.threshold) #print('RESULTS for image ', 1) for c in classes: print('%s: %.6f' % (labels.get(c.id, c.id), c.score))
import board import busio import time import adafruit_bme680 import json from periphery import Serial productUID = "com.[your-company].[your-product]" serial = Serial('/dev/ttyS0', 9600) serial.write(b'\n') req = {"req": "hub.set"} req["product"] = productUID req["mode"] = "continuous" serial.write(bytearray(json.dumps(req), 'utf8')) serial.write(b'\n') print(json.dumps(req)) data = serial.read(32, 0.5) if data is not None: data_string = ''.join([chr(b) for b in data]) print(data_string, end="") print("Notecard configured...") else: print('Notecard not connected...') i2c = busio.I2C(board.SCL, board.SDA) sensor = adafruit_bme680.Adafruit_BME680_I2C(i2c)
""" periphery uart 测试 """ from periphery import Serial try: # 申请串口资源/dev/ttymxc2,设置串口波特率为115200,数据位为8,无校验位,停止位为1,不使用流控制 serial = Serial( "/dev/ttymxc2", baudrate=115200, databits=8, parity="none", stopbits=1, xonxoff=False, rtscts=False, ) # 使用申请的串口发送字节流数据 "Hello World!\n" serial.write(b"Hello World!\n") # 读取串口接收的数据,该函数返回条件二者满足其一,一、读取到128个字节,二、读取时间超过1秒 buf = serial.read(128, 1) # 注:Python读取出来的数据类型为:bytes # 打印原始数据 print("原始数据:\n", buf) # 转码为gbk字符串,可以显示中文 data_strings = buf.decode("gbk") # 打印读取的数据量及数据内容 print("读取到 {:d} 个字节 , 以字符串形式打印:\n {:s}".format(len(buf), data_strings)) finally: # 释放申请的串口资源 serial.close()
#!/home/mendel/.virtualenvs/cv/bin/python import cv2 as cv import time from periphery import Serial serial = Serial("/dev/ttymxc2", 9600) #i2c2 = I2C("/dev/i2c-1") #pwm = PWM(0, 0) while(1): time.sleep(5) serial.write(b"2!") print ("2")
3. NXP reserves the right to make changes to the NXP Software/Sourcecode any time, also without informing customer. 4. Licensee agrees to indemnify and hold harmless NXP and its affiliated companies from and against any claims, suits, losses, damages, liabilities, costs and expenses (including reasonable attorney's fees) resulting from Licensee's and/or Licensee customer's/licensee's use of the NXP Software/Source Code. ''' from periphery import Serial from periphery import time #connect to serial port ttyUSB1 of Sigfox module connected to coral micro usb port with baudrate 115200 sigfox_serial_port = Serial("/dev/ttyACM0", 115200) #send wakeup sigfox_serial_port.write(b"1\n\r") time.sleep(0.2) #switch to RCZ1 for Europe sigfox_serial_port.write(b"15\n\r") time.sleep(0.2) #transmit payload sigfox_serial_port.write(b"4\n\r") time.sleep(0.2) #transmit payload sigfox_serial_port.write(b"h3p1t182803\n\r")
def add_central_line(frame, lines, line_color=(0, 0, 255), line_width=2): line_image = np.zeros_like(frame) x1, y1, x2, y2 = lines if lines is not None: cv.line(frame, (x1, y1), (x2, y2), line_color, line_width) print(x1, y1, x2, y2) #plt.imshow(frame) #line_image = cv.addWeighted(frame, 0.8, line_image, 1, 1) return frame def get_output_angle(x1, y1, x2, y2): num = y2 - y1 den = x1 - x2 if den == 0: return 90 degrees = math.degrees(math.atan(num / den)) return degrees line_offset = middle_line(raw_image, lane_lines_image) print(line_offset) degrees = get_output_angle(line_offset[0], line_offset[1], line_offset[2], line_offset[3]) end = time.time() print(end - start) print(degrees) uart3.write(b"Altranos")
import board import busio import time import adafruit_bme680 import json import notecard from periphery import Serial productUID = "com.[your-company].[your-product]" serial = Serial('/dev/ttyS0', 9600) serial.write(b'\n') card = notecard.OpenSerial(serial) req = {"req": "hub.set"} req["product"] = productUID req["mode"] = "continuous" print(json.dumps(req)) rsp = card.Transaction(req) print(rsp) i2c = busio.I2C(board.SCL, board.SDA) sensor = adafruit_bme680.Adafruit_BME680_I2C(i2c) while True: temp = sensor.temperature humidity = sensor.humidity print('Temperature: {} degrees C'.format(temp))
#!/home/mendel/.virtualenvs/cv/bin/python from periphery import Serial import time uart3 = Serial("/dev/ttymxc2", 9600) def output_uart(): uart3.write(b'popo'); time.sleep(5) uart3.write(b'popo');
#!/home/mendel/.virtualenvs/cv/bin/python from periphery import Serial import numpy as np import cv2 as cv import time import re import svgwrite import imp import os from edgetpu.detection.engine import DetectionEngine import gstreamer uart3 = Serial("/dev/ttymxc2", 9600) uart3.write(b'popo')