Global Shutter LED Out

Discussion related to "under the hood" OpenMV topics.
User avatar
CameraMan
Posts: 21
Joined: Thu Apr 09, 2020 3:41 pm

Global Shutter LED Out

Postby CameraMan » Sat Apr 25, 2020 11:19 am

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?
-Chief Tinkering Officer
User avatar
iabdalkader
Posts: 1180
Joined: Sun May 24, 2015 3:53 pm

Re: Global Shutter LED Out

Postby iabdalkader » Sat Apr 25, 2020 1:31 pm

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.
User avatar
kwagyeman
Posts: 4105
Joined: Sun May 24, 2015 2:10 pm

Re: Global Shutter LED Out

Postby kwagyeman » Sat Apr 25, 2020 1:45 pm

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: https://github.com/openmv/micropython/b ... 4/pins.csv - Add a name for the pin and then the hardware pin name and then it can be controlled via PYB.
Nyamekye,
User avatar
CameraMan
Posts: 21
Joined: Thu Apr 09, 2020 3:41 pm

Re: Global Shutter LED Out

Postby CameraMan » Sat Apr 25, 2020 2:19 pm

Awesome Thanks!
-Chief Tinkering Officer
User avatar
CameraMan
Posts: 21
Joined: Thu Apr 09, 2020 3:41 pm

Re: Global Shutter LED Out

Postby CameraMan » Sat Apr 25, 2020 3:00 pm

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:

Code: Select all

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?
Last edited by CameraMan on Sat Apr 25, 2020 3:36 pm, edited 1 time in total.
-Chief Tinkering Officer
User avatar
kwagyeman
Posts: 4105
Joined: Sun May 24, 2015 2:10 pm

Re: Global Shutter LED Out

Postby kwagyeman » Sat Apr 25, 2020 3:08 pm

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.
Nyamekye,
User avatar
CameraMan
Posts: 21
Joined: Thu Apr 09, 2020 3:41 pm

Re: Global Shutter LED Out

Postby CameraMan » Sat Apr 25, 2020 10:33 pm

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:

Code: Select all

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.
-Chief Tinkering Officer
User avatar
kwagyeman
Posts: 4105
Joined: Sun May 24, 2015 2:10 pm

Re: Global Shutter LED Out

Postby kwagyeman » Sun Apr 26, 2020 12:55 am

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

Follow this guide:

https://github.com/openmv/openmv/wiki (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.
Nyamekye,
User avatar
CameraMan
Posts: 21
Joined: Thu Apr 09, 2020 3:41 pm

Re: Global Shutter LED Out

Postby CameraMan » Sun Apr 26, 2020 1:14 am

Perfect Ill give it a go. No need to do it for me. This should be more than a enough. Thanks again!
-Chief Tinkering Officer
User avatar
CameraMan
Posts: 21
Joined: Thu Apr 09, 2020 3:41 pm

Re: Global Shutter LED Out

Postby CameraMan » Sun Apr 26, 2020 3:32 pm

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:

Code: Select all

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

Code: Select all

LED_OUT,PA15
Build information:

Code: Select all

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
Attachments
OPENMV4P.bin.zip
(1.16 MiB) Downloaded 11 times
OPENMV4.bin.zip
(1.16 MiB) Downloaded 18 times
Test VGA stock Firmware.jpg
Test VGA custom Firmware.jpg
-Chief Tinkering Officer
User avatar
kwagyeman
Posts: 4105
Joined: Sun May 24, 2015 2:10 pm

Re: Global Shutter LED Out

Postby kwagyeman » Sun Apr 26, 2020 4:36 pm

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?
Nyamekye,
User avatar
CameraMan
Posts: 21
Joined: Thu Apr 09, 2020 3:41 pm

Re: Global Shutter LED Out

Postby CameraMan » Sun Apr 26, 2020 4:49 pm

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.

Code: Select all

# 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.
-Chief Tinkering Officer
User avatar
kwagyeman
Posts: 4105
Joined: Sun May 24, 2015 2:10 pm

Re: Global Shutter LED Out

Postby kwagyeman » Sun Apr 26, 2020 5:17 pm

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.
Nyamekye,

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 5 guests