We want to make the OpenMV Cam more friendly to interface to other processors and we will now support Interface libraries for the camera to the Arduino and RaspberryPi. The plan is to offer interface libraries for:
The OpenMV Cam as slave processor over Aysnc Serial (UART, RX, TX) to the Arduino
The OpenMV Cam as an I2C Slave processor (SCL, SDA) to the Arduino
The OpenMV Cam as an SPI Slave processor (SS, SCK, MISO, MOSI) to the Arduino
The OpenMV Cam as slave processor over VCP Serial (USB) to the RapsberryPi (or any linux processor)
I have looked at porting the firmata library but it’s a rather large amount of code and functionality to emulate. For this library I’m trying a light touch.
The interface library modules will be written in python and then baked into the OpenMV Cam firmware as frozen modules. We want to do it this way so that you have access to the python code easily if you want to modify our library… but, otherwise, if you are using it unmodified it’s already onboard.
We will also supply the other half of the code running on the Arduino/Pi that will talk to the camera.
The plan is to make these 4 libraries just about control of the camera and not about running any particular functionality. This is so that others can build off of them.
Anyway, the point of this forum thread is to gather feedback on what features I should put in these interface libraries. Thoughts are welcome.
Here’s my plan for the library setup:
First there’s an init method which will create the library and the underlying hardware channel for you.
Second, you will register callbacks on the OpenMV Cam that can be run on receiving a command from the other device. Callbacks will execute on request from the host processor and return a response.
And that’s it. There will be no while(true): loop anymore in your code. Instead you just create the interface library device, register some callbacks with particular IDs that your host program should know, execute a method to enter an event loop, and then when the host program executes a command with the right ID the callback is run and you get data back. This gives you freedom to do whatever you want. The interface libraries primarily will deal with moving bytes across a link.
Next, for example purposes, I will have examples showing off the client (OpenMV Cam) and host side of the code for:
As an example, on the Arduino, the data structure being moved will be described in C and then on the OpenMV Cam the data structure will be serialized using the struct module to match the Arduino structure. On the Pi, the struct will just be un-packed in python.
I feel that setting up things in this way is very generic and allows folks to do anything they need and makes the I/O part easy. That said, I understand it requires some understanding of data-structures. However, I think having 8 examples should give folks enough tools to copy from to do what they need.
Note that this library code is designed to make the OpenMV Cam a slave device on-purpose since that’s the best way for other processors to handle the data rate from the camera.
… Regarding the VPC stuff. As time allows, I will work on features in the IDE to still be functional if the VPC port is used. Also, MicroPython technically enabled having two VPC ports now in the current firmware releases to it may be possible to have another VPC port that the IDE doesn’t have to share.