Program unable to run independently on camera

Hi there, we are trying to send numbers from the cam to our arduino board via UART. However, testing with other code that we uploaded on the camera, they were able to run fine and we were able to receive stuff on the arduino board so there is probably no issue with the UART connection. However, when we uploaded this code through “Save Open Script to OpenMV Cam” we were not able to receive anything. Hope yall can look through the code. Thanks!

 
 import sensor, image, pyb, time
from pyb import UART

#setup sensor
sensor.reset()
sensor.set_contrast(1)
sensor.set_gainceiling(16)
sensor.set_framesize(sensor.HQVGA)
sensor.set_pixformat(sensor.GRAYSCALE)

face_cascade = image.HaarCascade("frontalface", stages=25)
eyes_cascade = image.HaarCascade("eye", stages=24)

uart = pyb.UART(3, 115200)

while (True):

     img = sensor.snapshot()
     objects = img.find_features(face_cascade, threshold=0.9, scale=1.5)

     for face in objects:
       if face [2] in range (80,85) and face [1] in range (25,55) and face [0] in range (60,110): uart.write("4")
       if face [1] in range (0,25) and face [0] in range (60,110): uart.write("0")
       if face [1] in range (55,200) and face [0] in range (60,110): uart.write("2")
       if face [0] in range (0,60) and face [1] in range (25,55): uart.write("3")
       if face [0] in range (110, 200) and face [1] in range (25,55): uart.write("1")
       time.sleep (500)

Hi, make the “uart = pyb.UART(3, 115200)” read as “uart = pyb.UART(3, 115200, timeout_char=1000)”. Also, update to firmware version 2.6 here: Releases · openmv/openmv · GitHub. Use the OPENMV3/firmware.bin to update your OpenMV Cam.

You’re encountering a bug with the OpenMV Cam not saving the file after being unmounted because Windows SCSI USB flash drivers for FAT12 disks are buggy (Linux and Mac drivers for FAT12 devices are also buggy). In particular, they don’t flush writes to the disk even after being told to do so… repeatedly by OpenMV IDE. Version 2.6 fixes with with the last MP (version 1.9.2) build.

Alternatively, use an SD card with your OpenMV Cam. The problem goes away then since the SD card is FAT16/32 and the drivers on PCs handle these type of disks correctly. I.e. They save all the files to the disk when an unmount is requested.
Or, just wait about 5 minutes and the OS will eventually flush the file.
Or finally, write a bunch of other files to cause the old write to get flushed.

Note that the OS updates the file… but, never flushes the directory meta data so the file looks as if ti’s zero bytes long. This is because on a file being written its truncated to zero bytes first, data is written, and the size is updated.

(Yes, I got your script working without the IDE).