Page 2 of 2

Re: Advanced Iris Tracking Software

Posted: Tue Apr 17, 2018 1:38 pm
by kwagyeman
Only one program can read the serial port at a time. But, once you have the script working in OpenMV IDE... Save the script to the camera, reset the camera, and then open the serial port in another application.

Re: Advanced Iris Tracking Software

Posted: Fri Apr 20, 2018 3:06 pm
by s-bbrackett
I guess if you want a simpler answer, I simply want to take data off of the camera and onto visual studios.

Re: Advanced Iris Tracking Software

Posted: Fri Apr 20, 2018 3:07 pm
by s-bbrackett
Sorry I didn't see your last post. So, I can write just a print statement and use the IDE terminal with the saved code and it will pickup on VS?

Re: Advanced Iris Tracking Software

Posted: Fri Apr 20, 2018 7:33 pm
by kwagyeman
Yes.

Note: On opening the VCP port make the DTR line active. The MicroPython OS will not print data unless this is active.

Re: Advanced Iris Tracking Software

Posted: Mon Apr 23, 2018 10:47 am
by s-bbrackett
Excuse my beginner questions but how to I work the DTS and RTS? I have a RTS function in visual studios but I'm not sure how it works in Micropython.


Thanks

Re: Advanced Iris Tracking Software

Posted: Mon Apr 23, 2018 11:16 am
by s-bbrackett
*DTR

Re: Advanced Iris Tracking Software

Posted: Mon Apr 23, 2018 11:47 am
by kwagyeman
After opening the serial port make sure to set the line. I can give you a snippet of Qt C++ code for example. This is one line of code normally.

Re: Advanced Iris Tracking Software

Posted: Mon Apr 23, 2018 3:06 pm
by s-bbrackett
While I don't need the code for Qt, how do I write the code in micropython?

Re: Advanced Iris Tracking Software

Posted: Mon Apr 23, 2018 3:52 pm
by kwagyeman
Nothing has to be done on the cam for this. Just print data.

Re: Advanced Iris Tracking Software

Posted: Mon Apr 23, 2018 4:34 pm
by s-bbrackett
So no settings, no code? Just save and reset?

Re: Advanced Iris Tracking Software

Posted: Tue Apr 24, 2018 1:08 am
by kwagyeman
Hey man, you may wish to try by doing o_o.

Re: Advanced Iris Tracking Software

Posted: Tue Apr 24, 2018 10:38 am
by s-bbrackett
Hey if you could show me a bit of that Qt code, maybe that might help my issues. A while ago, I sent you a post with the current settings/variables in my VS code. If those could clear anything up, let me know.


Thanks.

Re: Advanced Iris Tracking Software

Posted: Tue Apr 24, 2018 11:09 am
by s-bbrackett
If you understand C#, let me know and I could send you a bit of my code.

Re: Advanced Iris Tracking Software

Posted: Wed Apr 25, 2018 2:03 am
by kwagyeman
Paste it. Use the code tags.

Re: Advanced Iris Tracking Software

Posted: Wed Apr 25, 2018 10:33 am
by s-bbrackett
Here you go:

Code: Select all

using System;
using System.IO.Ports;
using System.ComponentModel;

namespace EyeStuff
{
    class PortDataReceived
    {
        

        public static void Main()
        {
            SerialPort mySerialPort = new SerialPort("COM3");

            mySerialPort.BaudRate = 115200;
            mySerialPort.Parity = Parity.None;
            mySerialPort.StopBits = StopBits.One;
            mySerialPort.DataBits = 8;
            mySerialPort.Handshake = Handshake.None;
            mySerialPort.RtsEnable = true;

            mySerialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
           
            mySerialPort.Open();

            Console.WriteLine("Press any key to continue...");
            Console.WriteLine();
            Console.ReadKey();
            mySerialPort.Close();
        }

        private static void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
        {
            SerialPort sp = (SerialPort)sender;
            string indata = sp.ReadExisting();
            Console.WriteLine("Data Received:");
            Console.Write(indata);
        }
    }
}

Re: Advanced Iris Tracking Software

Posted: Thu Apr 26, 2018 3:07 am
by kwagyeman
Okay, is it working?

Re: Advanced Iris Tracking Software

Posted: Thu Apr 26, 2018 10:30 am
by s-bbrackett
The code compiles with no errors and it runs it's "Press any key" part, but it never prints out any data. At this point, I really don't know what the problem could be besides that I forgot something. Please let me know if you have any suggestions.

Thanks

Re: Advanced Iris Tracking Software

Posted: Thu Apr 26, 2018 6:04 pm
by s-bbrackett
Never mind I got it working. However, I wanted to say thank you for your help with the DTR. I forgot one line of code within my script and when I fixed it, everything worked fine. Thanks again.

Re: Advanced Iris Tracking Software

Posted: Fri Apr 27, 2018 1:58 am
by kwagyeman
Great to hear!

Re: Advanced Iris Tracking Software

Posted: Thu May 03, 2018 11:24 am
by s-bbrackett
Hey I'm back again.
I just wanted to know, if I were to use serial pins to communicate between the two cameras, I would ONLY use pins 4 and 5, right? This is also the simplest way to communicate between the two correct?

Thanks.

Re: Advanced Iris Tracking Software

Posted: Fri May 04, 2018 12:31 am
by kwagyeman
Yes, communication is just a serial port between the two devices then. It's full duplex. You can use the struct module to send binary messages and decode them. Or, you can send data as text.

Re: Advanced Iris Tracking Software

Posted: Fri May 04, 2018 10:39 am
by s-bbrackett
So I can just use the print function to send text, and then create a statemachine on the other end to receive it?

Re: Advanced Iris Tracking Software

Posted: Fri May 04, 2018 10:44 am
by s-bbrackett
I guess the better way to phrase it would be, what's the easiest way to receive data sent by the print command.

Re: Advanced Iris Tracking Software

Posted: Fri May 04, 2018 11:14 am
by kwagyeman
No, use this:

import time
from pyb import UART

# Always pass UART 3 for the UART number for your OpenMV Cam.
# The second argument is the UART baud rate. For a more advanced UART control
# example see the BLE-Shield driver.
uart = UART(3, 19200, timeout_char = 1000)

while(True):
uart.write("Hello World!\r")
time.sleep(1000)

uart.write() accepts any formatted string. So, you can use python string formatting there. See all the uart methods: http://docs.openmv.io/library/pyb.UART. ... light=uart

Re: Advanced Iris Tracking Software

Posted: Fri May 04, 2018 11:26 am
by s-bbrackett
Awesome! So if that sends strings, how to I receive the strings? Also, don't need to declare the pins anywhere, correct?

Re: Advanced Iris Tracking Software

Posted: Sat May 05, 2018 2:34 pm
by kwagyeman
UART(3) is fixed to the same I/O pins.

As for receiving data. Please read the UART methods. In general, you want to call any() to see how many bytes are available and then read() that many bytes. If you'd like to see a great example... please see the Pixy Emulation UART script.

Re: Advanced Iris Tracking Software

Posted: Mon May 07, 2018 10:48 am
by s-bbrackett
OK so I understand the code, but can I give you an example of how my physical pin system is set up? My system has two openMV cams both plugged into the computer via micro-USB cords. The two cams are then connected with two wires vis pins 4 and 5. Lastly, the camera that sends eye data is disconnected from the openMv IDE while the other is connected. Does this all sound about right?


Thanks again.

Re: Advanced Iris Tracking Software

Posted: Mon May 07, 2018 11:11 pm
by kwagyeman
Yes, make sure both cameras share grounds and that RX plugs into TX of the other camera and TX plugs into RX of the other camera.

Re: Advanced Iris Tracking Software

Posted: Tue May 08, 2018 10:42 am
by s-bbrackett
Thank you, now I have this code as a start but I know its wrong. Could you tell/show me what else I need to add to it.

Code: Select all

uart = UART(3, 19200, timeout_char = 1000)

while(True):
    inData = uart.any()
    print(inData);
    time.sleep(1000)

Re: Advanced Iris Tracking Software

Posted: Wed May 09, 2018 1:08 am
by kwagyeman

Code: Select all

uart = UART(3, 19200, timeout_char = 1000)

while(True):
    count = uart.any()
    if count:
    	print(uart.read(count))
    	time.sleep(1000)

Re: Advanced Iris Tracking Software

Posted: Wed May 09, 2018 10:54 am
by s-bbrackett
Thank you. So, I have everything all connected via pins 4 and 5, and my system has two connecting ground pins. Then I have one of the cameras plugged into the IDE while the other is disconnected. However, I still am not reading any data on my receiving camera. Do you have any ideas of what could be wrong?

Thanks

Re: Advanced Iris Tracking Software

Posted: Wed May 09, 2018 11:55 am
by kwagyeman
The code only prints to the IDE. If you want to send data over the UART you have to call the usrt.write() method. Print sends data back to the PC over USB.

Re: Advanced Iris Tracking Software

Posted: Wed May 09, 2018 12:46 pm
by s-bbrackett
So I replace all the example code you gave me with usrt?

Re: Advanced Iris Tracking Software

Posted: Wed May 09, 2018 1:43 pm
by s-bbrackett
If you want I can send you examples of my sending code. The code that's receiving the data is the code that you provided for me.

Re: Advanced Iris Tracking Software

Posted: Wed May 09, 2018 10:21 pm
by kwagyeman
Okay, I'll take a look.

Re: Advanced Iris Tracking Software

Posted: Thu May 10, 2018 10:37 am
by s-bbrackett
So for my sending code I have,

Code: Select all

uart = pyb.UART(3, 115200)

while (True):
    clock.tick()
    # Capture snapshot
    img = sensor.snapshot()
    # Find eyes !
    # Note: Lower scale factor scales-down the image more and detects smaller objects.
    # Higher threshold results in a higher detection rate, with more false positives.
    eyes = img.find_features(eyes_cascade, threshold=0.5, scale=1.5)

    # Find iris
    for e in eyes:
        iris = img.find_eye(e)
        img.draw_rectangle(e)
        img.draw_cross(iris[0], iris[1])
        uart.write("!EYE x:%d, y:%d, w:%d, h:%d" % e)
        uart.write("!IRIS x:%d, y:%d" % iris)
Then for my receiving code I have

Code: Select all

uart = UART(3, 19200, timeout_char = 1000)

#LED
blue_led = LED(3)

while(True):
    count = uart.any()
    if count:
        print(uart.read(count))
        blue_led.on()
        time.sleep(1000)
The pins are then setup as I described before.

Thanks

Re: Advanced Iris Tracking Software

Posted: Thu May 10, 2018 4:32 pm
by s-bbrackett
Never mind I got it working. However, I was wondering if you could tell me how to pull a string out of a string. MY data is currently being transmitted in the format of

Code: Select all

uart.write("!EYE x:%d, y:%d, w:%d, h:%d" % e)
        uart.write("!IRIS x:%d, y:%d" % iris)
I want to have just the x and y data values at the end, and I am curious as how to go about it. Thank you.

Re: Advanced Iris Tracking Software

Posted: Thu May 10, 2018 4:52 pm
by kwagyeman
Hi, that would be a general purpose python question. You should Google about how to do that in Python and there's likely a lot of examples.

Re: Advanced Iris Tracking Software

Posted: Wed Sep 12, 2018 1:27 pm
by jiapei100
Are you using VSCode to debug OpenMV code?