Configure an esp32-camera (viam-micro-server)
esp32-camera
is the camera model that supports all cameras that work with Espressif’s esp32-camera drivers including:
OV2640
- Datasheet
- 1600 x 1200, Color, ¼” lens
- You can use a cam ribbon adapter to connect to your
esp32
board
OV3660
: an m5 camera timer module- Datasheet
- 2048 x 1536, Color, ⅕” lens
For example, the OV2640
with a ribbon cable connected to an ESP32:
Software requirements
To use this model, you must follow the viam-micro-server
Development Setup, which enables you to install and activate the ESP-IDF.
At the step Generate a new project from a template where you create a new project with cargo generate
, select the option to include camera module traits when prompted.
Finish the viam-micro-server
Development Setup and return to this guide.
Data management not supported
The esp32-camera
camera model does not currently support the data management service.
First, connect your camera to your machine’s microcontroller and turn the microcontroller on. Then, configure your camera:
Navigate to the CONFIGURE tab of your machine’s page in the Viam app.
Select JSON mode.
Copy and paste the following JSON into your existing machine configuration into the "components"
array:
{
"name": "my-esp32camera",
"namespace": "rdk",
"type": "camera",
"model": "esp32-camera",
"attributes": {
"pin_d4": <int>,
"jpeg_quality": <int>,
"frame_size": <int>,
"pin_d5": <int>,
"pin_d3": <int>,
"pin_d6": <int>,
"pin_vsync": <int>,
"ledc_timer": <int>,
"pin_d7": <int>,
"pin_sccb_sda": <int>,
"pin_href": <int>,
"pin_sccb_scl": <int>,
"sccb_i2c_port": <int>,
"pin_d1": <int>,
"pin_d0": <int>,
"pin_xclk": <int>,
"pin_reset": <int>,
"pin_pclk": <int>,
"pin_d2": <int>,
"xclk_freq_hz": <int>,
"ledc_channel": <int>
}
}
Edit and fill in the attributes as applicable.
{
"name": "my-esp32camera",
"namespace": "rdk",
"type": "camera",
"model": "esp32-camera",
"attributes": {
"pin_pwdn": -1,
"pin_reset": -1,
"pin_xclk": 21,
"pin_sccb_sda": 26,
"pin_sccb_scl": 27,
"pin_d7": 35,
"pin_d6": 34,
"pin_d5": 39,
"pin_d4": 36,
"pin_d3": 19,
"pin_d2": 18,
"pin_d1": 5,
"pin_d0": 4,
"pin_vsync": 25,
"pin_href": 23,
"pin_pclk": 22,
"xclk_freq_hz": 20000000,
"ledc_timer": 1,
"ledc_channel": 1
}
}
{
"name": "my-esp32camera",
"namespace": "rdk",
"type": "camera",
"model": "esp32-camera",
"attributes": {
"pin_d4": 39,
"jpeg_quality": 32,
"frame_size": 5,
"pin_d5": 18,
"pin_d3": 5,
"pin_d6": 36,
"pin_vsync": 22,
"ledc_timer": 1,
"pin_d7": 19,
"pin_sccb_sda": 25,
"pin_href": 26,
"pin_sccb_scl": 23,
"sccb_i2c_port": -1,
"pin_d1": 35,
"pin_d0": 32,
"pin_xclk": 27,
"pin_reset": 15,
"pin_pclk": 21,
"pin_d2": 34,
"xclk_freq_hz": 20000000,
"ledc_channel": 1
}
}
Note
While the following attributes marked as Optional do have defaults, it is recommended that you configure them according to your datasheet as your device may not align with the defaults which could cause damage to your board or camera.
The following attributes are available for esp32-camera
cameras:
Name | Type | Required? | Description |
---|---|---|---|
pin_pwdn | int | Optional | GPIO pin for camera power down line. Default: -1 |
pin_reset | int | Optional | GPIO pin for camera reset line. Default: -1 |
pin_xclk | int | Optional | GPIO pin for camera XCLK line. Default: 21 |
pin_sccb_sda | int | Optional | GPIO pin for camera SDA line. Default: 26 |
pin_sccb_scl | int | Optional | GPIO pin for camera SCL line. Default: 27 |
pin_d7 | int | Optional | GPIO pin for camera D7 line. Default: 35 |
pin_d6 | int | Optional | GPIO pin for camera D6 line. Default: 34 |
pin_d5 | int | Optional | GPIO pin for camera D5 line. Default: 39 |
pin_d4 | int | Optional | GPIO pin for camera D4 line. Default: 36 |
pin_d3 | int | Optional | GPIO pin for camera D3 line. Default: 19 |
pin_d2 | int | Optional | GPIO pin for camera D2 line. Default: 18 |
pin_d1 | int | Optional | GPIO pin for camera D1 line. Default: 5 |
pin_d0 | int | Optional | GPIO pin for camera D0 line. Default: 4 |
pin_vsync | int | Optional | GPIO pin for camera VSYNC line. Default: 25 |
pin_href | int | Optional | GPIO pin for camera HREF line. Default: 23 |
pin_pclk | int | Optional | GPIO pin for camera PLCK line. Default: 22 |
xclk_freq_hz | int | Optional | Frequency of XCLK signal, in Hz. Experimental: Set to 16MHz on ESP32-S2 or ESP32-S3 to enable EDMA mode. Default: 20000000 |
ledc_timer | int | Optional | LEDC timer to generate XCLK. Default: 1 |
ledc_channel | int | Optional | LEDC channel to generate XCLK. Default: 1 |
frame_size | int | Optional | Size of the output image. Default: 1 |
jpeg_quality | int | Optional | Quality of JPEG output. Lower means higher quality. Range: 0-63 Default: 32 |
View the camera stream
Once your camera is configured and connected, expand the TEST panel on the CONFIGURE or CONTROL tabs. If everything is configured correctly, you will see the live feed from your camera.
Troubleshooting
If your camera is not working as expected, follow these steps:
- Check your machine logs on the LOGS tab to check for errors.
- Review this camera model’s documentation to ensure you have configured all required attributes.
- Click on the TEST panel on the CONFIGURE or CONTROL tab and test if you can use the camera there.
If none of these steps work, reach out to us on the Community Discord and we will be happy to help.
Common errors
Next steps
For more configuration and usage info, see:
Have questions, or want to meet other people working on robots? Join our Community Discord.
If you notice any issues with the documentation, feel free to file an issue or edit this file.
Was this page helpful?
Glad to hear it! If you have any other feedback please let us know:
We're sorry about that. To help us improve, please tell us what we can do better:
Thank you!