A timelapse program for esp32 cam with ov2640 sensor. The exposure is done manually based on the light level, and the image quality is far better than the default settings.
I've been working at this program on and off for over 2 months. What it does is simple: It takes a picture, saves it on the SD card, goes to sleep, then it wakes up again after a predefined interval, and so on.
The complicated part is that the registers for the ov_2640 sensor are not well documented, so a lot of time was spent testing and finding registers and the best value. The program adjusts the exposure based on the ambient light level (taken from the sensor), and it modifies the exposure by setting the proper registers. In theory, this should be simple, there is a 15 bit exposure value, spread across 3 registers. In practice, however, this doesn't work, at least on my 2 esp32-cam boards. So to modify the exposure I modify the frame rate, add dummy lines, etc. Furthermore, for long exposures you need to wait for 2 frames to get the right image. So for a 4 second exposure, you need to wait for over 4 seconds before capturing the image. If you are running the camera on batteries, this can be a problem. Fortunately, if you set bit 7 on the 0x43 register on the sensor bank, you get the image after 1 frame only, which saves a lot of time. One other problem that I couldn't fix was that the min exposure is a bit too high for sunny days, so if you point the camera at the sky parts of the image will be overexposed. If you know how to reduce the exposure even further, please let me know.
Finally, it seems that some sensors/boards are better than others. For example, on one board I get some lines shifted throughout the frame, which makes straight lines a bit curved. It's like a rolling shutter problem, even though the scene is fixed. Since on another board it doesn't do that, I think it's a hardware defect, but I can't be too sure.