JeVois Tutorials  1.14
JeVois Smart Embedded Machine Vision Tutorials
Share this page:
Parsing serial messages from JeVois using Python

Many machine vision modules running on JeVois send messages over serial port (either the hardware 4-pin connector, or the serial-over-USB port) to indicate what they have found (e.g., detected ArUco marker IDs, decoded QR-Code contents, identified TensorFlow objects).

Objective

In this tutorial, we will write a simple Python program to read and parse the messages sent by JeVois over serial.

Getting started

The Python program

1 #!/usr/bin/python
2 
3 # Needed packages: sudo apt install python-serial
4 
5 # This tutorial is a simple program that allows one to read and parse serial messages from JeVois
6 
7 serdev = '/dev/ttyACM0' # serial device of JeVois
8 
9 import serial
10 import time
11 
12 with serial.Serial(serdev, 115200, timeout=1) as ser:
13  while 1:
14  # Read a whole line and strip any trailing line ending character:
15  line = ser.readline().rstrip()
16  print "received: {}".format(line)
17 
18  # Split the line into tokens:
19  tok = line.split()
20 
21  # Skip if timeout or malformed line:
22  if len(tok) < 1: continue
23 
24  # Skip if not a standardized "Normal 2D" message:
25  # See http://jevois.org/doc/UserSerialStyle.html
26  if tok[0] != 'N2': continue
27 
28  # From now on, we hence expect: N2 id x y w h
29  if len(tok) != 6: continue
30 
31  # Assign some named Python variables to the tokens:
32  key, id, x, y, w, h = tok
33 
34  print "Found ArUco {} at ({},{}) size {}x{}".format(id, x, y, w, h)
35 

Note how the empty "received:" statements are because we have a chosen timeout of 1 second when opening the serial port, and JeVois was not looking at any ArUco for the first 5 seconds of this example.

Troubleshooting

If you see nothing, review this: