Open mv json data

Hi everyone,

I am working on a computer vision project using OpenMV to measure filament diameter. I send configuration commands to the camera via USB VCP from a custom desktop interface.

I am trying to save a calibration value to the camera’s local flash storage in JSON format (kalibrasyon.json). However, when my script tries to execute open("kalibrasyon.json", "w"), I get an “Access Denied” error in the OpenMV IDE, and the file cannot be written.

Here is the relevant part of my code:

Python

import sensor, image, time, pyb, json, os

usb = pyb.USB_VCP()
CAL_FILE = "/kalibrasyon.json"

while True:
    if usb.any():
        cmd = usb.readline().decode().strip()
        if cmd.startswith("SET_CAL:"):
            val = float(cmd.split(":")[1])
            # Getting "Access Denied" error on the below write operation
            with open(CAL_FILE, "w") as f:
                f.write(json.dumps({"scale": val}))
            
            usb.write(json.dumps({"status":"ok", "scale":val})+"\n")

Is there a specific permission, mount setting, or workaround required to write data to the flash memory dynamically while the while True loop is running?

Any help is appreciated. Thanks!

It’s because / is the root of the file system which doesn’t exist. /sdcard and /flash are the two drives you can write to. The camera cds into /sdcard if it exists or uses /flash. Remove the / from your path.