Arduino UNO (master) to OpenMV v7 (slave) I2c

I have experimented in detail with using the OpenMV camera (slave) connecting to my Arduino Uno. I use appropriate pullup resisters and all is fine if I disable interrupts. I have simple working two-way demo code that is very very reliable.
[Have built a complex auto car that uses Arduino Uno and added the camera lately to the front, so it would be a great deal of work to make the camera master on I2C. In fact the I2C communication with the OpenMV as master still requires interrupts to be disabled - I have examples that show this explicitly]

However, with interrupts disabled I cannot connect to the IDE since it (of course) cannot interrupt the running code when I request a connection
I only disable interrupts when making the I2C call, so it is mostly fine.
So long as the Arduino is playing nicely (eating the data sent from the camera and writing data whenever the camera is waiting) there is not issue with this solution.

However, I would very much like to have timeouts working on the OpenMv recv and send requests. I am afraid that they won’t be working because I have interrupts disabled. If this is the case then I have a bricked OpenMV and have to reflash it - which is a pain.
So, can you tell me:

  1. whether the timeouts will work in pyb.I2C.recv and send when I have interrupts disabled.

  2. (Better still) Is there a way to just disable some interrupts - so that I2C works as slave) but the IDE interrupt still works? This would be great. I am happy to mod the source and build a custom firmware.

I have downloaded the source but cannot find documentation which explains micropython code architecture . I cannot even find how the REPL dispatches code to appropriate C routines. With enough doc I may be able to help myself more :slight_smile:

Hi, did you see the picture emulation i2c example script? It’s under examples. It shows how to use i2c while disabling interrupts for a very short time in order to not block the IDE.

Um, so, the main.c file is under src/omv/. And the MP code is under src/MicroPython/stmhal. You can find the I2C code there. That said, please see the example above.

Thanks for this,

The example pretty much does what I do - So IDE interrupt works well for me. However, it is possible that the Arduino will blocks or fail when this car is deployed (intended for public Science Festivals) for some reason.

So my question is - does the timeout 1 work even though interrupts are disabled? Or can it hang in the
bus.send(out_data_, timeout = 1)
line if no master ever sets the read conditions on the lines, so the data stays in the I2c buffer?

More important is whether bus.recv(… timeout=1) will be able to hang. I.E - how do recv and send handle the timeout when there are no interrupts?

My guess is that threads are no help here because, with interrupts disabled, threads do not get scheduled?

Just to confirm, my simple code does both read and write successfully, without requiring either the Arduino or the Camera to settle first. It does (of course) miss some comms, but this will be easy to deal with in the application protocol.


Um, so, can you use software serial in the Arduino and run a slow serial port ouput with the OpenMV Cam? I do that for my self driving robot car and it works very well.

Anyway, the way the code works for the OpenMV Cam I2C I wrote… Mainly it will miss communication between the Arduino if the Arduino polls before the camera is ready. Then, the system will loose the IDE connection if the Arduino is not polling at a fast enough frequency. That said, the camera doesn’t actually crash… Just USB stops working. So, when deployed in an application it should be fine.

Can’t use software serial. Actual serial ports on Arduino in use for Bluetooth. Can’t use serial on i2c lines because I have other I2c devices (which is why I need the Arduino to be master - to save writing libraries for OpenMV to operate these devices.)
Every other pin on the Arduino is already in use :slight_smile: so software serial not an option.

This is a “demo” self-driving car for teaching purposes. I would have liked it not even to have a camera (hence the design) - to show how (many) other sensors, together with a supportive infrastructure, can work.

However, I do not use differential steering, so I needed advance notice of environment changes since the turn latency is so high. Hence the (lovely) camera. Which is a real joy to play with - thanks so much :slight_smile:

I am very interested in the light (temperature) auto-balancing thread.

Great! Well for I2C, if you have some ideas on how to do a fifo buffer for it so the camera thread doesn’t have to be blocked on that the whole MP Community could use you input. We use the same drivers as the pyboard. So, any fix for our stuff can be upstreamed.