Global Shutter LED Out

Hello, I am trying to get the global shutter camera module to sync to a LED flash. From looking at the Docs I can see that the MT9V034 has an LED_OUT on SPI3_SSEL.

What I want to do is get that into a pyb pin, so I can do stuff with it. How would one go about this?

You would configure it as ExtInt but this pin doesn’t have an alias like (P0, P1 etc…) so it’s not accessible from pyb.

Um, it, you can make an alias for it and recompile the firmware and then it will appear in PYB. Or, you can use the stm module to directly access registers and bypass everything.

You just need to build the firmware and modify this file: micropython/pins.csv at abc992e9401f98829e07465c3836601b07358a37 · openmv/micropython · GitHub - Add a name for the pin and then the hardware pin name and then it can be controlled via PYB.

Awesome Thanks!

Hmm maybe im going about this the wrong way, Im using the motor shield as a led driver, here is how I have it setup for pinA of the H-Bridge:

pinA = pyb.Pin('P3', pyb.Pin.OUT_PP, pyb.Pin.PULL_NONE)
tim = pyb.Timer(4, freq=1000)
pinAPower = tim.channel(1, pyb.Timer.PWM, pin=pyb.Pin("P7"), pulse_width_percent=20)

Im trying to get the LED Out of the global shutter to trigger PinA.Value(1) to true.

Would a better way better to use push pull or something else, instead to getting LED Out to a pyb pin?

Um, you’d have to manually wire things up. So, no.

Just use an external interrupt to modify the state of the PWM on the interrupt.

Ok been spinning my wheels on this.
According to the docs:
“There are a total of 22 interrupt lines. 16 of these can come from GPIO pins and the remaining 6 are from internal sources.”

Given the example:

extint = pyb.ExtInt(pin, pyb.ExtInt.IRQ_FALLING, pyb.Pin.PULL_UP, callback)

How can I define “pyb.ExtInt(pin” if the pin does not have alias? The drawings for the sensor say LED_OUT on SPI3_SSEL does that mean in looking for interrupts on SPI 2 SS (Serial Select) → P3 (PB12)?

I think the piece I’m missing is what is LED_OUT labeled so I can define it some where.

You have to recompile the firmware. See the file I linked to above.

Follow this guide:

Home · openmv/openmv Wiki · GitHub (make sure to clone recursively).

The make file TARGET is OPENMV4… e.g. make TARGET=OPENMV4

Firmware output will be in src/build.

Note, you may run into an issue related to MicroPython’s cross compiler. You will likely have to make it separately before the main firmware build. So, cd into src/micropython and follow the README in there to build their cross compiler.

Finally, update the file I linked to above with an alias (e.g. the name in MicroPython) and then the actual pin name (e.g. PB12 or something like that). You can get the actual pin name from the Eagle schematic. Note, the alias can just be the actual pin name.

Once this is done the Pin Alias can now be created as a Pin object like other pins and you can attach an interrupt to it and etc.

Use OpenMV IDE → Tools → Run Bootloader to load the firmware.bin file in the build output.

I can also compile the firmware specially for you and just add this. However, if you can go through the above it will save you time waiting on me.

Perfect Ill give it a go. No need to do it for me. This should be more than a enough. Thanks again!

Got everything built but now there are different issues. Used TARGET=OPENMV4 ( I am using the The OpenMV cam h7 plus, so just to check I also repeated the following with TARGET=OPENMV4P which gave me the same image quality issues.)

The image quality is severly degraded on my custom firmware. Attached are two images taken from the stock firmware and my custom firmware. the helloworld_1.py example. The only thing changed in the helloworld_1.py was:

sensor.set_framesize(sensor.VGA)

The only changes made to source, micropython/ports/stm32/boards/OPENMV4/pins.csv I added the following:

LED_OUT,PA15

Build information:

MicroPython v1.12-omv-12-gabc992e94-dirty OpenMV v3.6.1-36-g5ec3a2a2-dirty 2020-04-26; OPENMV4-STM32H743

Attached are the following files:
OPENMV4.zip : this is built using TARGET=OPENMV4
OPENMV4P.zip : this is built using TARGET=OPENMV4P (I did not change anything in the pin.csv on this build since PA15 was already defined as PA15)
Test VGA custom Firmware.jpeg : this is sensor snapshot using custom firmware.bin
Test VGA stock Firmware.jpeg : this is a sensor snapshot using stock firmware.bin
OPENMV4P.bin.zip (1.16 MB)
OPENMV4.bin.zip (1.16 MB)
Test VGA custom Firmware.jpg
Test VGA stock Firmware.jpg

I have no idea… The only thing I can think is that there’s an issue with the driver on the latest firmware. So, it’s not your issue.

We will be doing a new firmware release soon. But, I don’t have time to debug this until I get to that. Probably in 2 weeks. In the mean-time. Assuming I can fix the image quality in the next release could you keep moving forward?

Yea, I have it sort of working using using the firmware built from the git releases with the pin defined as PA15. However the syncing is still not working. Im sure its something in my code. Ill keep trying to tweak it. All I’m trying to do is create an example for the community, with the hope it could make it into the IDE examples.

# Global Shutter Camera and Flash Sync Example
#
# 

import sensor, image, time, pyb

sensor.reset()                      # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA)   # Set frame size to QVGA (320x240)
sensor.skip_frames(time = 2000)     # Wait for settings take effect.
sensor.set_auto_exposure(True, exposure_us=500) #Set Exposure Time
clock = time.clock()                # Create a clock object to track the FPS.


#Setup Flash Stuff
tim = pyb.Timer(4)
tim.init(freq=1000)
tim.callback(lambda t:pinA.toggle())

pinA = pyb.Pin('P3', pyb.Pin.OUT_PP, pyb.Pin.PULL_NONE)
pinAPower = tim.channel(1, pyb.Timer.PWM, pin=pyb.Pin("P7"), pulse_width_percent=10)

extint = pyb.ExtInt('PA15', pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_NONE, tim.callback)

while(True):
    clock.tick()                    # Update the FPS clock.
    img = sensor.snapshot()         # Take a picture and return the image.
    print(clock.fps())              # Note: OpenMV Cam runs about half as fast when connected
                                    # to the IDE. The FPS should increase once disconnected.

Note, you have to actually do the ioctl to enable the camera to be triggered off of snapshot. Then for that I/O pin it’s probably not on by default and you need to enable it via a register setting on the camera. See the camera datasheet.