shariltumin / esp32-cam-micropython-2022

MicroPython esp32-cam firmware with camera support compiled with esp-idf-4.4.0. Python script files for live streaming
MIT License
174 stars 33 forks source link

REPL not accessible, Stop/Break does not work properly #24

Closed Yimro closed 1 year ago

Yimro commented 1 year ago

Hi. I am using firmware 20230521 WIFI-TLS. I have uploaded a Micropython script that runs in an endless loop, taking images, comparing them and sending a MQTT message when there are significant changes. It works fine! However, I am not able to abort the program and return to REPL, edit the file or upload another one. In Thonny, pressing "Stop" makes the shell hang, no output, no prompt.

In a terminal emulator, it outputs an endless : cam_hal: EV-VSYNC-OVF

However, I see this error, when starting the ESP32-CAM: E (6090) gpio: gpio_install_isr_service(449): GPIO isr service already installed

It might have to do with this problem. Any ideas?

shariltumin commented 1 year ago

The error

E (6090) gpio: gpio_install_isr_service(449): GPIO isr service already installed

is OK. The camera.init() tried to install an I2C service that MicroPython had already installed. It has nothing to do with the

cam_hal: EV-VSYNC-OVF

Did you change the XCLK_MHZ? Maybe to the high value of 20? I suggest you try camera.conf(K.XCLK_MHZ, 12), which is the default value in the camera module. It all depends on how your sensor and PSRAM work together. Increasing XCLK_MHZ will not result in a faster streaming rate. Other factors, such as WiFi, will affect the streaming rate more.

Have you tried using a terminal to connect to REPL? You can reset esp32-cam by pressing the reset button. May I suggest that you do not put your main script as main.py. Say you have your main script as cam_app.py, make a main.py that contains a single line

import cam_app
Yimro commented 1 year ago

Thank you for your answer. I use the default config values from your config.py file now. And I put my loop in a seperate file. I found out that, in my case, the error cam_hal: EV-EOF-OVF occurs at the moment when my script writes the image buffer to a file. Now I set XCLK_MHZ:10 in the config.py file. The error still appears when writing to a file. I will have to look into it deeper, it might have to do with access to PSRAM or RAM.

shariltumin commented 1 year ago

Your sensor could be faulty. If you have another OV2640, please try it. I've had some experience with cam_hal: EV-VSYNC-OVF error. Using a slower XCLK value will usually reduce the occurrence of errors. You can also try removing and reconnecting the sensor to the connector.

Yimro commented 1 year ago

Solution: I added some (long) sleep times between opening the file and writing into it. No more errors! XCLK is at 12 Mhz, unchanged. Will find out which sleep times are possible.

fs = open(file_name, "wb")
                sleep_ms(500)
                fs.write(img)
                sleep_ms(500)
                fs.close()
shariltumin commented 1 year ago

Are you writing to flash or sdcard?

Yimro commented 1 year ago

Writing to flash, I need to sleep at least around 200 ms after opening the file and before writing to the file stream, at lower sleep intervals, the EV-EOF-OVF errors appear again. SDCard is the same, works well when the program sleeps 200 ms. Like this:

fs = open(file_name, "wb")
sleep_ms(200)
fs.write(img)
fs.close()