AI-on-the-edge-device icon indicating copy to clipboard operation
AI-on-the-edge-device copied to clipboard

Support for OV5640

Open CountParadox opened this issue 1 year ago • 15 comments

The Feature

Hi guys,

I have this module: https://www.aliexpress.com/item/1005004521039608.html?aem_p4p_detail=20230311200737107046978822230007724708&algo_exp_id=973ada50-63fc-40e0-91c3-87db4e401cd5-2&pdp_ext_f=%7B%22sku_id%22%3A%2212000031106421469%22%7D&pdp_npi=3%40dis%21AUD%2136.52%2123.0%21%21%21%21%21%40211bf3f716785940569804937d06c0%2112000031106421469%21sea%21AU%212214764457&curPageLogUid=fhcmfz3jOSwK&ad_pvid=20230311200737107046978822230007724708_3&ad_pvid=20230311200737107046978822230007724708_3

I think the inclusion of USB-C is very convenient. I think it should be quite simple to support, maybe just changing the pinouts defined in the code? I was able to get it working with ESPhome very easily by doing this.

What are others opinion?

Thanks

image image image image image image

CountParadox avatar Mar 12 '23 04:03 CountParadox

Did you try if it works?

AFAIK there is no pinout configuration, we simply use the ESP library which provides the support for the different cameras. See https://github.com/espressif/esp32-camera/tree/5c8349f4cf169c8a61283e0da9b8cff10994d3f3

caco3 avatar Mar 13 '23 20:03 caco3

Compared to the currently used camera (OV2640), it has a higher resolution, thus memory might be an issue! (2592 x 1944 vs. 1600 x 1200)

caco3 avatar Mar 13 '23 20:03 caco3

@caco3 looks like its supported by the underlying library, but I need to be able to define the pins its connected to, I forked and had a go at this but I am pretty bad at code... The increased resolution may not be an issue given that its not running video, just stills ?

CountParadox avatar Mar 13 '23 23:03 CountParadox

It could possibly work with some modifications:

Camera pinouts are defined here: https://github.com/jomjol/AI-on-the-edge-device/blob/933215c1164d8b2b816a87ad42df185563939b1b/code/include/defines.h#L201

Additionally this flag needs to set: https://github.com/jomjol/AI-on-the-edge-device/blob/933215c1164d8b2b816a87ad42df185563939b1b/code/sdkconfig.defaults#L135

Be aware, that for other peripherals pins needs to be adpated as well:

  • SD card https://github.com/jomjol/AI-on-the-edge-device/blob/933215c1164d8b2b816a87ad42df185563939b1b/code/main/main.cpp#L117

  • LED

  • Flashlight (seems not available on this board) https://github.com/jomjol/AI-on-the-edge-device/blob/933215c1164d8b2b816a87ad42df185563939b1b/code/include/defines.h#L62

  • The resolution needs to be set max. to 640x480 to ensure that available memory is sufficient.

Only testing can tell you, if more modifications are necessary. This is just what came in mind to me...

Slider0007 avatar Mar 14 '23 09:03 Slider0007

I'd say according to the table shown earlier there's no flashlight soldered but the table states that pin GPIO25 is the right one, as long as not attaching a TFT which would occupy that IO port.

commentsonly avatar Jul 14 '23 05:07 commentsonly

keep in mind that we don't have RAM to support a higher camera resolution!

caco3 avatar Jul 14 '23 17:07 caco3

@CountParadox could you figure out a solution for this camera?

AhmedThabit avatar Apr 24 '24 19:04 AhmedThabit

Negative, I just purchased a supported board

CountParadox avatar Apr 24 '24 21:04 CountParadox

can you recommend one?

AhmedThabit avatar Apr 24 '24 21:04 AhmedThabit

I managed to get my OV5640 to work on my local build. I just needed to enable ov5640 in SDK config, added guards around ov2640 specific code because they are not compatible to ov5640. Zoom mode is also working on ov5640 after very slight modification in the zoom handling code in ClassControllCamera.cpp. The zoom mode will give more magnification compared to ov2640.

For anyone who's interested, I'm using this OV5640 module: https://www.ebay.com.au/itm/304414545614

@caco3 I would create a PR if I can get the html working but create reference image html on rolling branch appears to be broken? What is the state of rolling branch now? Sorry I haven't looked into this for a few months.

jasaw avatar May 04 '24 17:05 jasaw

@caco3 I would create a PR if I can get the html working but create reference image html on rolling branch appears to be broken? What is the state of rolling branch now? Sorry I haven't looked into this for a few months.

I am not aware of any recent changes on the Web UI. Can you try the latest rolling and describe your problem a bit more in detail?

caco3 avatar May 05 '24 20:05 caco3

I am not aware of any recent changes on the Web UI. Can you try the latest rolling and describe your problem a bit more in detail?

@caco3 sorry, turns out that it was just my web browser caching the previous version of the web interface causing problem with the new firmware on rolling branch. I just need to clear my browser cache.

I've created a PR to support OV5640. https://github.com/jomjol/AI-on-the-edge-device/pull/3063

jasaw avatar May 06 '24 02:05 jasaw

Has anyone tried the OV5640 camera with autofocus? This alternate aliexpress listing is for esp32cam with OV5640 but I'm not sure whether the esp32cam board has pre-connected the AF-VCC and AF-GND. If they are already pre-connected, then there's no need to solder wires.

Just need to solder 2 wires on the ESP32cam CSI connector to power the autofocus control. The first 2 pins are not connected at the moment. Connect AF-VCC to 2.8V (pin 21 of this CSI connector), AF-GND to GND. ESP32-CAM-AI-Thinker-schematic-diagram

This is the OV5640 with autofocus pinout. ov5640af_pinout

Here's an open source project that demonstrates the autofocus feature. https://github.com/0015/ESP32-OV5640-AF

Here's the application note for controlling the autofocus function. ov5640-firmware-user-guide.pdf

jasaw avatar May 09 '24 06:05 jasaw

The esp32cam OV5640 autofocus aliexpress listing that I mentioned above does indeed have the autofocus AF-VCC and AF-GND connected on the CSI connector, so no soldering required.

esp32cam_plus_ov5640_af

jasaw avatar May 13 '24 15:05 jasaw

@SybexX Just a quick update on my progress on autofocus:

  • I have seen 3 variants of OV5640 with AF: waveshare (AF-VDD on pin24), Adafruit (AF-VDD on pin23), AliExpress (AF-VDD pin23 & AF-GND pin24). I'm using the AliExpress variant.
  • Autofocus works beautifully when I power AF-VDD with 2.8V and AF-GND with GND (no zoom mode). I've shared my hardware mod photo below.
  • I am using the OV5640 autofocus microcode from https://github.com/0015/ESP32-OV5640-AF but had to modify all the other functions for AF to work.
  • ov5640-firmware-user-guide.pdf describes step by step exactly how to get AF to work. Basically the steps are, load AF microcode to initialize, then on each flow cycle, set single shot AF mode, wait for it to get focus by polling focus status, capture image for the flow cycle, release AF.
  • I haven't been able to get autofocus to work with zoom mode enabled. I suspect 4 focus zones need to be disabled, and move the 1 focus zone to the zoomed window.
  • I have yet to figure out how to manually set the focus level. I think we have to manipulate registers 0x3602 and 0x3603.

20240522_125703

jasaw avatar Jun 03 '24 02:06 jasaw