Skip to content
This repository has been archived by the owner on Jun 15, 2020. It is now read-only.

JPEG mode #15

Closed
Oitzu opened this issue Dec 8, 2016 · 55 comments
Closed

JPEG mode #15

Oitzu opened this issue Dec 8, 2016 · 55 comments

Comments

@Oitzu
Copy link
Contributor

Oitzu commented Dec 8, 2016

Forked from #11 to not go off-topic.

I also need to see the waveforms for JPEG case and check with hardware folks if this is something that I2S can support (although this is not something directly related to this specific issue).

I will do this, as soon as i get the cam. (Feels like taking forever)

@Oitzu
Copy link
Contributor Author

Oitzu commented Dec 8, 2016

According to this code: https://github.com/iqyx/ov2640-stm32/blob/master/F4discovery/main.c
It SHOULD btw. look like this:
ov2640-jpg-timing

@Oitzu
Copy link
Contributor Author

Oitzu commented Dec 8, 2016

Well its not completly clear from the code how often href rises and falls. Just that VSYNC goes high on the beginning of the frame and low at the end and that an active href marks valid data on the databus.

@Oitzu
Copy link
Contributor Author

Oitzu commented Dec 12, 2016

timing-ov2640-jpeg

This is more accurate. In the end only the dma and fb buffers needs to extended to a safety margin, and the transfer needs to be stoped at falling vsync.

@Oitzu
Copy link
Contributor Author

Oitzu commented Dec 15, 2016

@igrr last one is the case. Can we get an example on how to work with an interrupt on vsync?

@igrr
Copy link
Owner

igrr commented Dec 16, 2016

Is there a known max length of data sent per HREF high period? Is there some guaranteed alignment, i.e. total size is dividable by 2 or by 4? Getting an interrupt is easy — check the gpio driver, it has some function to install interrupt handler. But i don't know how to tell the DMA FSM to flush all the data and end the transfer, especially if the FIFO contains an odd number of bytes. I'll try to clarify this.

@Oitzu
Copy link
Contributor Author

Oitzu commented Dec 16, 2016

Is there a known max length of data sent per HREF high period?

It's unfourtnatly not documented. Other implementations just streams in a big dma-buffer and flush it when vsync is going low.
Afterwards bytes are cut before and trailing the JPEG-Data, because this method seems kinda unclean but used widely.

Is there some guaranteed alignment, i.e. total size is dividable by 2 or by 4?

Also not documented. :((

I will try to experiment a little bit arround.

@Oitzu
Copy link
Contributor Author

Oitzu commented Dec 22, 2016

@igrr looking at the data and the osci, the data suggests that PCLK per HREF-HIGH stays at resolution width.
The number of HREF-HIGHS per VSYNC-HIGH seems to change with the compression rate.

So the dma-buffers could actually stay the same. The framebuffer should be set to maximum image size and trimed after capture.

@Oitzu
Copy link
Contributor Author

Oitzu commented Dec 24, 2016

Hm.... doesn't seem to quite work out if i try it.
Maybe a big dma buffer and flushing on falling vsync would be better.

@igrr
Copy link
Owner

igrr commented Dec 30, 2016

Got myself an ov2640; will try to play with it on holidays.

@Oitzu
Copy link
Contributor Author

Oitzu commented Dec 30, 2016

Thats great news. :)
I played arround also the last few days, at low PCLK-Rate i get a few bytes out of it that suggest JPEG-Data ("ff d8 ff e0 00 10 4a 46 49 46" jpeg-header), but get corrupted data or task-handle-errors afterwards.
I think my "PCLK per HREF-HIGH" theory was wrong, unfourtnatly my oscilloscope doesn't allow a precise measurment of that.
Maybe i need to stock up my gear and also get jtag-debug-hardware (only swd laying arround).

@igrr
Copy link
Owner

igrr commented Jan 20, 2017

@Oitzu I had a few minutes today to check with the folks who had designed I2S peripheral, and there seems to be a way to get all the data out of I2S even when RXEOF interrupt doesn't fire. Will try using your OV2640 code.

@Oitzu
Copy link
Contributor Author

Oitzu commented Jan 20, 2017

@igrr great to hear that you found some time. :)
I pushed some of my jpeg-tests to https://github.com/Oitzu/esp32-cam-demo/tree/ov2640-jpeg-playground
It's absolutely messy, and probably completly on the wrong path but well... :/
Mind: It uses wifi+httpd to output the raw-data and uses the alternative pinout.

@igrr
Copy link
Owner

igrr commented Jan 20, 2017

Yep, I have to find more time for this — apparently there are people who actually want to use JPEG sensors with the ESP32 for mass production, and we have to support them. Thanks for the code and the pointers.

@Oitzu
Copy link
Contributor Author

Oitzu commented Jan 20, 2017

Well that is great to hear, for me. :P
I'm actually validating to use the esp32 on a project. But only on the laughable scale of 10-20 units. (for the start)

Any open information about the guys that want to mass produce?

@igrr
Copy link
Owner

igrr commented Jan 22, 2017

Well, based on your code i was able to get mjpeg streaming, a few frames per second :) And thanks for dropping a web server in there — it has really helped debugging!

I need make this thing at least slightly faster and do some, will push my work-in-progress branch once I'm done for the day.

edit: regarding your last question, no, there's no open info.

@Oitzu
Copy link
Contributor Author

Oitzu commented Jan 22, 2017

Wow thats great, and is exactly what i wanted to accomplish, but stopped after not getting one complete frame. :)

Note: If you want push in reference to my "quick and dirty"-branch mind that i rewrote history of the commit 2 days ago. I accidently dropped wlan credentials in it (that i already changed on my side). I should have implemented them in the sdkconfig at the first place. roll-eyes

I'm thrilled to see how it is implemented.

@Oitzu
Copy link
Contributor Author

Oitzu commented Jan 28, 2017

@igrr any news on this? :)

@igrr
Copy link
Owner

igrr commented Feb 7, 2017

The workaround for #20 has been found, and we can now get JPEG stream at 20MHz pixel clock. Need to think how to integrate this properly though, as clock rates <=10MHz and >10MHz require different DMA setups.

@Oitzu
Copy link
Contributor Author

Oitzu commented Feb 8, 2017

Maybe a getter method implemented into the camera-specific files that calculates the expected pclk based on xclk/multipliers/dividers, resulting on different function calls on dma init?

igrr added a commit that referenced this issue Feb 9, 2017
- Fixes #15 using special sampling mode which can capture the last
  sample before HSYNC goes low.
- Implements #20
- Breaks grayscale mode with OV7725
@igrr
Copy link
Owner

igrr commented Feb 9, 2017

Pushed my work-in-progress branch. At the moment I have likely broken OV7725 (i.e. non-jpeg) support, will fix it a bit later.
OV2640 works in jpeg mode both at 10MHz and 20MHz. Server can now do mjpeg streaming (although the frame rate leaves a lot to be desired).

@Oitzu
Copy link
Contributor Author

Oitzu commented Feb 9, 2017

Great. 👍 Quite a lot changes. Need to play arround with it the next few days.
Did you ever tried to bump it up to UXGA?

@Oitzu
Copy link
Contributor Author

Oitzu commented Feb 9, 2017

Cloned it. Modified the pin configuration back.
Getting an error while the DMA buffers are allocating.
https://gist.github.com/Oitzu/842b5027c59e3ed435f8f82f697bf77e

I updated inbefore my toolchain also.

@igrr
Copy link
Owner

igrr commented Feb 9, 2017

Can you please try with log level set to "verbose" in menuconfig? Also you may try using xtensa-esp32-elf-addr2line on the addresses in backtrace line to see where exactly it is crashing.

@Oitzu
Copy link
Contributor Author

Oitzu commented Feb 9, 2017

0x40083185
/home/oitzu/esp/esp-idf/components/freertos/./queue.c:2040
0x40083692
/home/oitzu/esp/esp-idf/components/freertos/./heap_regions.c:410
0x400836fa
/home/oitzu/esp/esp-idf/components/freertos/./heap_regions.c:499 (discriminator 1)
0x40104dba
/home/oitzu/esp/esp32-cam-demo/main/./app_main.c:223
0x40103787
/home/oitzu/esp/esp-idf/components/wpa_supplicant/src/crypto/aes-internal-enc.c:84
0x400d1179
/home/oitzu/esp/esp-idf/components/esp32/./cpu_start.c:280 (discriminator 1)

@Oitzu
Copy link
Contributor Author

Oitzu commented Feb 9, 2017

Verbose output here: https://gist.github.com/Oitzu/e6c14089fadf4dc488a4c71b806d0c42

Strangly enough the backtrace differs?

@H-LK
Copy link

H-LK commented Feb 10, 2017

Getting an error during i2c check of camera:
D (1843) camera: Detected camera at address=0x30
D (1853) camera: Camera PID=0x00 VER=0x00 MIDL=0x00 MIDH=0x00

Cables are very short and testet.

Sparkfun ESP32 THING + WaveShare OV2640

@Oitzu
Copy link
Contributor Author

Oitzu commented Feb 10, 2017

@H-LK :
Well obviously first check your cables against the config and a pinout of your board.
Especially the vcc/gnd/SIDC/SIOD connections.

Second: Try a "cold boot". It happens that the ov2640 doesn't reset correctly on soft reboots.

  1. Disconnect USB.
  2. Press and hold Reset on the esp32.
  3. Connect USB and wait till the usb-serial chip is completly connected.
  4. Open Serial Terminal.
  5. Release Reset.
    With this way you get the first serial output from your esp32 on "cold boot".

@H-LK
Copy link

H-LK commented Feb 10, 2017

@Oitzu works fine :)
I am getting the same type of error like Oitzu:
https://gist.github.com/H-LK/7bfcc058d079d4bf058580bdb45f1f57

@Oitzu
Copy link
Contributor Author

Oitzu commented Feb 10, 2017

I had to reduce the clock down to 5MHz to get a not gibberish picture, but that works! :)

I probably need to work on the hardware connection between camera and esp32 to get better/faster results.

@igrr
Copy link
Owner

igrr commented Feb 10, 2017

Yes, one thing with jpegs is that if you get a single byte wrong, the the rest of the picture will be garbage. I'm using the ESP-WROVER-KIT here, it works okay up to 20MHz.

In the next chip we'll bump max i2s slave clock to 40MHz, to support those higher resolution modes.

@Oitzu
Copy link
Contributor Author

Oitzu commented Feb 10, 2017

So the higher resolution modes are currently not implemented because that would be painfully slow?

With "the next chip" you are speaking of the next revision of the esp32?
I hope that also someone will produce a module with a ipex connector on the next revision.

@igrr
Copy link
Owner

igrr commented Feb 10, 2017

Regarding higher resolutions (uxga?) — I just used the code from openmv, so I suppose it's just a matter of adding the right register configuration in ov2640.c. I have tested SVGA (800x600) which worked fine, but that's the highest resolution which I personally need.

Regarding the next chip, I was referring to the single-core version of the esp32. The next silicon revision of dual-core esp32 doesn't have these changes. The new module based on the ESP32, which has 4MB pSRAM, also comes with ipex connector. PSRAM will come handy to store larger frame buffers as well.

@Oitzu
Copy link
Contributor Author

Oitzu commented Feb 11, 2017

Will definitly try the higher resolution. In the meantime i pushed a few smaller enhancements. (No more fighting about the pin configuration)

Didn't know that there is a single-core ESP32 in the queue. Is there anywhere detailed information about the differences between different versions and revisions?

@Oitzu
Copy link
Contributor Author

Oitzu commented Feb 11, 2017

Was investigating the higher resolution and was baffled about the buffer allocation.
We are actually allocating more buffer than we need, or?
Also we do send a lot of junk after the picture? (Should end with 0xff 0xd9)

@igrr
Copy link
Owner

igrr commented Feb 11, 2017

I'm allocating (fb_size)/compression_ratio, where compression ratio is estimated based on jpeg quality parameter. That's not perfect, if you have any suggestion please let me know.

Regarding junk — quite probably. I think the size is rounded up to the end of the line.

@Oitzu
Copy link
Contributor Author

Oitzu commented Feb 18, 2017

That's not perfect, if you have any suggestion please let me know.

At the moment, no. I was just curious from where this number is coming from.
Hard to say what the maximum framesize could be, without knowing of the internal workings of the ov2640 jpeg compression.

Possibly there is a method like: "header + (number_of_8x8_chunks * max_chunk_size / quality_factor) + footer (+junk)" but i'm not quite sure about the max chunk size and the quality factor.

Maybe i just wait for the new ESP32 module and all my space restrictions will be gone. ;)

@radiumray
Copy link

@Oitzu i am trying https://github.com/Oitzu/esp32-cam-demo/tree/ov2640-jpeg-playground
but i got nothing in my broswer,
i can get data ascii data on serial for another branch of git code

@Oitzu
Copy link
Contributor Author

Oitzu commented May 8, 2017

@radiumray could you give us the serial output? Maybe something in there gives a clue what is going wrong.

@igrr
Copy link
Owner

igrr commented May 8, 2017

There's also feature/ov2640 branch in this repo, which i need to merge one day. I think the only thing not finished there are non-JPEG modes (which are broken).

@radiumray
Copy link

@Oitzu i was useing OV7725, there is no serial output for jpeg-playground branch
i have change camera config to this:
camera_config_t config = {
.ledc_channel = LEDC_CHANNEL_0,
.ledc_timer = LEDC_TIMER_0,
.pin_d0 = 4,
.pin_d1 = 5,
.pin_d2 = 18,
.pin_d3 = 19,
.pin_d4 = 36,
.pin_d5 = 39,
.pin_d6 = 34,
.pin_d7 = 35,
.pin_xclk = 21,
.pin_pclk = 22,
.pin_vsync = 25,
.pin_href = 23,
.pin_sscb_sda = 26,
.pin_sscb_scl = 27,
.pin_reset = 2,
.xclk_freq_hz = 10000000,
.pixel_format = CAMERA_PF_JPEG,
.frame_size = CAMERA_FS_VGA,
.jpeg_quality = 15

@Oitzu
Copy link
Contributor Author

Oitzu commented May 8, 2017

@radiumray not even "Enabling XCLK output" -> "Initializing SSCB" etc...?
Could you increase the debug output level?
Absolutly no serial output would be very strange and would be a hint to a more basic problem.

@igrr The jpeg-playground branch is basicly the same just added more configuration-options and fixes/adds direct jpeg display in browser.

@radiumray
Copy link

hi @Oitzu thanks a lots for your advise, (it is seem like not supported OV7725, Is not it?)
i have already increase my debug level,below is my serial output:
}D (473) camera: Test pattern enabled�[0m
�[0;31mE (473) camera: JPEG format is only supported for ov2640�[0m
C:/esp/esp-idf/components/freertos/heap_regions.c:369 (vPortFreeTagged)- assert failed!
abort() was called at PC 0x40084ef8 on core 0
Guru Meditation Error: Core 0 panic'ed (abort)

Backtrace: 0x40008155:0x3ffb8760 0x40007d16:0x3ffb8780 0x40087320:0x3ffb87a0 0x40081c6c:0x3ffb87c0 0x4000beca:0x3ffb87e0 0x400dd41a:0x3ffb8800 0x400dbdf3:0x3ffb8830 0x400d0ba1:0x3ffb88c0

================= CORE DUMP START =================
LBMAAAYAAAB8AQAA
UPT6P6CG+z9Mifs/
sIX7P+CI+z8UAAAACC/7Pwgv+z9Q9Po/AC/7PxgAAACU5fo/lOX6P1D0+j8AAAAA
AQAAAFB5+z9tYWluAApDnxYZc/RO6pAAAAAAAEyJ+z8AAAAAIQAGAAEAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWOP6P8Dj+j8o5Po/
AAAAAAAAAAABAAAAAAAAADAeQD8AAAAASB0AQAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADxV64=
g2gIgFWBAEA2CQYAFn0AgGCH+z9YAAAAWAAAABAAAAD/////AAAAAPD///+xLfs/
AQAAAC4AAAAuAAAADAAAAP////8AAAAA/v///wUAAAABAAAAAAAAAP0UAEANFQBA
/v///wwAAAD/////HBQIQAAAAAAAAAAAAAAAAAAAAAAAAD+zAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAgAAAAIAAAA1Ib7P/////8gcwiAgIf7P/Kl8CvqpfAr
EAAAAP////8AAAAA8P///2wcCICgh/s/8qXwK8Dj+j+khvs/AAAAAAYAAAAAAAD/
yr4AgMCH+z/Q9Po/8qXwKwEAAACAhPs/gIT7PwIAA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ACl4og=
EBUIQLdYCEAwAAYAuxAIgIDq+j+85fo/AAAAAATm+j8AAAAAAQAAAAEAAACFWQiA
YOr6P9wA8D8BAAAA4DD7P0A7/j9kE/s/AgAAAAAAAAClpaWlpaWlpQAAAAAAAAAA
AAAAAA0XCEBAO/4/jFsIQAAAAAAAAAAAAAAAAAAAAAAAAD+zAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwOr6PwAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAP////8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAODq+j8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAjDgiA8Dv+P1gu+z/EMfs/
AAAAAAAAAADs6vo/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAA
================= CORE DUMP END =================
CPU halted.

@Oitzu
Copy link
Contributor Author

Oitzu commented May 9, 2017

@radiumray yes the JPEG format is only available to the ov2640.
The mode relies on the internal jpeg processing capabilities of the ov2640.
The OV7725 doesn't have this feature afaik.
Also we have no free memory, at the moment, to do some fancy yuv/rgb to jpeg compression.

@radiumray
Copy link

@Oitzu a huge thanks

@radiumray
Copy link

radiumray commented May 12, 2017

hi @Oitzu i get OV2640 already, i still can't get image on my brower, my address is:
http://192.168.199.222/get
http://192.168.199.222/stream

the debug info below is something wrong about SCCB:
D (294) camera: Resetting camera
I (294) gpio: GPIO[2]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
D (324) camera: Searching for camera address
D (334) camera: Detected camera at address=0x30
D (344) camera: Camera PID=0x26 VER=0x42 MIDL=0x7f MIDH=0xa2
D (344) camera: Doing SW reset of sensor
SCCB_Write [35]=88 failed
SCCB_Write [37]=40 failed
SCCB_Write [34]=a0 failed
SCCB_Write [06]=88 failed
SCCB_Write [0e]=01 failed
SCCB_Write [49]=00 failed
SCCB_Write [63]=00 failed
SCCB_Write [47]=00 failed
SCCB_Write [5e]=7d failed
SCCB_Write [70]=02 failed
SCCB_Write [e0]=14 failed
SCCB_Write [43]=18 failed
SCCB_Write [88]=3f failed
SCCB_Write [d7]=03 failed
SCCB_Write [d3]=82 failed
SCCB_Write [7d]=00 failed
SCCB_Write [91]=0e failed
SCCB_Write [91]=88 failed
SCCB_Write [91]=96 failed
SCCB_Write [91]=d7 failed
SCCB_Write [91]=20 failed
SCCB_Write [93]=03 failed
SCCB_Write [97]=24 failed
SCCB_Write [97]=80 failed
SCCB_Write [97]=00 failed
SCCB_Write [c6]=51 failed
SCCB_Write [c7]=10 failed
SCCB_Write [b9]=7c failed
SCCB_Write [b0]=c5 failed
SCCB_Write [c4]=5c failed
SCCB_Write [a7]=20 failed
SCCB_Write [a7]=31 failed
SCCB_Write [a7]=d8 failed
SCCB_Write [a7]=31 failed
SCCB_Write [7f]=00 failed
SCCB_Write [e1]=77 failed
SCCB_Write [12]=40 failed
SCCB_Write [0d]=87 failed
SCCB_Write [e0]=04 failed
D (464) camera: Setting frame size to 640x480
D (524) camera: Test pattern enabled
D (524) camera: bpp: 2, fb_size: 61440, mode: 3, width: 640 height: 480
D (524) camera: Allocating frame buffer (61440 bytes)
D (524) camera: Initializing I2S and DMA
I (524) gpio: GPIO[35]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (534) gpio: GPIO[34]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (544) gpio: GPIO[39]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (554) gpio: GPIO[36]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (564) gpio: GPIO[19]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (564) gpio: GPIO[18]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (574) gpio: GPIO[5]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (584) gpio: GPIO[4]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (594) gpio: GPIO[25]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (604) gpio: GPIO[23]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (614) gpio: GPIO[22]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
D (614) intr_alloc: Connected src 32 to int 12 (cpu 0)
D (624) camera: Line width (for DMA): 5120 bytes
D (624) camera: DMA buffer size: 2560, DMA buffers per line: 2
D (634) camera: DMA buffer count: 8
D (634) camera: Allocating DMA buffer #0, size=2560
D (644) camera: Allocating DMA buffer #1, size=2560
D (644) camera: Allocating DMA buffer #2, size=2560
D (654) camera: Allocating DMA buffer #3, size=2560
D (654) camera: Allocating DMA buffer #4, size=2560
D (664) camera: Allocating DMA buffer #5, size=2560
D (664) camera: Allocating DMA buffer #6, size=2560
D (664) camera: Allocating DMA buffer #7, size=2560
D (674) camera: Initializing GPIO interrupts
D (674) intr_alloc: Connected src 22 to int 13 (cpu 0)
D (684) camera: Init done
D (684) nvs: nvs_open misc 1
D (684) nvs: nvs_get_str_or_blob log
I (694) wifi: wifi firmware version: ba7c292
I (694) wifi: config NVS flash: enabled
I (694) wifi: config nano formating: disabled
D (704) nvs: nvs_open nvs.net80211 1
D (704) nvs: nvs_get opmode 1
D (704) nvs: nvs_get country 1
D (714) nvs: nvs_get_str_or_blob sta.ssid
D (714) nvs: nvs_get_str_or_blob sta.mac
D (714) nvs: nvs_get sta.authmode 1
D (724) nvs: nvs_get_str_or_blob sta.pswd
D (724) nvs: nvs_get_str_or_blob sta.pmk
D (724) nvs: nvs_get sta.chan 1
D (734) nvs: nvs_get auto.conn 1
D (734) nvs: nvs_get bssid.set 1
D (734) nvs: nvs_get_str_or_blob sta.bssid
D (744) nvs: nvs_get sta.phym 1
D (744) nvs: nvs_get sta.phybw 1
D (744) nvs: nvs_get_str_or_blob sta.apsw
D (754) nvs: nvs_get_str_or_blob sta.apinfo
D (754) nvs: nvs_get_str_or_blob ap.ssid
D (754) nvs: nvs_get_str_or_blob ap.mac
D (764) nvs: nvs_get_str_or_blob ap.passwd
D (764) nvs: nvs_get_str_or_blob ap.pmk
D (774) nvs: nvs_get ap.chan 1
D (774) nvs: nvs_get ap.authmode 1
D (774) nvs: nvs_get ap.hidden 1
D (774) nvs: nvs_get ap.max.conn 1
D (784) nvs: nvs_get bcn.interval 2
D (784) nvs: nvs_get ap.phym 1
D (784) nvs: nvs_get ap.phybw 1
D (794) nvs: nvs_get ap.sndchan 1
D (794) nvs: nvs_set_blob sta.mac 6
D (794) nvs: nvs_set_blob ap.mac 6
I (794) wifi: Init dynamic tx buffer num: 32
I (794) wifi: Init dynamic rx buffer num: 64
I (804) wifi: wifi driver task: 3ffd26d8, prio:23, stack:3584
I (804) wifi: Init static rx buffer num: 10
I (804) wifi: Init dynamic rx buffer num: 64
I (814) wifi: Init rx ampdu len mblock:7
I (814) wifi: Init lldesc rx ampdu entry mblock:4
I (824) wifi: wifi power manager task: 0x3ffd7a9c prio: 21 stack: 2560
I (824) wifi: wifi timer task: 3ffd8b38, prio:22, stack:3584
D (834) phy_init: loading PHY init data from application binary
D (834) nvs: nvs_open phy 0
D (844) nvs: nvs_get cal_version 4
D (844) nvs: nvs_get_str_or_blob cal_mac
D (844) nvs: nvs_get_str_or_blob cal_data
D (854) nvs: nvs_close 3
I (964) phy: phy_version: 350, Mar 22 2017, 15:02:06, 0, 0
I (964) wifi: mode : sta (30:ae:a4:03:99:6c)
D (964) event: SYSTEM_EVENT_STA_START
I (964) wifi: sleep disable
D (964) tcpip_adapter: check: local, if=0 fn=0x40112ec8

D (974) tcpip_adapter: call api in lwip: ret=0x0, give sem
D (984) tcpip_adapter: check: remote, if=0 fn=0x40112ec8

I (1714) wifi: n:6 0, o:1 0, ap:255 255, sta:6 0, prof:1
I (2364) wifi: state: init -> auth (b0)
I (2374) wifi: state: auth -> assoc (0)
I (2404) wifi: state: assoc -> run (10)
I (2694) wifi: connected with Microduino_IoT, channel 6
D (2694) event: SYSTEM_EVENT_STA_CONNECTED, ssid:Microduino_IoT, ssid_len:14, bssid:d4:ee:07:22:26:6c, channel:6, authmode:3
D (2694) tcpip_adapter: check: local, if=0 fn=0x401130a4

D (2704) tcpip_adapter: call api in lwip: ret=0x0, give sem
D (2704) tcpip_adapter: check: remote, if=0 fn=0x401130a4

D (2714) tcpip_adapter: check: local, if=0 fn=0x40113420

D (2714) tcpip_adapter: dhcp client init ip/mask/gw to all-0
D (2724) tcpip_adapter: dhcp client start successfully
D (2724) tcpip_adapter: call api in lwip: ret=0x0, give sem
D (2734) tcpip_adapter: check: remote, if=0 fn=0x40113420

D (2844) event: SYSTEM_EVENT_STA_GOTIP, ip:192.168.199.146, mask:255.255.255.0, gw:192.168.199.1
I (2844) event: ip: 192.168.199.146, mask: 255.255.255.0, gw: 192.168.199.1
I (2854) camera_demo: Free heap: 156712

I (2854) camera_demo: Camera demo ready
I (2854) camera_demo: open http://192.168.199.146/get for single frame
I (2864) camera_demo: open http://192.168.199.146/stream for multipart/x-mixed-replace stream (use with JPEGs)
I (12404) wifi: pm start, type:0

@Oitzu
Copy link
Contributor Author

Oitzu commented May 17, 2017

Never seen this SCCB_Write errors.
Try following to debug:
Press and hold reset on your esp32 board.
Plug in USB.
Open Serial connection.
Release the reset button.

This gets you the fresh startup output without any software resets or whatever in between.

@radiumray
Copy link

@Oitzu hi
got another OV2640 from different factory, and it is almost work perfectly
my browser can reciver data but display error
i have try to print s_state->fb to Serial when http://192.168.199.222/get
my s_state->fb hex data is not to begin FF D8 ..........and end with FF D9, it is not like jpeg format

my s_state->fb hex data Serial print is like that:
ff 10 49 01 00 00 ff 43 0a 0b .....................................................................
..................................................................................................................................
...................................................................................................................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 14 00 0d

@Oitzu
Copy link
Contributor Author

Oitzu commented May 20, 2017

The end of the jpeg is currently not junk-free but should work neither the less.
Try to lower the clockrate also make sure to turn down the log-output-level to prevent timing issues.

@hopkinskong
Copy link

@Oitzu @igrr Can you guys confirm you can't get proper JPEG image beyond 20MHz XCLK? I have bumped up the XCLK to 20MHz (confirmed with logic analyzer), and I start to have missing bytes (like JPEG header "JFIF" turns to "JFF").

btw, I can get like 8~10fps with MJPEG under 800x600 under 20MHz XCLK, I am using long wires though.

@hopkinskong
Copy link

hopkinskong commented Jun 2, 2017

Also, when I increased my core speed to 240MHz (default 160MHz), I can't see the images anymore. Frames seems still arrive, but corrupted, any idea why?

@Oitzu
Copy link
Contributor Author

Oitzu commented Jun 6, 2017

@hopkinskong regarding the 20MHz XCLK: I couldn't reach 20MHz successful yet.
But i have a rather messy test-setup for this, and it very much depends on cable length and connection quality.

@hopkinskong
Copy link

@Oitzu Mine is messy too, I have 40CM long cables between the ESP32 and EVERY pins of my OV2640. With the logic analyzer, I can confirm that with >20MHz XCLK will in a result of >20MHz PCLK, which makes the I2S receiver missing some received bytes.

@anuprao
Copy link

anuprao commented Jan 7, 2020

Hi Everyone,

Apologies for posting on a closed topic.

I am trying to understand how the length of the JPG is assessed. From the above, I gather that once the data is captured from the ports onto a buffer, irrelevant bytes must be trimmed out. How does one know the length of relevant bytes ? Kindly share for the benefit of those trying to learn more about the OV2640 sensor and the ESP32 CAM Demo implementation.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants