Saving To File

General discussion about topics related to OpenMV.
jpreese246@gmail.com
Posts: 1
Joined: Sat Apr 14, 2018 10:40 pm

Saving To File

Postby jpreese246@gmail.com » Sat Apr 14, 2018 10:43 pm

Hello everyone. I can successfully save a barcode payload to the SD card on the OpenMV. However, my operating system does not recognize that a file has been saved on the SD card until I reset the open MV. For my application, i want to detect when a new file is present, and then perform an action. I cannot do this correctly because I have to cycle power to the OpenMV camera to recognize that a new file has been created.

Is there a way in Micropython to save to the desktop of the computer that the Open MV is plugged into via the USB? Or, is there a way around having to restart the OpenMV to detect that a new file has been saved to the SD card?

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

Re: Saving To File

Postby kwagyeman » Sun Apr 15, 2018 3:36 am

Desktop OSes won't rescan the flash drive unless plugged in. There's no fix for this. The camera acting as a USB drive which can create files is not something handled by today's desktop OS drivers.

You can however manually reset the OpenMV Cam in your script by issuing this command:

pyb.hard_reset()

...

An alternative method is just to print out the bardcode value. Anything that opens the OpenMV Cam's VCP UART will see the print data as text as whatever baud rate they open the OpenMV Cam serial port at. Note that you have to disconnect OpenMV IDE. But, it's pretty easy to get your script working with print and be good... and then use another program to read the printed data.
Nyamekye,
User avatar
aakoch
Posts: 24
Joined: Wed Dec 06, 2017 11:07 pm

Re: Saving To File

Postby aakoch » Sat Apr 21, 2018 12:07 am

What OS do you have? I am on a Mac with macOS High Sierra.

This is what I did. I wrote a program that prints the output:

Code: Select all

import pyb

while(True):
    print("Hello, World")
    pyb.delay(500)
I saved that to the camera then reset the camera.

I then found out the serial device name. You can do that through OpenMV IDE or by running

Code: Select all

ls /dev/cu.*
and finding the USB port.

I used the command

Code: Select all

screen /dev/cu.usbmodem1411 115200
to connect to my camera and verified it was printing to that serial port. (Use CTRL-A, then CTRL-\ to quit)

Next, I Google'd how to pipe a serial port and found this: https://superuser.com/a/710840/141346
(There is also using an app called miniterm, but I didn't try that.)

After some failed attempts, I was able to compile the code using XCode. I created a new project targeted for macOS and pasted the code into the main.cpp file and built the app. In the file viewer on the right I found the executable, found the location and copied it to my directory.

Then run the command

Code: Select all

./comm3 /dev/cu.usbmodem1411 115200 > serial_outfile.txt &
. (My project was named "comm3" hence the name of the executable.) I'm piping the output to serial_output.txt and letting that run in the background.

I can then run

Code: Select all

tail -f serial_outfile.txt
to watch the file being written.

Hopefully this helps.

Adam

Return to “General Topics”

Who is online

Users browsing this forum: No registered users and 5 guests