esphome / esphome/issues

ESP32-CAM: Not possible to change contrast, brightness, saturation

Open
#5,499 15 comments 1 reaction 0 assignees View on GitHub
Dominant language
No language data
Stars
313
Forks
40
PR merge metrics
No merged PRs in 30d

Description

### The problem

Several method calls of the esp32_camera component do not result in any visible change, i.e. (but not complete):
* set_contrast(x); update_camera_parameters();
* set_brightness(x); update_camera_parameters();
* set_saturation(x); update_camera_parameters();

The reason is probably an oversimplified approach of the ESP32-CAM driver that is used by the component.
The central point here is the "SDE indirect register" of the OV2640, which contains a bit mask of enable flags for changes to contrast, brightness, saturation, color tint, negative and others. With each call to the driver's set_contrast / set_brightness / set_... the enable bit for the requested effect is set and all others are zeroed. Thus only the last changed effect remains active and all others are switched off again.

Now, the esp32_camera component's set_xyz() methods do not call the corresponding driver methods at all.
Instead they store the requested effect strength parameter in an internal status var.
All these status vars are then written to the OV2640 by a single call to update_camera_parameters(). This fires a series of method calls of the driver (including set_contrast, set_brightness, set_saturation and others). As described, only the last of these wins, which is probably the color tint change, as this seems to work. With this flow the brightness/saturation/contrast will never work.

I see two possible solutions here:

1. Simple but limited solution
Move the set_xyz() calls from update_camera_parameters() directly into the corresponding set_xyz() calls of the ESPHome component. This would at least allow to set all of the effects separately, but not in combination.

2. Take control of the enable flags in SDE indirect register
This would allow for all combinations of effects, but I see several comments on the web, that there are interferences between different effects that might need to be taken care of. I.e. brightness and contrast seem to interfere. But then again, this could also be handled by the user by sending adjusting method calls herself.

Solution 1. seems easy to implement and I think I can file a PR for that.
Solution 2. is beyond my reach. I tried but got stuck because I needed the write_SCCB() method of the driver. This method is currently not available in the ESPHome esp32_camera component and I have no idea how I could get hold of that. If someone could provide me a way to get hold of this method, I could also try to work on 2.

### Which version of ESPHome has the issue?

2023.5.5

### What type of installation are you using?

Home Assistant Add-on

### Which version of Home Assistant has the issue?

2023.6.1

### What platform are you using?

ESP32

### Board

ESP32-CAM (AI Thinker Clone)

### Component causing the issue

esp32_camera

### Example YAML snippet

```yaml
esp32_camera:
id: espcam
...
...

number:
- platform: template
name: Kontrast
id: cam_contrast
optimistic: true
initial_value: 0
min_value: -2
max_value: 2
step: 1
set_action:
- lambda: |-
id(espcam).set_contrast(x);
id(espcam).update_camera_parameters();
- platform: template
name: Helligkeit
id: cam_brightness
optimistic: true
initial_value: 0
min_value: -2
max_value: 2
step: 1
set_action:
- lambda: |-
id(espcam).set_brightness(x);
id(espcam).update_camera_parameters();
- platform: template
name: Sättigung
id: cam_saturation
optimistic: true
initial_value: 0
min_value: -2
max_value: 2
step: 1
set_action:
- lambda: |-
id(espcam).set_saturation(x);
id(espcam).update_camera_parameters();
```

### Anything in the logs that might be useful for us?

_No response_

### Additional information

[OV2640 Datasheet v2.2](https://www.uctronics.com/download/OV2640_DS.pdf)
[OV2640 Software Application Notes](https://www.dragonwake.com/download/camera/ov2640/OV2640%20Camera%20Module%20Software%20Application%20Notes.pdf)

[Information about enable flags in SDE indirect register](https://esp32.com/viewtopic.php?t=14376#p93178)
[Example of handling interference between brightness and contrast settings](https://github.com/espressif/esp32-camera/issues/401#issuecomment-1186605826)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.