Hi, my application involves using a Portenta + Vision Shield to click and save images taken upon motion. Very rarely the system corrupts the main program itself, leading to operational failure.
I encountered this today again and noticed how the latest motion detection saved only 8/10 images, hence I suspect something went wrong at this image saving stage. I’m using a pretty standard approach to save the images.
# Click pictures
def click(n):
img = [None]*n # Empty array of size n to store images
time_of_motion = dt_format() # Datetime of motion
ir_lights.value(1) # Turn on IR lights
pyb.delay(100)
for i in range(n): # Click images, save in array and path
g_led.on()
img[i] = sensor.snapshot().rotation_corr(z_rotation=ROTATE)
img[i].save(f"{save_path}/{time_of_motion}_{i}.jpeg")
g_led.off()
pyb.delay(500)
ir_lights.value(0) # Turn off IR lights
g_led.off()
return(img)
I only suspect this is what causes the issue, not fully sure. I cannot think of any other reason this might be happening. Has anyone also encountered something similar?
PC
Are you saving images to the internal flash or an SDcard?
If a power loss happens while it’s saving images, then this occurs.
It looks like you are saving the files in a folder, which makes it more reliable.
Mmm, you might want to start building your script into the firmware to make it more robust. Do you have the build system for our firmware setup?
You’re right. I think this can happen sometimes in my case but not always. I mean, it’s def not the power this time cause my battery pack is pretty much full.
Sorry, I don’t know how to do that. Is there a tutorial I could follow to learn?
PC
You’ll need a Linux machine, but here’s the guide: openmv/docs/firmware.md at master · openmv/openmv · GitHub
When you build the firmware, it’s possible to inject the main.py into the firmware as a frozen script, which cannot be corrupted anymore. It will then always run on the system when it turns on. All of our customers who deploy the system in real applications do this.
After you do this, main.py is run whether or not an SD card is attached.
You can then detect if /sdcard is found and only write data in this case.
Thanks a ton, I’ll try this out!
PC
Hi again, I tried building the firmware (without any new program really, just wanted to do a dry run first) but encountered an error during
make -j$(nproc) TARGET=ARDUINO_PORTENTA_H7
I’m not sure how to proceed since the error seems to have come from some openmv/lib/micrppython/py/makeqstrdefs.py file and I’d rather not touch something I don’t know of. Just in case it’s important in any sense, I get this error in both full and sub cloning of the repo.
PC
Hi, it’s because you didn’t install the arm-none-eabi-gcc tools. This is the cross compiler.
Then add it to your path in your .bash_rc or etc.
Hi, thanks for that!
Sorry to be a bother but I genuinely have no idea about building a firmware and hence this most likely is stupid: what do you mean by “install”? Where am I supposed to place the arm-non-eabi-gcc tools? Is there another guide with these details?
PC
You download it. Untar it. Put it in /opt and then add it to your path.
Please consult ChatGPT on what that ci function is doing and it will walk you through the steps.
2 Likes
To simplify development, I’ve bundled all the toolchains and tools required for the build into an SDK. Once you pull the latest code, just run make sdk. This will install the required tools into a path recognized by the Makefile, and then you can build any target you need.