Tutorial Needed: Companion computer reading data

General discussion about topics related to OpenMV.
User avatar
jurban
Posts: 8
Joined: Wed May 30, 2018 12:17 am

Tutorial Needed: Companion computer reading data

Postby jurban » Wed Sep 05, 2018 1:51 am

Is there any tutorial that can demonstrate the code required to enable the OpenMV to send a data stream over a USB to a companion computer (Raspberry Pi, or a PC) running a python script? That script would then consume the data stream and executes a simple task. I need this to work without the IDE.

BTW, I've practically given up attempting to get a Windows-based terminal outside of the IDE to show the data stream from the USB COM port. Nothing works outside of the IDE's serial terminal. I've not found a clear description of how to view this data via a terminal.

Also, if anyone has a decent tutorial that provides a good overview of all of the communication protocols and devices, I'd greatly appreciate the link.

Thanks!
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: Tutorial Needed: Companion computer reading data

Postby kwagyeman » Wed Sep 05, 2018 2:52 am

>> BTW, I've practically given up attempting to get a Windows-based terminal outside of the IDE to show the data stream from the USB COM port. Nothing works outside of the IDE's serial terminal. I've not found a clear description of how to view this data via a terminal.

This is because you have to set the DTR line high. It's due to how micropython works. Once you do that in any terminal program they work. Similarly, you need to do this in any program that wants to talk to the camera on windows.

Note that this is only a problem on windows. As for talking to the camera over USB our protocol is in this script:

https://github.com/openmv/openmv/blob/m ... yopenmv.py
Nyamekye,
User avatar
jurban
Posts: 8
Joined: Wed May 30, 2018 12:17 am

Re: Tutorial Needed: Companion computer reading data

Postby jurban » Wed Sep 05, 2018 1:34 pm

That worked!

Next, the numerical output in the IDE Serial Terminal for the clock.fps is around 42 to 44. But, the third-party terminal I'm using (YAT) displays it as 84 - 85. It looks like it is doubling it - but not precisely. Any funny-business happening in the interim?

Also, I added a "test" output on the same print string. That comes through just fine. So, just the numerical output seems impacted.

Also, as a general best-practice: Do you recommend using the USB com port to communicate to a Raspberry Pi or should I consider the pin-outs instead? Issues to consider: Reliability, speed, time to initiate when powered up.

I'll dig into the pyopenmv.py script later today. Thanks for that reference!
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: Tutorial Needed: Companion computer reading data

Postby kwagyeman » Wed Sep 05, 2018 9:05 pm

USB is the fastest.

The frame rate sped up because you were no longer pulling images from the camera. Things are highly variable based on the camera load.
Nyamekye,
User avatar
jurban
Posts: 8
Joined: Wed May 30, 2018 12:17 am

Re: Tutorial Needed: Companion computer reading data

Postby jurban » Wed Sep 12, 2018 4:22 pm

Would you be able to provide a quick description on how to set up that pyopenmv.py script? What script is on the camera and which script is on the computer?

-or-

It would be nice to have a really simple set of scripts that take a text output from the camera's USB, passes it to a python script on a computer, translates it to something simple (e.g. 2="RED", etc), and prints it. Really simple. That would provide a perspective on the components and probably resolve the more obvious issues that newbies have with getting grounded on the system. I could build on that to accomplish my project objectives.
User avatar
jurban
Posts: 8
Joined: Wed May 30, 2018 12:17 am

Re: Tutorial Needed: Companion computer reading data

Postby jurban » Thu Sep 13, 2018 12:49 pm

Here is a really simple script that parses the messages inbound from the USB port and prints them to the terminal window. I've added comments so that a newbie such as myself could understand what is happening. Clarifications or criticisms on those descriptions are welcome.

Code: Select all

import serial, string, re

output = " " # Clear the output
ser = serial.Serial('COM3', 19200, 8, 'N', 1, timeout=1) # Setup the communication to the USB com port.  The "COM3" will change based on your OS and where the device is recognised.  Use the "mode" command in a terminal window to find which it is.
n = 8 # number of parameters in the message

while True:
  print "----"  # Visual spacer between outputs
  while output != "":  # Ensures that there is data coming in 
    output = ser.readline()  # Read in the serial values and assign it to the "output" variable.
    for i in range(n):  # Create a range to loop through. "n" is adjusted above.
	  i = output.split(",")[i] # Split the output by a comma, then select which value to assign to i.  i also becomes the variable's value.
	  print i  # Print it to the screen.
  output = " "  # Clear the output
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: Tutorial Needed: Companion computer reading data

Postby kwagyeman » Thu Sep 13, 2018 4:39 pm

Mmm, sorry for not responding immediately. I thought I did already. I do most forum responses on my phone.
Nyamekye,

Return to “General Topics”

Who is online

Users browsing this forum: No registered users and 4 guests