sensor.snapshot and rpc


I have been using a modified version of the image_transfer_raw_as_the_controller_device example (and its corresponding remote version) in order to get a picture from both the remote and the controller device (2 OpenMV H7 cameras).
It works fine but, as soon as I try to get a snapshot on the controller device at the same time as I am getting the pic from the remote cam, I am getting a black image from the remote cam.

If I get the snapshot on the controller side before starting any communication with the remote cam, then everything is fine.

I have attached the code for the controller and the remote device. On the controller side, setting use_pin_synchro to True or False simulates the 2 situations:

  • False: the pic is taken on the controller side before asking a pic to the remote cam: this works fine
  • True: the pic is taken juste before getting the bytes from the remote cam.

The idea behind all this is to use a pin between the 2 cameras to synchronise perfectly the 2 snapshots. You can see several lines of codes that are currently commented in order to do so.

Could someone help me understanding what I am doing wrong here?

Thanks a lot!


Nicolas (1.71 KB) (2.16 KB)

Hi, the issue is that you ignored the huge warning about how fast the data is about to come (I believe the default script mentions this).

When you call “raw_image_read” the slave starts a DMA transfer over the SPI bus and starts dumping the data immediately. This is done outside of the RPC context to avoid having to do a CRC over all the data.

When you do the pin sync logic you delay receiving the data which you cannot do in this case.

To fix this, I would use an external sync pin and have both cameras wait on that pin to capture an image. The clean way to do this is to use an rising/falling edge interrupt. Then in the interrupt handler call micropython.schedule() with a callback to a method that will capture the image and then set a flag.

Then have a main loop which is just checking if the flag was set, if so, it clears it and then starts the RPC call to grab the image.

Finally, then just make sure the sync freq is less than what the whole process above takes.

That said, the OV7725 isn’t a synced camera. If you are using that… I wouldn’t bother trying to sync up the camera images. The OV7725 is just running constantly always.


Thanks for your quick response.
A huge warning was indeed in the example! But, at some point, I removed it in my code and did not think about it anymore :unamused:

Taking into account your advices, I am now able to get something running.

Thanks a lot,